0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-27 22:49:56 -05:00
ghost/apps/comments-ui/test/e2e/autoclose-forms.test.ts
Ronald Langeveld cf6884d098
Wired up Admin Comment Endpoints to UI (#21661)
ref PLG-227

- Updated logic that allows Admin Users on comments to interact with
some endpoints from a specific admin-only route.
- It pulls 2 admin specific routes:
- 1. an admin specific 'browse' route that includes hidden comments that
would otherwise be hidden from regular users and members.
- 2. A specific replies route, that would also include hidden comments
- This was needed in order to get accurate pagination.

- Additionally, it wires up the routes via `message-handler` that deal
with the potential cors issues.
- Includes style updates

---------

Co-authored-by: Sanne de Vries <sannedv@protonmail.com>
Co-authored-by: Kevin Ansfield <kevin@lookingsideways.co.uk>
2024-11-21 10:52:36 +00:00

65 lines
2.2 KiB
TypeScript

import {FrameLocator, expect, test} from '@playwright/test';
import {MockedApi, initialize, waitEditorFocused} from '../utils/e2e';
import {buildReply} from '../utils/fixtures';
test.describe('Autoclose forms', async () => {
let mockedApi: MockedApi;
let frame: FrameLocator;
test.beforeEach(async ({page}) => {
mockedApi = new MockedApi({});
mockedApi.setMember({});
mockedApi.addComment({
html: '<p>Comment 1</p>',
replies: [{
html: '<p>Reply 1.1</p>'
}, {
html: '<p>Reply 1.2</p>'
}].map(buildReply)
});
mockedApi.addComment({
html: '<p>Comment 2</p>'
});
({frame} = await initialize({
mockedApi,
page,
publication: 'Publisher weekly',
labs: {
commentImprovements: true
}
}));
});
// NOTE: form counts are replies + 1 for the main form that is now always shown
// at the top of the comments list
test('autocloses open reply forms when opening another', async ({}) => {
const comment1 = await frame.getByTestId('comment-component').nth(0);
await comment1.getByTestId('reply-button').nth(1).click();
await expect(frame.getByTestId('form')).toHaveCount(2);
const comment2 = await frame.getByTestId('comment-component').nth(3);
await comment2.getByTestId('reply-button').click();
await expect(frame.getByTestId('form')).toHaveCount(2);
});
test('does not autoclose open reply form with unsaved changes', async ({}) => {
const comment1 = await frame.getByTestId('comment-component').nth(0);
await comment1.getByTestId('reply-button').nth(1).click();
await expect(frame.getByTestId('form')).toHaveCount(2);
const editor = frame.getByTestId('form-editor').nth(1);
await waitEditorFocused(editor);
await editor.type('Replying to comment 1');
const comment2 = await frame.getByTestId('comment-component').nth(3);
await comment2.getByTestId('reply-button').click();
await expect(frame.getByTestId('form')).toHaveCount(3);
});
});