chore: set up preview e2e tests (#21912)

* chore: set up preview e2e tests

* fix: webkit permissions

* fix: webkit permission

* fix: disable clipboard check on webkit

* fix: remove clipboard check
This commit is contained in:
Rémi de Juvigny 2024-10-23 14:22:48 +02:00 committed by GitHub
parent 3db8f1fc61
commit 6ed779c066
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 74 additions and 0 deletions

View File

@ -14,4 +14,16 @@ module.exports = ({ env }) => ({
nps: env.bool('FLAG_NPS', true),
promoteEE: env.bool('FLAG_PROMOTE_EE', true),
},
preview: {
enabled: true,
config: {
handler(uid, { documentId, locale, status }) {
if (uid === 'api::product.product') {
return null;
}
return `https://strapi.io/preview/${uid}/${documentId}/${locale}/${status}`;
},
},
},
});

View File

@ -1,5 +1,6 @@
module.exports = ({ env }) => ({
future: {
contentReleasesScheduling: env.bool('STRAPI_FEATURES_FUTURE_RELEASES_SCHEDULING', false),
preview: true,
},
});

View File

@ -0,0 +1,61 @@
import { test, expect, Page } from '@playwright/test';
import { login } from '../../utils/login';
import { resetDatabaseAndImportDataFromPath } from '../../utils/dts-import';
import { clickAndWait, describeOnCondition, findAndClose, skipCtbTour } from '../../utils/shared';
import { resetFiles } from '../../utils/file-reset';
const edition = process.env.STRAPI_DISABLE_EE === 'true' ? 'CE' : 'EE';
describeOnCondition(edition === 'EE')('Preview', () => {
test.beforeEach(async ({ page }) => {
await resetDatabaseAndImportDataFromPath('with-admin.tar', (cts) => cts, { coreStore: false });
await resetFiles();
await page.goto('/admin');
await page.evaluate(() => window.localStorage.setItem('GUIDED_TOUR_SKIPPED', 'true'));
await login({ page });
await page.waitForURL('/admin');
});
test('Preview button should appear for configured content types', async ({
page,
context,
browser,
}) => {
// Open an edit view for a content type that has preview
await clickAndWait(page, page.getByRole('link', { name: 'Content Manager' }));
await clickAndWait(page, page.getByRole('link', { name: 'Article' }));
await clickAndWait(page, page.getByRole('gridcell', { name: /west ham post match/i }));
// Copy the preview link
await page.getByRole('button', { name: /copy preview link/i }).click();
await findAndClose(page, 'Copied preview link');
// Check that preview opens in a new tab
const newTabPromiseDraft = page.waitForEvent('popup');
await page.getByRole('link', { name: /open preview/i }).click();
const newTab = await newTabPromiseDraft;
expect(newTab.url()).toMatch(/^https:\/\/strapi\.io\/preview\/api::article\.article.*\/draft$/);
// Check that preview link reflects the publication status
await page.getByRole('button', { name: /publish/i }).click();
await findAndClose(page, 'Published document');
await page.getByRole('tab', { name: /published/i }).click();
const newTabPromisePublished = page.waitForEvent('popup');
await page.getByRole('link', { name: /open preview/i }).click();
const newTab2 = await newTabPromisePublished;
expect(newTab2.url()).toMatch(
/^https:\/\/strapi\.io\/preview\/api::article\.article.*\/published$/
);
});
test('Preview button should not appear for content types without preview config', async ({
page,
}) => {
// Open an edit view for a content type that does not have preview
await clickAndWait(page, page.getByRole('link', { name: 'Content Manager' }));
await clickAndWait(page, page.getByRole('link', { name: 'Product' }));
await clickAndWait(page, page.getByRole('gridcell', { name: /nike mens/i }));
await expect(page.getByRole('link', { name: /open preview/i })).not.toBeVisible();
});
});