Skip to content

Commit

Permalink
Merge pull request #8983 from weseek/support/148793-replace-tests-wit…
Browse files Browse the repository at this point in the history
…h-playwright

support: Replace tests with playwright (23-editor/23-editor--with-navigation.cy.ts)
  • Loading branch information
miya authored Jul 26, 2024
2 parents a933337 + d068a62 commit f98e944
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 178 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/reusable-app-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ jobs:
fail-fast: false
matrix:
# List string expressions that is comma separated ids of tests in "test/cypress/integration"
spec-group: ['21', '23', '30', '50']
spec-group: ['21', '30', '50']

services:
mongodb:
Expand Down
113 changes: 113 additions & 0 deletions apps/app/playwright/23-editor/with-navigation.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { readFileSync } from 'fs';
import path from 'path';

import { test, expect, type Page } from '@playwright/test';

/**
* for the issues:
* @see https://redmine.weseek.co.jp/issues/122040
* @see https://redmine.weseek.co.jp/issues/124281
*/
test('should not be cleared and should prevent GrantSelector from modified', async({ page }) => {
await page.goto('/Sandbox/for-122040');

// Open Editor
await page.getByTestId('editor-button').click();
await expect(page.getByTestId('grw-editor-navbar-bottom')).toBeVisible();

// Open GrantSelector and select "only me"
await page.getByTestId('grw-grant-selector').click();
const dropdownMenu = page.getByTestId('grw-grant-selector-dropdown-menu');
await expect(dropdownMenu).toBeVisible();
await dropdownMenu.locator('.dropdown-item').nth(2).click();
await expect(page.getByTestId('grw-grant-selector')).toContainText('Only me');

// Upload attachment
const filePath = path.resolve(__dirname, '../23-editor/assets/example.txt');
const buffer = readFileSync(filePath).toString('base64');
const dataTransfer = await page.evaluateHandle(
async({ bufferData, localFileName, localFileType }) => {
const dt = new DataTransfer();

const blobData = await fetch(bufferData).then(res => res.blob());

const file = new File([blobData], localFileName, {
type: localFileType,
});
dt.items.add(file);
return dt;
},
{
bufferData: `data:application/octet-stream;base64,${buffer}`,
localFileName: 'sample.tst',
localFileType: 'application/octet-stream',
},
);
await page.locator('.dropzone').first().dispatchEvent('drop', { dataTransfer });
await expect(page.getByTestId('page-editor-preview-body').getByTestId('rich-attachment')).toBeVisible();

// Save page
await page.getByTestId('save-page-btn').click();

// Expect grant not to be reset after uploading an attachment
await expect(page.getByTestId('page-grant-alert')).toContainText('Browsing of this page is restricted');
});

const appendTextToEditorUntilContains = async(page: Page, text: string) => {
await page.locator('.cm-content').fill(text);
await expect(page.getByTestId('page-editor-preview-body')).toContainText(text);
};

