2023-10-13 14:42:39 +03:00
|
|
|
const {expect} = require('@playwright/test');
|
|
|
|
const test = require('../fixtures/ghost-test');
|
2023-05-05 13:11:26 +03:00
|
|
|
|
|
|
|
test.describe('Announcement Bar Settings', () => {
|
2023-10-16 18:32:13 +03:00
|
|
|
test('Bar hidden by default', async ({sharedPage}) => {
|
|
|
|
await sharedPage.goto('/ghost');
|
|
|
|
await goToAnnouncementBarSettings(sharedPage);
|
2023-05-05 13:11:26 +03:00
|
|
|
|
|
|
|
await test.step('Bar should be hidden', async () => {
|
2023-10-16 18:32:13 +03:00
|
|
|
const htmlFrame = getPreviewFrame(sharedPage);
|
2023-05-05 13:11:26 +03:00
|
|
|
await expect(await htmlFrame.locator('#announcement-bar-root')).toHaveCount(0);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-10-16 18:32:13 +03:00
|
|
|
test('Show/hide bar if visibility checked/unchecked and text filled', async ({sharedPage}) => {
|
|
|
|
await sharedPage.goto('/ghost');
|
|
|
|
const modal = await goToAnnouncementBarSettings(sharedPage);
|
2023-05-05 13:11:26 +03:00
|
|
|
|
|
|
|
await test.step('Check free members', async () => {
|
2023-10-09 10:12:46 +03:00
|
|
|
const freeMembersCheckbox = modal.getByLabel('Free members');
|
|
|
|
await expect(freeMembersCheckbox).not.toBeChecked();
|
|
|
|
await freeMembersCheckbox.check();
|
2023-05-05 13:11:26 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
await test.step('Fill announcement text', async () => {
|
2023-10-09 10:12:46 +03:00
|
|
|
await modal.locator('.koenig-react-editor').click();
|
|
|
|
await expect(await modal.locator('[contenteditable="true"]')).toBeVisible({timeout: 30000}); // add timeout as lexical module loading can take time
|
2023-10-16 18:32:13 +03:00
|
|
|
await sharedPage.keyboard.type('Announcement text');
|
2023-10-09 10:12:46 +03:00
|
|
|
await modal.getByText('Announcement').first().click(); // defocus the editor
|
2023-05-05 13:11:26 +03:00
|
|
|
});
|
|
|
|
|
2023-10-16 18:32:13 +03:00
|
|
|
const htmlFrame = getPreviewFrame(sharedPage);
|
2023-05-05 13:11:26 +03:00
|
|
|
await test.step('Announcement bar should be visible', async () => {
|
|
|
|
await expect(await htmlFrame.getByText('Announcement text')).toBeVisible();
|
|
|
|
});
|
|
|
|
|
|
|
|
await test.step('Disable free members', async () => {
|
2023-10-09 10:12:46 +03:00
|
|
|
const freeMembersCheckbox = modal.getByLabel('Free members');
|
|
|
|
await expect(freeMembersCheckbox).toBeChecked();
|
|
|
|
await freeMembersCheckbox.uncheck();
|
|
|
|
await modal.locator('.koenig-react-editor').click();
|
2023-05-05 13:11:26 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
await test.step('Announcement bar should be hidden', async () => {
|
|
|
|
await expect(await htmlFrame.getByText('Announcement text')).toBeHidden();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-10-16 18:32:13 +03:00
|
|
|
async function goToAnnouncementBarSettings(sharedPage) {
|
2023-10-09 10:12:46 +03:00
|
|
|
await test.step('Navigate to the announcement bar settings', async () => {
|
2023-10-16 18:32:13 +03:00
|
|
|
await sharedPage.locator('[data-test-nav="settings"]').click();
|
|
|
|
await sharedPage.getByTestId('announcement-bar').getByRole('button', {name: 'Customize'}).click();
|
2023-10-09 10:12:46 +03:00
|
|
|
// Wait for the preview to load
|
2023-10-16 18:32:13 +03:00
|
|
|
await getPreviewFrame(sharedPage).locator('body *:visible').first().waitFor();
|
2023-05-05 13:11:26 +03:00
|
|
|
});
|
2023-10-16 18:32:13 +03:00
|
|
|
return sharedPage.getByTestId('announcement-bar-modal');
|
2023-05-05 13:11:26 +03:00
|
|
|
}
|
|
|
|
|
2023-10-16 18:32:13 +03:00
|
|
|
function getPreviewFrame(sharedPage) {
|
|
|
|
return sharedPage.frameLocator('[data-testid="announcement-bar-preview-iframe"] > iframe[data-visible=true]');
|
2023-05-05 13:11:26 +03:00
|
|
|
}
|