From 8f5ee9234c819da8f0380a912e57a8e48e0f7844 Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Wed, 11 Oct 2023 01:05:06 -0500 Subject: [PATCH] test: remove deprecated api usage (#4577) --- tests/affine-cloud/e2e/basic.spec.ts | 2 +- tests/affine-cloud/e2e/collaboration.spec.ts | 10 +++---- tests/affine-desktop/e2e/basic.spec.ts | 29 ++++++++++++------- .../0.8.0-canary.7/e2e/basic.spec.ts | 2 +- tests/affine-legacy/0.8.4/e2e/basic.spec.ts | 2 +- .../e2e/blocksuite/editor.spec.ts | 12 ++++---- tests/affine-local/e2e/duplicate-page.spec.ts | 2 +- .../e2e/local-first-avatar.spec.ts | 2 +- .../e2e/local-first-delete-workspace.spec.ts | 17 ++++++----- .../e2e/local-first-trash-page.spec.ts | 2 +- tests/affine-local/e2e/quick-search.spec.ts | 8 ++--- 11 files changed, 49 insertions(+), 39 deletions(-) diff --git a/tests/affine-cloud/e2e/basic.spec.ts b/tests/affine-cloud/e2e/basic.spec.ts index 3c080593a..a372c81a4 100644 --- a/tests/affine-cloud/e2e/basic.spec.ts +++ b/tests/affine-cloud/e2e/basic.spec.ts @@ -124,7 +124,7 @@ test.describe('basic', () => { }); const nameInput = page.getByPlaceholder('Input account name'); await nameInput.clear(); - await nameInput.type(newName, { + await nameInput.pressSequentially(newName, { delay: 50, }); await page.getByTestId('save-user-name').click({ diff --git a/tests/affine-cloud/e2e/collaboration.spec.ts b/tests/affine-cloud/e2e/collaboration.spec.ts index 7576eb184..f2aeb2cd9 100644 --- a/tests/affine-cloud/e2e/collaboration.spec.ts +++ b/tests/affine-cloud/e2e/collaboration.spec.ts @@ -49,7 +49,7 @@ test.describe('collaboration', () => { ); await enableCloudWorkspace(page); const title = getBlockSuiteEditorTitle(page); - await title.type('TEST TITLE', { + await title.pressSequentially('TEST TITLE', { delay: 50, }); await page.keyboard.press('Enter', { delay: 50 }); @@ -102,7 +102,7 @@ test.describe('collaboration', () => { await page2.goto(currentUrl); { const title = getBlockSuiteEditorTitle(page); - await title.type('TEST TITLE', { + await title.pressSequentially('TEST TITLE', { delay: 50, }); } @@ -124,7 +124,7 @@ test.describe('collaboration', () => { await clickUserInfoCard(page); const input = page.getByTestId('user-name-input'); await input.clear(); - await input.type('TEST USER', { + await input.pressSequentially('TEST USER', { delay: 50, }); await page.getByTestId('save-user-name').click({ @@ -167,7 +167,7 @@ test.describe('collaboration', () => { const page2 = await context.newPage(); await loginUser(page2, user.email); await page2.goto(page.url()); - waitForEditorLoad(page2); + await waitForEditorLoad(page2); const collections = page2.getByTestId('collections'); await expect(collections.getByText('test collection')).toBeVisible(); } @@ -235,7 +235,7 @@ test.describe('collaboration members', () => { .all(); // make sure the first member is the owner - expect(page.getByTestId('member-item').first()).toContainText( + await expect(page.getByTestId('member-item').first()).toContainText( 'Workspace Owner' ); diff --git a/tests/affine-desktop/e2e/basic.spec.ts b/tests/affine-desktop/e2e/basic.spec.ts index 65de02d5a..921fad362 100644 --- a/tests/affine-desktop/e2e/basic.spec.ts +++ b/tests/affine-desktop/e2e/basic.spec.ts @@ -1,6 +1,7 @@ import { platform } from 'node:os'; import { test } from '@affine-test/kit/electron'; +import { getBlockSuiteEditorTitle } from '@affine-test/kit/utils/page-logic'; import { clickSideBarSettingButton } from '@affine-test/kit/utils/sidebar'; import { expect } from '@playwright/test'; @@ -27,8 +28,9 @@ if (platform() === 'darwin') { delay: 100, }); await page.waitForSelector('v-line'); - await page.focus('.affine-doc-page-block-title'); - await page.type('.affine-doc-page-block-title', 'test1', { + const title = getBlockSuiteEditorTitle(page); + await title.focus(); + await title.pressSequentially('test1', { delay: 100, }); await page.waitForTimeout(500); @@ -36,8 +38,9 @@ if (platform() === 'darwin') { delay: 100, }); await page.waitForSelector('v-line'); - await page.focus('.affine-doc-page-block-title'); - await page.type('.affine-doc-page-block-title', 'test2', { + + await title.focus(); + await title.pressSequentially('test2', { delay: 100, }); await page.waitForTimeout(500); @@ -45,8 +48,8 @@ if (platform() === 'darwin') { delay: 100, }); await page.waitForSelector('v-line'); - await page.focus('.affine-doc-page-block-title'); - await page.type('.affine-doc-page-block-title', 'test3', { + await title.focus(); + await title.pressSequentially('test3', { delay: 100, }); } @@ -155,9 +158,11 @@ test('windows only check', async ({ page }) => { test('delete workspace', async ({ page }) => { await page.getByTestId('current-workspace').click(); await page.getByTestId('new-workspace').click(); - await page.getByTestId('create-workspace-input').type('Delete Me', { - delay: 100, - }); + await page + .getByTestId('create-workspace-input') + .pressSequentially('Delete Me', { + delay: 100, + }); await page.getByTestId('create-workspace-create-button').click({ delay: 100, }); @@ -170,7 +175,7 @@ test('delete workspace', async ({ page }) => { expect(await page.getByTestId('workspace-name-input').inputValue()).toBe( 'Delete Me' ); - const contentElement = await page.getByTestId('setting-modal-content'); + const contentElement = page.getByTestId('setting-modal-content'); const boundingBox = await contentElement.boundingBox(); if (!boundingBox) { throw new Error('boundingBox is null'); @@ -181,7 +186,9 @@ test('delete workspace', async ({ page }) => { ); await page.mouse.wheel(0, 500); await page.getByTestId('delete-workspace-button').click(); - await page.getByTestId('delete-workspace-input').type('Delete Me'); + await page + .getByTestId('delete-workspace-input') + .pressSequentially('Delete Me'); await page.getByTestId('delete-workspace-confirm-button').click(); await page.waitForTimeout(1000); expect(await page.getByTestId('workspace-name').textContent()).toBe( diff --git a/tests/affine-legacy/0.8.0-canary.7/e2e/basic.spec.ts b/tests/affine-legacy/0.8.0-canary.7/e2e/basic.spec.ts index 421b994c7..f68514df2 100644 --- a/tests/affine-legacy/0.8.0-canary.7/e2e/basic.spec.ts +++ b/tests/affine-legacy/0.8.0-canary.7/e2e/basic.spec.ts @@ -21,7 +21,7 @@ test('database migration', async ({ page, context }) => { }); await page.getByTestId('new-page-button').click(); const title = page.locator('.affine-default-page-block-title'); - await title.type('hello'); + await title.pressSequentially('hello'); await page.keyboard.press('Enter', { delay: 50 }); await page.keyboard.press('/', { delay: 50 }); await page.keyboard.press('d'); diff --git a/tests/affine-legacy/0.8.4/e2e/basic.spec.ts b/tests/affine-legacy/0.8.4/e2e/basic.spec.ts index 900083690..ef1d6d030 100644 --- a/tests/affine-legacy/0.8.4/e2e/basic.spec.ts +++ b/tests/affine-legacy/0.8.4/e2e/basic.spec.ts @@ -24,7 +24,7 @@ test('surface migration', async ({ page, context }) => { }); await page.getByTestId('new-page-button').click(); const title = getBlockSuiteEditorTitle(page); - await title.type('hello'); + await title.pressSequentially('hello'); await page.keyboard.press('Enter', { delay: 50 }); await page.keyboard.type('world', { delay: 50, diff --git a/tests/affine-local/e2e/blocksuite/editor.spec.ts b/tests/affine-local/e2e/blocksuite/editor.spec.ts index 8166236a8..d1e889d05 100644 --- a/tests/affine-local/e2e/blocksuite/editor.spec.ts +++ b/tests/affine-local/e2e/blocksuite/editor.spec.ts @@ -23,7 +23,7 @@ test('database is useable', async ({ page }) => { await clickNewPageButton(page); await waitForEditorLoad(page); const title = getBlockSuiteEditorTitle(page); - await title.type('test title'); + await title.pressSequentially('test title'); await page.keyboard.press('Enter'); expect(await title.innerText()).toBe('test title'); await addDatabase(page); @@ -34,7 +34,7 @@ test('database is useable', async ({ page }) => { await clickNewPageButton(page); await waitForEditorLoad(page); const title2 = getBlockSuiteEditorTitle(page); - await title2.type('test title2'); + await title2.pressSequentially('test title2'); await page.waitForTimeout(500); expect(await title2.innerText()).toBe('test title2'); await page.keyboard.press('Enter'); @@ -48,14 +48,14 @@ test('link page is useable', async ({ page }) => { await waitForEditorLoad(page); await clickNewPageButton(page); await waitForEditorLoad(page); - const title = await getBlockSuiteEditorTitle(page); - await title.type('page1'); + const title = getBlockSuiteEditorTitle(page); + await title.pressSequentially('page1'); await page.keyboard.press('Enter'); expect(await title.innerText()).toBe('page1'); await clickNewPageButton(page); await waitForEditorLoad(page); - const title2 = await getBlockSuiteEditorTitle(page); - await title2.type('page2'); + const title2 = getBlockSuiteEditorTitle(page); + await title2.pressSequentially('page2'); await page.keyboard.press('Enter'); expect(await title2.innerText()).toBe('page2'); await page.keyboard.press('@', { delay: 50 }); diff --git a/tests/affine-local/e2e/duplicate-page.spec.ts b/tests/affine-local/e2e/duplicate-page.spec.ts index c5f3675f5..894e5fafe 100644 --- a/tests/affine-local/e2e/duplicate-page.spec.ts +++ b/tests/affine-local/e2e/duplicate-page.spec.ts @@ -13,7 +13,7 @@ test('Duplicate page should work', async ({ page }) => { await waitForEditorLoad(page); await clickNewPageButton(page); const title = getBlockSuiteEditorTitle(page); - await title.type('test'); + await title.pressSequentially('test'); await clickPageMoreActions(page); const duplicateButton = page.getByTestId('editor-option-menu-duplicate'); await duplicateButton.click({ delay: 100 }); diff --git a/tests/affine-local/e2e/local-first-avatar.spec.ts b/tests/affine-local/e2e/local-first-avatar.spec.ts index 73397d0f6..b35268640 100644 --- a/tests/affine-local/e2e/local-first-avatar.spec.ts +++ b/tests/affine-local/e2e/local-first-avatar.spec.ts @@ -19,7 +19,7 @@ test('should create a page with a local first avatar and remove it', async ({ await page.getByTestId('new-workspace').click({ delay: 50 }); await page .getByTestId('create-workspace-input') - .type('Test Workspace 1', { delay: 50 }); + .pressSequentially('Test Workspace 1', { delay: 50 }); await page.getByTestId('create-workspace-create-button').click(); await page.getByTestId('workspace-name').click({ delay: 50, diff --git a/tests/affine-local/e2e/local-first-delete-workspace.spec.ts b/tests/affine-local/e2e/local-first-delete-workspace.spec.ts index 0f43a85e4..1b577df39 100644 --- a/tests/affine-local/e2e/local-first-delete-workspace.spec.ts +++ b/tests/affine-local/e2e/local-first-delete-workspace.spec.ts @@ -13,7 +13,7 @@ test('Create new workspace, then delete it', async ({ page, workspace }) => { await page.getByTestId('new-workspace').click(); await page .getByTestId('create-workspace-input') - .type('Test Workspace', { delay: 50 }); + .pressSequentially('Test Workspace', { delay: 50 }); await page.getByTestId('create-workspace-create-button').click(); await page.waitForTimeout(1000); @@ -25,12 +25,13 @@ test('Create new workspace, then delete it', async ({ page, workspace }) => { await openWorkspaceSettingPanel(page, 'Test Workspace'); await page.getByTestId('delete-workspace-button').click(); const workspaceNameDom = await page.getByTestId('workspace-name'); - const currentWorkspaceName = await workspaceNameDom.evaluate( + const currentWorkspaceName = (await workspaceNameDom.evaluate( node => node.textContent - ); + )) as string; + expect(currentWorkspaceName).toBeDefined(); await page .getByTestId('delete-workspace-input') - .type(currentWorkspaceName as string); + .pressSequentially(currentWorkspaceName); const promise = page .getByTestId('affine-notification') .waitFor({ state: 'attached' }); @@ -46,7 +47,7 @@ test('Create new workspace, then delete it', async ({ page, workspace }) => { expect(currentWorkspace.flavour).toContain('local'); }); -//FIXME: this test is broken + test('Delete last workspace', async ({ page }) => { await openHomePage(page); await waitForEditorLoad(page); @@ -59,12 +60,14 @@ test('Delete last workspace', async ({ page }) => { await page.getByTestId('delete-workspace-button').click(); await page .getByTestId('delete-workspace-input') - .type(currentWorkspaceName as string); + .pressSequentially(currentWorkspaceName as string); await page.getByTestId('delete-workspace-confirm-button').click(); await openHomePage(page); await expect(page.getByTestId('new-workspace')).toBeVisible(); await page.getByTestId('new-workspace').click(); - await page.type('[data-testid="create-workspace-input"]', 'Test Workspace'); + await page + .locator('[data-testid="create-workspace-input"]') + .pressSequentially('Test Workspace'); await page.getByTestId('create-workspace-create-button').click(); await page.waitForTimeout(1000); await page.waitForSelector('[data-testid="workspace-name"]'); diff --git a/tests/affine-local/e2e/local-first-trash-page.spec.ts b/tests/affine-local/e2e/local-first-trash-page.spec.ts index d8a186628..dd2c2ef9e 100644 --- a/tests/affine-local/e2e/local-first-trash-page.spec.ts +++ b/tests/affine-local/e2e/local-first-trash-page.spec.ts @@ -52,7 +52,7 @@ test('New a page , then delete it in page, blockHub and option menu will not app await waitForEditorLoad(page); await clickNewPageButton(page); const title = getBlockSuiteEditorTitle(page); - await title.type('test'); + await title.pressSequentially('test'); await clickPageMoreActions(page); await page.getByTestId('editor-option-menu-delete').click(); await page.getByTestId('confirm-delete-page').click(); diff --git a/tests/affine-local/e2e/quick-search.spec.ts b/tests/affine-local/e2e/quick-search.spec.ts index f1adb90c8..fb2d5f041 100644 --- a/tests/affine-local/e2e/quick-search.spec.ts +++ b/tests/affine-local/e2e/quick-search.spec.ts @@ -219,7 +219,7 @@ test('assert the recent browse pages are on the recent list', async ({ await clickNewPageButton(page); { const title = getBlockSuiteEditorTitle(page); - await title.type('sgtokidoki', { + await title.pressSequentially('sgtokidoki', { delay: 50, }); } @@ -231,7 +231,7 @@ test('assert the recent browse pages are on the recent list', async ({ await addNewPage.click(); { const title = getBlockSuiteEditorTitle(page); - await title.type('theliquidhorse', { + await title.pressSequentially('theliquidhorse', { delay: 50, }); } @@ -242,7 +242,7 @@ test('assert the recent browse pages are on the recent list', async ({ await addNewPage.click(); { const title = getBlockSuiteEditorTitle(page); - await title.type('battlekot', { + await title.pressSequentially('battlekot', { delay: 50, }); } @@ -271,7 +271,7 @@ test('assert the recent browse pages are on the recent list', async ({ await page.waitForTimeout(200); { const title = getBlockSuiteEditorTitle(page); - await title.type('affine is the best', { + await title.pressSequentially('affine is the best', { delay: 50, }); }