From a5cbc7dec6c82174dcaf1403f7937b436861f28d Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Tue, 28 Jan 2025 14:53:53 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=85(e2e)=20fix=20flakiness?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some flakiness appeared in the e2e tests. It started to impact many pull requests. Time to fix them. --- .../apps/e2e/__tests__/app-impress/common.ts | 14 +++- .../__tests__/app-impress/doc-editor.spec.ts | 13 ++-- .../app-impress/doc-favorite.spec.ts | 75 ------------------- .../__tests__/app-impress/doc-grid.spec.ts | 27 +++++++ .../app-impress/doc-member-create.spec.ts | 18 +++-- .../doc-share/components/DocShareModal.tsx | 5 +- .../docs/docs-grid/components/DocsGrid.tsx | 1 + .../docs-grid/components/SimpleDocItem.tsx | 8 +- 8 files changed, 69 insertions(+), 92 deletions(-) delete mode 100644 src/frontend/apps/e2e/__tests__/app-impress/doc-favorite.spec.ts diff --git a/src/frontend/apps/e2e/__tests__/app-impress/common.ts b/src/frontend/apps/e2e/__tests__/app-impress/common.ts index e067bc7a7..fe595accc 100644 --- a/src/frontend/apps/e2e/__tests__/app-impress/common.ts +++ b/src/frontend/apps/e2e/__tests__/app-impress/common.ts @@ -26,7 +26,7 @@ export const createDoc = async ( page: Page, docName: string, browserName: string, - length: number, + length: number = 1, ) => { const randomDocs = randomName(docName, browserName, length); @@ -91,6 +91,18 @@ export const addNewMember = async ( return users[index].email; }; +export const getGridRow = async (page: Page, title: string) => { + const docsGrid = page.getByRole('grid'); + await expect(docsGrid).toBeVisible(); + await expect(docsGrid.getByTestId('grid-loader')).toBeHidden(); + + const rows = docsGrid.getByRole('row'); + + return rows.filter({ + hasText: title, + }); +}; + interface GoToGridDocOptions { nthRow?: number; title?: string; diff --git a/src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts b/src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts index 8dba8dab5..b3866745c 100644 --- a/src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts +++ b/src/frontend/apps/e2e/__tests__/app-impress/doc-editor.spec.ts @@ -220,7 +220,7 @@ test.describe('Doc Editor', () => { browserName, }) => { // Check the first doc - const [doc] = await createDoc(page, 'doc-saves-change', browserName, 1); + const [doc] = await createDoc(page, 'doc-saves-change', browserName); await verifyDocName(page, doc); const editor = page.locator('.ProseMirror'); @@ -228,9 +228,11 @@ test.describe('Doc Editor', () => { await editor.fill('Hello World Doc persisted 1'); await expect(editor.getByText('Hello World Doc persisted 1')).toBeVisible(); - const secondDoc = await goToGridDoc(page, { - nthRow: 2, - }); + const [secondDoc] = await createDoc( + page, + 'doc-saves-change-other', + browserName, + ); await verifyDocName(page, secondDoc); @@ -246,8 +248,7 @@ test.describe('Doc Editor', () => { test.skip(browserName === 'webkit', 'This test is very flaky with webkit'); // Check the first doc - const doc = await goToGridDoc(page); - + const [doc] = await createDoc(page, 'doc-quit-1', browserName, 1); await verifyDocName(page, doc); const editor = page.locator('.ProseMirror'); diff --git a/src/frontend/apps/e2e/__tests__/app-impress/doc-favorite.spec.ts b/src/frontend/apps/e2e/__tests__/app-impress/doc-favorite.spec.ts deleted file mode 100644 index f1fe950f7..000000000 --- a/src/frontend/apps/e2e/__tests__/app-impress/doc-favorite.spec.ts +++ /dev/null @@ -1,75 +0,0 @@ -import { expect, test } from '@playwright/test'; - -import { createDoc, verifyDocName } from './common'; - -type SmallDoc = { - id: string; - title: string; -}; - -test.describe('Document favorite', () => { - test('it check the favorite workflow', async ({ page, browserName }) => { - const id = Math.random().toString(7); - await page.goto('/'); - - // Create document - const createdDoc = await createDoc(page, `Doc ${id}`, browserName, 1); - await verifyDocName(page, createdDoc[0]); - - // Reload page - await page.reload(); - await page.goto('/'); - - // Get all documents - let docs: SmallDoc[] = []; - const response = await page.waitForResponse( - (response) => - response.url().endsWith('documents/?page=1') && - response.status() === 200, - ); - const result = await response.json(); - docs = result.results as SmallDoc[]; - const docsGrid = page.getByTestId('docs-grid'); - await docsGrid.getByRole('heading', { name: 'All docs' }).click(); - await expect(docsGrid.getByText(`Doc ${id}`)).toBeVisible(); - const doc = docs.find((doc) => doc.title === createdDoc[0]) as SmallDoc; - - // Check document - expect(doc).not.toBeUndefined(); - expect(doc?.title).toBe(createdDoc[0]); - - // Open document actions - const button = docsGrid.getByTestId(`docs-grid-actions-button-${doc.id}`); - await expect(button).toBeVisible(); - await button.click(); - - // Pin document - const pinButton = page.getByTestId(`docs-grid-actions-pin-${docs[0].id}`); - await expect(pinButton).toBeVisible(); - await pinButton.click(); - - // Check response - const responsePin = await page.waitForResponse( - (response) => - response.url().includes(`documents/${doc.id}/favorite/`) && - response.status() === 201, - ); - expect(responsePin.ok()).toBeTruthy(); - - // Check left panel favorites - const leftPanelFavorites = page.getByTestId('left-panel-favorites'); - await expect(leftPanelFavorites).toBeVisible(); - await expect(leftPanelFavorites.getByText(`Doc ${id}`)).toBeVisible(); - - // - await button.click(); - const unpinButton = page.getByTestId( - `docs-grid-actions-unpin-${docs[0].id}`, - ); - await expect(unpinButton).toBeVisible(); - await unpinButton.click(); - - // Check left panel favorites - await expect(leftPanelFavorites.getByText(`Doc ${id}`)).toBeHidden(); - }); -}); diff --git a/src/frontend/apps/e2e/__tests__/app-impress/doc-grid.spec.ts b/src/frontend/apps/e2e/__tests__/app-impress/doc-grid.spec.ts index 1963bf1cc..772ec1046 100644 --- a/src/frontend/apps/e2e/__tests__/app-impress/doc-grid.spec.ts +++ b/src/frontend/apps/e2e/__tests__/app-impress/doc-grid.spec.ts @@ -1,5 +1,7 @@ import { expect, test } from '@playwright/test'; +import { createDoc, getGridRow } from './common'; + type SmallDoc = { id: string; title: string; @@ -92,6 +94,31 @@ test.describe('Documents Grid mobile', () => { }); test.describe('Document grid item options', () => { + test('it pins a document', async ({ page, browserName }) => { + const [docTitle] = await createDoc(page, `Favorite doc`, browserName); + + await page.goto('/'); + + const row = await getGridRow(page, docTitle); + + // Pin + await row.getByText(`more_horiz`).click(); + await page.getByText('push_pin').click(); + + // Check is pinned + await expect(row.getByLabel('Pin document icon')).toBeVisible(); + const leftPanelFavorites = page.getByTestId('left-panel-favorites'); + await expect(leftPanelFavorites.getByText(docTitle)).toBeVisible(); + + // Unpin + await row.getByText(`more_horiz`).click(); + await page.getByText('Unpin').click(); + + // Check is unpinned + await expect(row.getByLabel('Pin document icon')).toBeHidden(); + await expect(leftPanelFavorites.getByText(docTitle)).toBeHidden(); + }); + test('it deletes the document', async ({ page }) => { let docs: SmallDoc[] = []; const response = await page.waitForResponse( diff --git a/src/frontend/apps/e2e/__tests__/app-impress/doc-member-create.spec.ts b/src/frontend/apps/e2e/__tests__/app-impress/doc-member-create.spec.ts index 04015e9e7..ec2a39532 100644 --- a/src/frontend/apps/e2e/__tests__/app-impress/doc-member-create.spec.ts +++ b/src/frontend/apps/e2e/__tests__/app-impress/doc-member-create.spec.ts @@ -26,7 +26,7 @@ test.describe('Document create member', () => { const response = await responsePromise; const users = (await response.json()).results as { email: string; - full_name: string; + full_name?: string | null; }[]; const list = page.getByTestId('doc-share-add-member-list'); @@ -40,7 +40,9 @@ test.describe('Document create member', () => { await expect( list.getByTestId(`doc-share-add-member-${users[0].email}`), ).toBeVisible(); - await expect(list.getByText(`${users[0].full_name}`)).toBeVisible(); + await expect( + list.getByText(`${users[0].full_name || users[0].email}`), + ).toBeVisible(); // Select user 2 and verify tag await inputSearch.fill('user'); @@ -51,7 +53,9 @@ test.describe('Document create member', () => { await expect( list.getByTestId(`doc-share-add-member-${users[1].email}`), ).toBeVisible(); - await expect(list.getByText(`${users[1].full_name}`)).toBeVisible(); + await expect( + list.getByText(`${users[1].full_name || users[1].email}`), + ).toBeVisible(); // Select email and verify tag const email = randomName('test@test.fr', browserName, 1)[0]; @@ -81,7 +85,9 @@ test.describe('Document create member', () => { // Check user added await expect(page.getByText('Share with 3 users')).toBeVisible(); await expect( - quickSearchContent.getByText(users[0].full_name).first(), + quickSearchContent + .getByText(users[0].full_name || users[0].email) + .first(), ).toBeVisible(); await expect( quickSearchContent.getByText(users[0].email).first(), @@ -90,7 +96,9 @@ test.describe('Document create member', () => { quickSearchContent.getByText(users[1].email).first(), ).toBeVisible(); await expect( - quickSearchContent.getByText(users[1].full_name).first(), + quickSearchContent + .getByText(users[1].full_name || users[1].email) + .first(), ).toBeVisible(); }); diff --git a/src/frontend/apps/impress/src/features/docs/doc-share/components/DocShareModal.tsx b/src/frontend/apps/impress/src/features/docs/doc-share/components/DocShareModal.tsx index 732365341..e7fbdffe6 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-share/components/DocShareModal.tsx +++ b/src/frontend/apps/impress/src/features/docs/doc-share/components/DocShareModal.tsx @@ -30,12 +30,9 @@ import { DocShareModalFooter } from './DocShareModalFooter'; import { DocShareModalInviteUserRow } from './DocShareModalInviteUserByEmail'; const ShareModalStyle = createGlobalStyle` - .c__modal__title { padding-bottom: 0 !important; - -} - + } `; type Props = { diff --git a/src/frontend/apps/impress/src/features/docs/docs-grid/components/DocsGrid.tsx b/src/frontend/apps/impress/src/features/docs/docs-grid/components/DocsGrid.tsx index 5c125bdba..f511abb22 100644 --- a/src/frontend/apps/impress/src/features/docs/docs-grid/components/DocsGrid.tsx +++ b/src/frontend/apps/impress/src/features/docs/docs-grid/components/DocsGrid.tsx @@ -70,6 +70,7 @@ export const DocsGrid = ({ > { + const { t } = useTranslation(); const { spacingsTokens } = useCunninghamTheme(); const { isDesktop } = useResponsiveStore(); const spacings = spacingsTokens(); @@ -44,7 +46,11 @@ export const SimpleDocItem = ({ filter: drop-shadow(0px 2px 2px rgba(0, 0, 0, 0.05)); `} > - {isPinned ? : } + {isPinned ? ( + + ) : ( + + )}