0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00
ghost/apps/admin-x-settings/test/e2e/advanced/integrations/pintura.test.ts
Ronald Langeveld d9cee38a77
Wired up Pintura integration to AdminX (#17759)
refs https://github.com/TryGhost/Product/issues/3729

- Wired up the Pintura Integration to AdminX.

---

<!-- Leave the line below if you'd like GitHub Copilot to generate a
summary from your commit -->
<!--
copilot:summary
-->
### <samp>🤖 Generated by Copilot at 4d33355</samp>

This pull request adds the ability to customize the Pintura image editor
with custom JS and CSS files in the advanced settings modal. It
introduces a new `files.ts` file in the `api` folder, which provides a
hook and a helper function for uploading and retrieving files. It also
modifies the `PinturaModal.tsx` component to use these functions and
display the settings.
2023-08-18 14:54:13 +02:00

104 lines
4.7 KiB
TypeScript

import {expect, test} from '@playwright/test';
import {globalDataRequests, mockApi, updatedSettingsResponse} from '../../../utils/e2e';
test.describe('Pintura integration', async () => {
test('Can toggle Pintura', async ({page}) => {
const {lastApiRequests} = await mockApi({page, requests: {
...globalDataRequests,
editSettings: {method: 'PUT', path: '/settings/', response: updatedSettingsResponse([
{key: 'pintura', value: false}
])}
}});
await page.goto('/');
const section = page.getByTestId('integrations');
const pinturaElement = section.getByText('Pintura').last();
await pinturaElement.hover();
await page.getByRole('button', {name: 'Configure'}).click();
const pinturaModal = page.getByTestId('pintura-modal');
const pinturaToggle = pinturaModal.getByRole('switch');
await pinturaToggle.click();
// Upload Pintura script text should be visible
await expect(pinturaModal.getByText('Upload Pintura script')).toBeVisible();
await expect(pinturaModal.getByText('Upload Pintura styles')).toBeVisible();
await pinturaToggle.click();
await expect(pinturaModal.getByText('Upload Pintura script')).not.toBeVisible();
await expect(pinturaModal.getByText('Upload Pintura styles')).not.toBeVisible();
// we want it true, so click again
await pinturaToggle.click();
await page.getByRole('button', {name: 'Save'}).click();
expect(lastApiRequests.editSettings?.body).toEqual({
settings: [
{key: 'pintura', value: true}
]
});
});
test('Can upload Pintura script', async ({page}) => {
const {lastApiRequests} = await mockApi({page, requests: {
...globalDataRequests,
uploadFile: {method: 'POST', path: '/files/upload/', response: {files: [{url: 'http://example.com/pintura-umd.js', ref: null}]}},
editSettings: {method: 'PUT', path: '/settings/', response: updatedSettingsResponse([
{key: 'pintura_js_url', value: 'http://example.com/pintura-umd.js'}
])}
}});
await page.goto('/');
const section = page.getByTestId('integrations');
const pinturaElement = section.getByText('Pintura').last();
await pinturaElement.hover();
await page.getByRole('button', {name: 'Configure'}).click();
const pinturaModal = page.getByTestId('pintura-modal');
const pinturaToggle = pinturaModal.getByRole('switch');
await pinturaToggle.click();
const jsFileChooserPromise = page.waitForEvent('filechooser');
const jsUploadButton = pinturaModal.getByRole('button', {name: 'Upload'}).first();
await jsUploadButton.click();
const jsFileChooser = await jsFileChooserPromise;
await jsFileChooser.setFiles(`${__dirname}/../../../utils/files/pintura-umd.js`);
await expect(jsUploadButton).toBeEnabled();
expect(lastApiRequests.editSettings?.body).toEqual({
settings: [
{key: 'pintura_js_url', value: 'http://example.com/pintura-umd.js'}
]
});
});
test('Can upload Pintura styles', async ({page}) => {
const {lastApiRequests} = await mockApi({page, requests: {
...globalDataRequests,
uploadFile: {method: 'POST', path: '/files/upload/', response: {files: [{url: 'http://example.com/pintura.css', ref: null}]}},
editSettings: {method: 'PUT', path: '/settings/', response: updatedSettingsResponse([
{key: 'pintura_css_url', value: 'http://example.com/pintura.css'}
])}
}});
await page.goto('/');
const section = page.getByTestId('integrations');
const pinturaElement = section.getByText('Pintura').last();
await pinturaElement.hover();
await page.getByRole('button', {name: 'Configure'}).click();
const pinturaModal = page.getByTestId('pintura-modal');
const pinturaToggle = pinturaModal.getByRole('switch');
await pinturaToggle.click();
const cssFileChooserPromise = page.waitForEvent('filechooser');
const cssUploadButton = pinturaModal.getByRole('button', {name: 'Upload'}).last();
await cssUploadButton.click();
const cssFileChooser = await cssFileChooserPromise;
await cssFileChooser.setFiles(`${__dirname}/../../../utils/files/pintura.css`);
await expect(cssUploadButton).toBeEnabled();
expect(lastApiRequests.editSettings?.body).toEqual({
settings: [
{key: 'pintura_css_url', value: 'http://example.com/pintura.css'}
]
});
});
});