From 330ea766d2b6d28ba976aca87d18944df5fc51e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20=C4=8Ciko=C5=A1?= Date: Mon, 7 Oct 2024 10:29:57 +0200 Subject: [PATCH] LPD-37782 Add test --- .../env/client-extensions.list | 1 + .../fixtures/ckeditorSamplePageTest.ts | 18 +++++++ .../pages/CKEditorSamplePage.ts | 42 ++++++++++++++++ .../react.spec.ts | 50 +++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 modules/test/playwright/tests/frontend-editor-ckeditor-web/env/client-extensions.list create mode 100644 modules/test/playwright/tests/frontend-editor-ckeditor-web/fixtures/ckeditorSamplePageTest.ts create mode 100644 modules/test/playwright/tests/frontend-editor-ckeditor-web/pages/CKEditorSamplePage.ts create mode 100644 modules/test/playwright/tests/frontend-editor-ckeditor-web/react.spec.ts diff --git a/modules/test/playwright/tests/frontend-editor-ckeditor-web/env/client-extensions.list b/modules/test/playwright/tests/frontend-editor-ckeditor-web/env/client-extensions.list new file mode 100644 index 00000000000000..77a83733e0b63c --- /dev/null +++ b/modules/test/playwright/tests/frontend-editor-ckeditor-web/env/client-extensions.list @@ -0,0 +1 @@ +liferay-sample-editor-config-contributor \ No newline at end of file diff --git a/modules/test/playwright/tests/frontend-editor-ckeditor-web/fixtures/ckeditorSamplePageTest.ts b/modules/test/playwright/tests/frontend-editor-ckeditor-web/fixtures/ckeditorSamplePageTest.ts new file mode 100644 index 00000000000000..b680076fd510a5 --- /dev/null +++ b/modules/test/playwright/tests/frontend-editor-ckeditor-web/fixtures/ckeditorSamplePageTest.ts @@ -0,0 +1,18 @@ +/** + * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com + * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 + */ + +import {test} from '@playwright/test'; + +import {CKEditorSamplePage} from '../pages/CKEditorSamplePage'; + +const ckeditorSamplePageTest = test.extend<{ + ckeditorSamplePage: CKEditorSamplePage; +}>({ + ckeditorSamplePage: async ({page}, use) => { + await use(new CKEditorSamplePage(page)); + }, +}); + +export {ckeditorSamplePageTest}; diff --git a/modules/test/playwright/tests/frontend-editor-ckeditor-web/pages/CKEditorSamplePage.ts b/modules/test/playwright/tests/frontend-editor-ckeditor-web/pages/CKEditorSamplePage.ts new file mode 100644 index 00000000000000..f97d204ce12e2d --- /dev/null +++ b/modules/test/playwright/tests/frontend-editor-ckeditor-web/pages/CKEditorSamplePage.ts @@ -0,0 +1,42 @@ +/** + * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com + * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 + */ + +import {Page} from '@playwright/test'; + +import {ApiHelpers} from '../../../helpers/ApiHelpers'; +import {liferayConfig} from '../../../liferay.config'; +import getRandomString from '../../../utils/getRandomString'; +import getPageDefinition from '../../layout-content-page-editor-web/utils/getPageDefinition'; +import getWidgetDefinition from '../../layout-content-page-editor-web/utils/getWidgetDefinition'; + +export class CKEditorSamplePage { + readonly apiHelpers: ApiHelpers; + readonly page: Page; + + constructor(page: Page) { + this.apiHelpers = new ApiHelpers(page); + this.page = page; + } + + async createAndGotoSitePage({site}: {site: Site}) { + const widgetDefinition = getWidgetDefinition({ + id: getRandomString(), + widgetName: + 'com_liferay_editor_ckeditor_sample_web_internal_portlet_CKEditorSamplePortlet', + }); + + const title = getRandomString(); + + await this.apiHelpers.headlessDelivery.createSitePage({ + pageDefinition: getPageDefinition([widgetDefinition]), + siteId: site.id, + title, + }); + + await this.page.goto( + `${liferayConfig.environment.baseUrl}/web${site.friendlyUrlPath}/${title}` + ); + } +} diff --git a/modules/test/playwright/tests/frontend-editor-ckeditor-web/react.spec.ts b/modules/test/playwright/tests/frontend-editor-ckeditor-web/react.spec.ts new file mode 100644 index 00000000000000..26aae14bb6c414 --- /dev/null +++ b/modules/test/playwright/tests/frontend-editor-ckeditor-web/react.spec.ts @@ -0,0 +1,50 @@ +/** + * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com + * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 + */ + +import {expect, mergeTests} from '@playwright/test'; + +import {apiHelpersTest} from '../../fixtures/apiHelpersTest'; +import {featureFlagsTest} from '../../fixtures/featureFlagsTest'; +import {isolatedSiteTest} from '../../fixtures/isolatedSiteTest'; +import {loginTest} from '../../fixtures/loginTest'; +import {ckeditorSamplePageTest} from './fixtures/ckeditorSamplePageTest'; + +export const test = mergeTests( + apiHelpersTest, + featureFlagsTest({ + 'LPS-178052': true, + }), + isolatedSiteTest, + loginTest(), + ckeditorSamplePageTest +); + +test.beforeEach(async ({ckeditorSamplePage, page, site}) => { + await ckeditorSamplePage.createAndGotoSitePage({site}); + + const reactTab = page.getByRole('tab', { + name: 'React', + }); + + await reactTab.click(); + + expect( + page.getByText('Classic Editor used from a React component') + ).toBeVisible(); +}); + +test( + 'Editor configuration object must not be mutated', + {tag: '@LPD-37782'}, + async ({page}) => { + const iframe = page.frameLocator( + 'iframe[title$="sampleReactClassicEditor"]' + ); + + expect( + iframe.getByText('Editor configuration object was not mutated.') + ).toBeVisible(); + } +);