2023-08-17 12:20:40 +03:00
|
|
|
import {MOCKED_SITE_URL, MockedApi, initialize, mockAdminAuthFrame} from '../utils/e2e';
|
|
|
|
import {expect, test} from '@playwright/test';
|
|
|
|
|
|
|
|
const admin = MOCKED_SITE_URL + '/ghost/';
|
|
|
|
|
|
|
|
test.describe('Auth Frame', async () => {
|
2024-03-05 18:57:20 +03:00
|
|
|
test('skips rendering the auth frame with no comments', async ({page}) => {
|
2023-08-17 12:20:40 +03:00
|
|
|
const mockedApi = new MockedApi({});
|
|
|
|
await initialize({
|
|
|
|
mockedApi,
|
|
|
|
page,
|
|
|
|
publication: 'Publisher Weekly',
|
|
|
|
admin
|
|
|
|
});
|
|
|
|
|
2024-03-05 18:57:20 +03:00
|
|
|
const iframeElement = await page.locator('iframe[data-frame="admin-auth"]');
|
|
|
|
await expect(iframeElement).toHaveCount(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('renders the auth frame when there are comments', async ({page}) => {
|
|
|
|
const mockedApi = new MockedApi({});
|
|
|
|
mockedApi.addComment({
|
|
|
|
html: '<p>This is comment 1</p>'
|
|
|
|
});
|
|
|
|
|
|
|
|
await initialize({
|
|
|
|
mockedApi,
|
|
|
|
page,
|
|
|
|
publication: 'Publisher Weekly',
|
|
|
|
admin
|
|
|
|
});
|
|
|
|
|
2023-08-17 12:20:40 +03:00
|
|
|
const iframeElement = await page.locator('iframe[data-frame="admin-auth"]');
|
|
|
|
await expect(iframeElement).toHaveCount(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('has no admin options', async ({page}) => {
|
|
|
|
const mockedApi = new MockedApi({});
|
|
|
|
mockedApi.addComment({
|
|
|
|
html: '<p>This is comment 1</p>'
|
|
|
|
});
|
|
|
|
mockedApi.addComment({
|
|
|
|
html: '<p>This is comment 2</p>'
|
|
|
|
});
|
|
|
|
mockedApi.addComment({
|
|
|
|
html: '<p>This is comment 3</p>'
|
|
|
|
});
|
|
|
|
mockedApi.addComment({
|
|
|
|
html: '<p>This is comment 4</p>'
|
|
|
|
});
|
|
|
|
mockedApi.addComment({
|
|
|
|
html: '<p>This is comment 5</p>'
|
|
|
|
});
|
|
|
|
|
|
|
|
const {frame} = await initialize({
|
|
|
|
mockedApi,
|
|
|
|
page,
|
|
|
|
publication: 'Publisher Weekly',
|
|
|
|
admin
|
|
|
|
});
|
|
|
|
|
|
|
|
const iframeElement = await page.locator('iframe[data-frame="admin-auth"]');
|
|
|
|
await expect(iframeElement).toHaveCount(1);
|
|
|
|
|
2024-03-05 18:57:20 +03:00
|
|
|
const comments = await frame.getByTestId('comment-component');
|
2023-08-17 12:20:40 +03:00
|
|
|
await expect(comments).toHaveCount(5);
|
|
|
|
|
|
|
|
const moreButtons = await frame.getByTestId('more-button');
|
|
|
|
await expect(moreButtons).toHaveCount(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('has admin options when signed in to Ghost admin', async ({page}) => {
|
|
|
|
const mockedApi = new MockedApi({});
|
|
|
|
mockedApi.addComment({
|
|
|
|
html: '<p>This is comment 1</p>'
|
|
|
|
});
|
|
|
|
mockedApi.addComment({
|
|
|
|
html: '<p>This is comment 2</p>'
|
|
|
|
});
|
|
|
|
mockedApi.addComment({
|
|
|
|
html: '<p>This is comment 3</p>'
|
|
|
|
});
|
|
|
|
mockedApi.addComment({
|
|
|
|
html: '<p>This is comment 4</p>'
|
|
|
|
});
|
|
|
|
mockedApi.addComment({
|
|
|
|
html: '<p>This is comment 5</p>'
|
|
|
|
});
|
|
|
|
|
|
|
|
await mockAdminAuthFrame({
|
|
|
|
admin,
|
|
|
|
page
|
|
|
|
});
|
|
|
|
|
|
|
|
const {frame} = await initialize({
|
|
|
|
mockedApi,
|
|
|
|
page,
|
|
|
|
publication: 'Publisher Weekly',
|
|
|
|
admin
|
|
|
|
});
|
|
|
|
|
|
|
|
const iframeElement = await page.locator('iframe[data-frame="admin-auth"]');
|
|
|
|
await expect(iframeElement).toHaveCount(1);
|
|
|
|
|
|
|
|
// Check if more actions button is visible on each comment
|
2024-03-05 18:57:20 +03:00
|
|
|
const comments = await frame.getByTestId('comment-component');
|
2023-08-17 12:20:40 +03:00
|
|
|
await expect(comments).toHaveCount(5);
|
|
|
|
|
|
|
|
const moreButtons = await frame.getByTestId('more-button');
|
|
|
|
await expect(moreButtons).toHaveCount(5);
|
|
|
|
|
|
|
|
// Click the 2nd button
|
|
|
|
await moreButtons.nth(1).click();
|
|
|
|
await moreButtons.nth(1).getByText('Hide comment').click();
|
|
|
|
|
|
|
|
// Check comment2 is replaced with a hidden message
|
|
|
|
const secondComment = comments.nth(1);
|
|
|
|
await expect(secondComment).toHaveText('This comment has been hidden.');
|
2024-02-27 23:04:56 +03:00
|
|
|
await expect(secondComment).not.toContainText('This is comment 2');
|
2023-08-17 12:20:40 +03:00
|
|
|
|
|
|
|
// Check can show it again
|
|
|
|
await moreButtons.nth(1).click();
|
|
|
|
await moreButtons.nth(1).getByText('Show comment').click();
|
2024-02-27 23:04:56 +03:00
|
|
|
await expect(secondComment).toContainText('This is comment 2');
|
2023-08-17 12:20:40 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
test('has admin options when signed in to Ghost admin and as a member', async ({page}) => {
|
|
|
|
const mockedApi = new MockedApi({});
|
|
|
|
mockedApi.setMember({});
|
|
|
|
|
|
|
|
mockedApi.addComment({
|
|
|
|
html: '<p>This is comment 1</p>'
|
|
|
|
});
|
|
|
|
mockedApi.addComment({
|
|
|
|
html: '<p>This is comment 2</p>'
|
|
|
|
});
|
|
|
|
mockedApi.addComment({
|
|
|
|
html: '<p>This is comment 3</p>'
|
|
|
|
});
|
|
|
|
mockedApi.addComment({
|
|
|
|
html: '<p>This is comment 4</p>'
|
|
|
|
});
|
|
|
|
mockedApi.addComment({
|
|
|
|
html: '<p>This is comment 5</p>'
|
|
|
|
});
|
|
|
|
|
|
|
|
await mockAdminAuthFrame({
|
|
|
|
admin,
|
|
|
|
page
|
|
|
|
});
|
|
|
|
|
|
|
|
const {frame} = await initialize({
|
|
|
|
mockedApi,
|
|
|
|
page,
|
|
|
|
publication: 'Publisher Weekly',
|
|
|
|
admin
|
|
|
|
});
|
|
|
|
|
|
|
|
const iframeElement = await page.locator('iframe[data-frame="admin-auth"]');
|
|
|
|
await expect(iframeElement).toHaveCount(1);
|
|
|
|
|
|
|
|
// Check if more actions button is visible on each comment
|
2024-03-05 18:57:20 +03:00
|
|
|
const comments = await frame.getByTestId('comment-component');
|
2023-08-17 12:20:40 +03:00
|
|
|
await expect(comments).toHaveCount(5);
|
|
|
|
|
|
|
|
const moreButtons = await frame.getByTestId('more-button');
|
|
|
|
await expect(moreButtons).toHaveCount(5);
|
|
|
|
|
|
|
|
// Click the 2nd button
|
|
|
|
await moreButtons.nth(1).click();
|
|
|
|
await moreButtons.nth(1).getByText('Hide comment').click();
|
|
|
|
|
|
|
|
// Check comment2 is replaced with a hidden message
|
|
|
|
const secondComment = comments.nth(1);
|
|
|
|
await expect(secondComment).toHaveText('This comment has been hidden.');
|
2024-02-27 23:04:56 +03:00
|
|
|
await expect(secondComment).not.toContainText('This is comment 2');
|
2023-08-17 12:20:40 +03:00
|
|
|
|
|
|
|
// Check can show it again
|
|
|
|
await moreButtons.nth(1).click();
|
|
|
|
await moreButtons.nth(1).getByText('Show comment').click();
|
2024-02-27 23:04:56 +03:00
|
|
|
await expect(secondComment).toContainText('This is comment 2');
|
2023-08-17 12:20:40 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|