mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Added Recommendations Acceptance tests - Admin X (#18513)
no issue
---
<!-- Leave the line below if you'd like GitHub Copilot to generate a
summary from your commit -->
<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at ebcfe42</samp>
This pull request adds acceptance tests for the recommendations feature
in the `admin-x-settings` app. It also updates the test utils module to
use the appropriate type and fixture for the recommendations API.
This commit is contained in:
parent
70304d92d4
commit
d0cd7f040d
3 changed files with 81 additions and 0 deletions
|
@ -0,0 +1,61 @@
|
|||
import {expect, test} from '@playwright/test';
|
||||
import {globalDataRequests, mockApi, responseFixtures, toggleLabsFlag} from '../../utils/acceptance';
|
||||
|
||||
test.describe('Recommendations', async () => {
|
||||
test.beforeEach(async () => {
|
||||
toggleLabsFlag('recommendations', true);
|
||||
});
|
||||
test('can add a recommendation', async ({page}) => {
|
||||
const {lastApiRequests} = await mockApi({page, requests: {
|
||||
...globalDataRequests,
|
||||
// mock the GET url with params
|
||||
browseRecommendations: {method: 'GET', path: '/recommendations/?filter=url%3A%7E%27example.com%2Fa-cool-website%27&limit=1', response: responseFixtures.recommendations},
|
||||
addRecommendation: {method: 'POST', path: '/recommendations/', response: {recommendations: [
|
||||
{excerpt: null,
|
||||
favicon: null,
|
||||
featured_image: null,
|
||||
one_click_subscribe: false,
|
||||
reason: 'This is a cool website',
|
||||
title: 'example.com',
|
||||
url: 'https://example.com/a-cool-website'}
|
||||
]}}
|
||||
}});
|
||||
await page.goto('/');
|
||||
|
||||
const section = await page.getByTestId('recommendations');
|
||||
|
||||
// console.log(section);
|
||||
await section.getByRole('button', {name: 'Add recommendation'}).click();
|
||||
|
||||
const modal = page.getByTestId('add-recommendation-modal');
|
||||
modal.getByRole('textbox').fill('https://example.com/a-cool-website');
|
||||
await modal.getByRole('button', {name: 'Next'}).click();
|
||||
modal.getByLabel('SHORT DESCRIPTION').fill('This is a cool website');
|
||||
await modal.getByRole('button', {name: 'Add'}).click();
|
||||
expect(lastApiRequests.addRecommendation?.body).toEqual({
|
||||
recommendations: [
|
||||
{excerpt: null,
|
||||
favicon: null,
|
||||
featured_image: null,
|
||||
one_click_subscribe: false,
|
||||
reason: 'This is a cool website',
|
||||
title: 'example.com',
|
||||
url: 'https://example.com/a-cool-website'}
|
||||
]
|
||||
});
|
||||
});
|
||||
|
||||
test('errors when passing an invalid URL', async ({page}) => {
|
||||
await mockApi({page, requests: {
|
||||
...globalDataRequests,
|
||||
browseRecommendations: {method: 'GET', path: '/recommendations/?filter=url%3A%7E%27example.com%2Fa-cool-website%27&limit=1', response: responseFixtures.recommendations}
|
||||
}});
|
||||
await page.goto('/');
|
||||
const section = await page.getByTestId('recommendations');
|
||||
await section.getByRole('button', {name: 'Add recommendation'}).click();
|
||||
const modal = page.getByTestId('add-recommendation-modal');
|
||||
modal.getByRole('textbox').fill('not a real url');
|
||||
await modal.getByRole('button', {name: 'Next'}).click();
|
||||
await expect(modal).toContainText('Please enter a valid URL.');
|
||||
});
|
||||
});
|
|
@ -6,6 +6,7 @@ import {LabelsResponseType} from '../../src/api/labels';
|
|||
import {Locator, Page} from '@playwright/test';
|
||||
import {NewslettersResponseType} from '../../src/api/newsletters';
|
||||
import {OffersResponseType} from '../../src/api/offers';
|
||||
import {RecommendationResponseType} from '../../src/api/recommendations';
|
||||
import {RolesResponseType} from '../../src/api/roles';
|
||||
import {SettingsResponseType} from '../../src/api/settings';
|
||||
import {SiteResponseType} from '../../src/api/site';
|
||||
|
@ -31,6 +32,7 @@ const siteFixture = JSON.parse(readFileSync(`${__dirname}/responses/site.json`).
|
|||
|
||||
export const responseFixtures = {
|
||||
settings: JSON.parse(readFileSync(`${__dirname}/responses/settings.json`).toString()) as SettingsResponseType,
|
||||
recommendations: JSON.parse(readFileSync(`${__dirname}/responses/recommendations.json`).toString()) as RecommendationResponseType,
|
||||
config: JSON.parse(readFileSync(`${__dirname}/responses/config.json`).toString()) as ConfigResponseType,
|
||||
users: JSON.parse(readFileSync(`${__dirname}/responses/users.json`).toString()) as UsersResponseType,
|
||||
me: JSON.parse(readFileSync(`${__dirname}/responses/me.json`).toString()) as UsersResponseType,
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"recommendations": {
|
||||
"id": "21452552",
|
||||
"title": "Some Recommendation",
|
||||
"reason": "i like this website",
|
||||
"excerpt": "this is a great website",
|
||||
"feature_image": null,
|
||||
"favicon": null,
|
||||
"url": "http://www.google.com",
|
||||
"one_click_subscribe": "false",
|
||||
"created_at": "2023-10-28T20:00:00.000Z",
|
||||
"updated_at": "2023-10-30T20:00:00.000Z",
|
||||
"count": {
|
||||
"impressions": 30,
|
||||
"subscriptions": 3
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue