Ghost/apps/comments-ui/test/e2e/options.test.ts
Simon Backx 8d6fb51908 Added Playwright tests to comments-ui
refs https://github.com/TryGhost/Team/issues/3504

Not complete yet, but contains the basic structure and a few tests that work and should run in CI.
2023-06-22 15:06:13 +02:00

73 lines
2.2 KiB
TypeScript

import {MockedApi, initialize} from '../utils/e2e';
import {expect, test} from '@playwright/test';
test.describe('Options', async () => {
test('Shows the title and count', async ({page}) => {
const mockedApi = new MockedApi({});
mockedApi.addComments(2);
const {frame} = await initialize({
mockedApi,
page,
title: 'Leave a comment',
publication: 'Publisher Weekly',
count: true
});
// Check text 'Leave a comment' is present
await expect(frame.getByTestId('title')).toHaveText('Leave a comment');
await expect(frame.getByTestId('count')).toHaveText('2 comments');
});
test('Shows the title and singular count', async ({page}) => {
const mockedApi = new MockedApi({});
mockedApi.addComments(1);
const {frame} = await initialize({
mockedApi,
page,
title: 'Leave a comment',
publication: 'Publisher Weekly',
count: true
});
// Check text 'Leave a comment' is present
await expect(frame.getByTestId('title')).toHaveText('Leave a comment');
await expect(frame.getByTestId('count')).toHaveText('1 comment');
});
test('Shows the title but hides the count', async ({page}) => {
const mockedApi = new MockedApi({});
mockedApi.addComments(2);
const {frame} = await initialize({
mockedApi,
page,
title: 'Leave a comment',
publication: 'Publisher Weekly',
count: false
});
// Check text 'Leave a comment' is present
await expect(frame.getByTestId('title')).toHaveText('Leave a comment');
// Check count is hidden
await expect(frame.getByTestId('count')).not.toBeVisible();
});
test('Hides title and count', async ({page}) => {
const mockedApi = new MockedApi({});
mockedApi.addComments(2);
const {frame} = await initialize({
mockedApi,
page,
publication: 'Publisher Weekly'
});
await expect(frame.getByTestId('title')).not.toBeVisible();
await expect(frame.getByTestId('count')).not.toBeVisible();
});
});