2023-08-08 12:08:19 +03:00
|
|
|
import {expect, test} from '@playwright/test';
|
2023-11-23 15:59:48 +03:00
|
|
|
import {globalDataRequests} from '../../utils/acceptance';
|
|
|
|
import {mockApi, updatedSettingsResponse} from '@tryghost/admin-x-framework/test/acceptance';
|
2023-08-08 12:08:19 +03:00
|
|
|
|
2023-08-31 21:54:39 +03:00
|
|
|
// CodeMirror takes some time to load in Playwright meaning the first few characters typed don't always
|
|
|
|
// show up in the input. Since that lag is not consistent, this workaround ensures we type enough
|
|
|
|
// characters to consistently include the full string we want
|
|
|
|
const PADDING = 'xxxxx ';
|
|
|
|
|
2023-08-08 12:08:19 +03:00
|
|
|
test.describe('Code injection settings', async () => {
|
|
|
|
test('Supports adding injected code', async ({page}) => {
|
|
|
|
const {lastApiRequests} = await mockApi({page, requests: {
|
|
|
|
...globalDataRequests,
|
|
|
|
editSettings: {method: 'PUT', path: '/settings/', response: updatedSettingsResponse([
|
2023-10-09 11:07:34 +03:00
|
|
|
{key: 'codeinjection_head', value: 'testhead'},
|
|
|
|
{key: 'codeinjection_foot', value: 'testfoot'}
|
2023-08-08 12:08:19 +03:00
|
|
|
])}
|
|
|
|
}});
|
|
|
|
|
|
|
|
await page.goto('/');
|
|
|
|
|
|
|
|
const section = page.getByTestId('code-injection');
|
|
|
|
|
2023-12-08 10:11:52 +03:00
|
|
|
await section.getByRole('button', {name: 'Open'}).click();
|
|
|
|
|
|
|
|
const modal = page.getByTestId('modal-code-injection');
|
2023-10-09 11:07:34 +03:00
|
|
|
// Click on the CodeMirror content to make sure it's loaded
|
2023-12-08 10:11:52 +03:00
|
|
|
await modal.getByTestId('header-code').locator('.cm-content').click();
|
2023-08-08 12:08:19 +03:00
|
|
|
|
2023-10-09 11:07:34 +03:00
|
|
|
for (const character of (PADDING + 'testhead').split('')) {
|
2023-08-08 12:08:19 +03:00
|
|
|
await page.keyboard.press(character);
|
|
|
|
}
|
|
|
|
|
2023-12-08 10:11:52 +03:00
|
|
|
await modal.getByRole('tab', {name: 'Site footer'}).click();
|
|
|
|
await modal.getByTestId('footer-code').locator('.cm-content').click();
|
2023-08-08 12:08:19 +03:00
|
|
|
|
2023-10-09 11:07:34 +03:00
|
|
|
for (const character of (PADDING + 'testfoot').split('')) {
|
2023-08-08 12:08:19 +03:00
|
|
|
await page.keyboard.press(character);
|
|
|
|
}
|
|
|
|
|
2023-12-08 10:11:52 +03:00
|
|
|
await modal.getByRole('button', {name: 'Save'}).click();
|
2023-08-08 12:08:19 +03:00
|
|
|
|
2023-08-31 21:54:39 +03:00
|
|
|
expect(lastApiRequests.editSettings?.body).toMatchObject({
|
2023-08-08 12:08:19 +03:00
|
|
|
settings: [
|
2023-10-09 11:07:34 +03:00
|
|
|
{key: 'codeinjection_head', value: /testhead$/},
|
|
|
|
{key: 'codeinjection_foot', value: /testfoot$/}
|
2023-08-08 12:08:19 +03:00
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|