/**
* for the issue:
* @see https://redmine.weseek.co.jp/issues/115285
*/
test('Successfully updating the page body', async({ page }) => {
const page1Path = '/Sandbox/for-115285/page1';
const page2Path = '/Sandbox/for-115285/page2';

const page1Body = 'Hello';
const page2Body = 'World';


await page.goto(page1Path);

// Open Editor (page1)
await page.getByTestId('editor-button').click();
await expect(page.getByTestId('grw-editor-navbar-bottom')).toBeVisible();

// Append text
await appendTextToEditorUntilContains(page, page1Body);

// Save page
await page.getByTestId('save-page-btn').click();

await expect(page.locator('.main')).toContainText(page1Body);

Check failure on line 85 in apps/app/playwright/23-editor/with-navigation.spec.ts

View workflow job for this annotation

GitHub Actions / test-prod-node20 / run-playwright (webkit, 2/2)

[webkit] › 23-editor/with-navigation.spec.ts:65:5 › Successfully updating the page body

2) [webkit] › 23-editor/with-navigation.spec.ts:65:5 › Successfully updating the page body ─────── Error: Timed out 7000ms waiting for expect(locator).toContainText(expected) Locator: locator('.main') Expected string: "Hello" Received string: "home/Sandbox/for-115285/page1content_pasteCopy to clipboardAppend paramsPage path/Sandbox/for-115285/page1Page URLhttp://localhost:3000/Sandbox/for-115285/page1Permanent linkhttp://localhost:3000/66a30eebd08a46b85b2804cbPage path and permanent link/Sandbox/for-115285/page1http://localhost:3000/66a30eebd08a46b85b2804cbMarkdown link[/Sandbox/for-115285/page1](http://localhost:3000/66a30eebd08a46b85b2804cb)infoThis page is still being writtenPublish pageCommmentsadd_commentAdd a comment...local_offerlocal_offerTagssubjectPage List1chatComments0" Call log: - expect.toContainText with timeout 7000ms - waiting for locator('.main') - locator resolved to <div class="main d-edit-none PageViewLayout_page-view-layout__c6O_V flex-expand-vert ps-sidebar">…</div> - unexpected value "home/Sandbox/for-115285/page1content_pasteCopy to clipboardAppend paramsPage path/Sandbox/for-115285/page1Page URLhttp://localhost:3000/Sandbox/for-115285/page1Permanent linkhttp://localhost:3000/66a30eebd08a46b85b2804cbPage path and permanent link/Sandbox/for-115285/page1http://localhost:3000/66a30eebd08a46b85b2804cbMarkdown link[/Sandbox/for-115285/page1](http://localhost:3000/66a30eebd08a46b85b2804cb)infoThis page is still being writtenPublish pageCommmentsadd_commentAdd a comment...local_offerlocal_offerTagssubjectPage List1chatComments0" - locator resolved to <div class="main d-edit-none PageViewLayout_page-view-layout__c6O_V flex-expand-vert ps-sidebar">…</div> - unexpected value "home/Sandbox/for-115285/page1content_pasteCopy to clipboardAppend paramsPage path/Sandbox/for-115285/page1Page URLhttp://localhost:3000/Sandbox/for-115285/page1Permanent linkhttp://localhost:3000/66a30eebd08a46b85b2804cbPage path and permanent link/Sandbox/for-115285/page1http://localhost:3000/66a30eebd08a46b85b2804cbMarkdown link[/Sandbox/for-115285/page1](http://localhost:3000/66a30eebd08a46b85b2804cb)infoThis page is still being writtenPublish pageCommmentsadd_commentAdd a comment...local_offerlocal_offerTagssubjectPage List1chatComments0" 83 | await page.getByTestId('save-page-btn').click(); 84 | > 85 | await expect(page.locator('.main')).toContainText(page1Body); | ^ 86 | 87 | // Duplicate page1 88 | await page.getByTestId('grw-contextual-sub-nav').getByTestId('open-page-item-control-btn').click(); at /__w/growi/growi/apps/app/playwright/23-editor/with-navigation.spec.ts:85:39

// Duplicate page1
await page.getByTestId('grw-contextual-sub-nav').getByTestId('open-page-item-control-btn').click();
await page.getByTestId('open-page-duplicate-modal-btn').click();
await expect(page.getByTestId('page-duplicate-modal')).toBeVisible();
await page.locator('.form-control').fill(page2Path);
await page.getByTestId('btn-duplicate').click();

// Open Editor (page2)
await page.getByTestId('editor-button').click();
await expect(page.getByTestId('grw-editor-navbar-bottom')).toBeVisible();

// Expect to see the text from which you are duplicating
await expect(page.getByTestId('page-editor-preview-body')).toContainText(page1Body);

// Append text
await appendTextToEditorUntilContains(page, page1Body + page2Body);


await page.goto(page1Path);

// Open Editor (page1)
await page.getByTestId('editor-button').click();
await expect(page.getByTestId('grw-editor-navbar-bottom')).toBeVisible();

await expect(page.getByTestId('page-editor-preview-body')).toContainText(page1Body);

});
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const RichAttachment = React.memo((props: RichAttachmentProps) => {
}

return (
<div className={`${styles.attachment} d-inline-block`}>
<div data-testid="rich-attachment" className={`${styles.attachment} d-inline-block`}>
<div className="my-2 p-2 card">
<div className="p-1 card-body d-flex align-items-center">
<div className="me-2 px-0 d-flex align-items-center justify-content-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const PageGrantAlert = (): JSX.Element => {


return (
<p className="alert alert-primary py-3 px-4">
<p data-testid="page-grant-alert" className="alert alert-primary py-3 px-4">
{renderAlertContent()}
</p>
);
Expand Down
175 changes: 0 additions & 175 deletions apps/app/test/cypress/e2e/23-editor/23-editor--with-navigation.cy.ts

This file was deleted.

0 comments on commit f98e944

Please sign in to comment.