chore: prohibit unnecessary await (#4586)

This commit is contained in:
Alex Yang
2023-10-12 00:04:58 -05:00
committed by GitHub
parent 5ebd82dc04
commit d05897b724
19 changed files with 104 additions and 104 deletions
+2
View File
@@ -132,6 +132,7 @@ const config = {
'@typescript-eslint/no-non-null-assertion': 'error',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{
@@ -202,6 +203,7 @@ const config = {
ignore: ['^\\[[a-zA-Z0-9-_]+\\]\\.tsx$'],
},
],
'unicorn/no-unnecessary-await': 'error',
'sonarjs/no-all-duplicated-branches': 'error',
'sonarjs/no-element-overwrite': 'error',
'sonarjs/no-empty-collection': 'error',
+1 -3
View File
@@ -358,9 +358,7 @@ function createSetupImpl(rootStore: ReturnType<typeof createStore>) {
},
}
),
navigator: {
userAgent: navigator.userAgent,
},
navigator: globalThis.navigator,
MouseEvent: globalThis.MouseEvent,
KeyboardEvent: globalThis.KeyboardEvent,
@@ -42,7 +42,10 @@ export interface PageDetailEditorProps {
isPublic?: boolean;
workspace: Workspace;
pageId: string;
onInit: (page: Page, editor: Readonly<EditorContainer>) => void;
onInit: (
page: Page,
editor: Readonly<EditorContainer>
) => Promise<void> | void;
onLoad?: OnLoadEditor;
}
+1 -1
View File
@@ -112,7 +112,7 @@ export function useAppHelper() {
targetWorkspace
);
// delete workspace from jotai storage
await set(workspaces => workspaces.filter(ws => ws.id !== workspaceId));
set(workspaces => workspaces.filter(ws => ws.id !== workspaceId));
},
[jotaiWorkspaces, set]
),
+1 -1
View File
@@ -70,7 +70,7 @@ export const Component = (): ReactElement => {
isPublic
workspace={page.workspace}
pageId={page.id}
onInit={useCallback(() => noop, [])}
onInit={noop}
onLoad={useCallback(() => noop, [])}
/>
</MainContainer>
+1 -2
View File
@@ -23,8 +23,7 @@ test.afterEach.always(async () => {
test('should be able to increment counter', async t => {
metrics.socketIOEventCounter(1, { event: 'client-handshake' });
const socketIOCounterMetric =
await register.getSingleMetric('socket_io_counter');
const socketIOCounterMetric = register.getSingleMetric('socket_io_counter');
t.truthy(socketIOCounterMetric);
t.truthy(
@@ -13,7 +13,7 @@ export function useBlockSuiteWorkspaceAvatarUrl(
const { data: avatar, mutate } = useSWR(url, {
fetcher: async avatar => {
assertExists(blockSuiteWorkspace);
const blobs = await blockSuiteWorkspace.blobs;
const blobs = blockSuiteWorkspace.blobs;
const blob = await blobs.get(avatar);
if (blob) {
return URL.createObjectURL(blob);
@@ -31,7 +31,7 @@ export function useBlockSuiteWorkspaceAvatarUrl(
return;
}
const blob = new Blob([file], { type: file.type });
const blobs = await blockSuiteWorkspace.blobs;
const blobs = blockSuiteWorkspace.blobs;
const blobId = await blobs.set(blob);
blockSuiteWorkspace.meta.setAvatar(blobId);
await mutate(blobId);
+1 -1
View File
@@ -1,7 +1,7 @@
import { runCli } from '@magic-works/i18n-codegen';
import { fileURLToPath } from 'url';
await runCli(
runCli(
{
config: fileURLToPath(new URL('../../.i18n-codegen.json', import.meta.url)),
watch: false,
@@ -190,7 +190,7 @@ const ImagePreviewModalImpl = (
if (typeof blockId === 'string') {
const block = page.getBlockById(blockId) as ImageBlockModel;
assertExists(block);
const store = await block.page.blobs;
const store = block.page.blobs;
const url = store?.get(block.sourceId);
const img = await url;
if (!img) {
+1 -1
View File
@@ -5,7 +5,7 @@ import { runCli } from '@magic-works/i18n-codegen';
import { beforeAll } from 'vitest';
beforeAll(async () => {
await runCli(
runCli(
{
watch: false,
cwd: join(fileURLToPath(import.meta.url), '../../../.i18n-codegen.json'),
+3 -3
View File
@@ -80,9 +80,9 @@ test('allow creation of filters by favorite', async ({ page }) => {
.locator('[data-testid="filter-arg"]', { hasText: 'true' })
.locator('div')
.click();
await expect(
await page.locator('[data-testid="filter-arg"]').textContent()
).toBe('false');
expect(await page.locator('[data-testid="filter-arg"]').textContent()).toBe(
'false'
);
});
test('allow creation of filters by created time', async ({ page }) => {
@@ -15,7 +15,7 @@ test('Switch to edgeless by switch edgeless item', async ({ page }) => {
}
await openHomePage(page);
await waitForEditorLoad(page);
const btn = await page.getByTestId('switch-edgeless-mode-button');
const btn = page.getByTestId('switch-edgeless-mode-button');
await page.evaluate(() => {
// @ts-expect-error
globalThis.__toastCount = 0;
@@ -31,7 +31,7 @@ test('Switch to edgeless by switch edgeless item', async ({ page }) => {
expect(count).toBe(1);
}
const edgeless = page.locator('affine-edgeless-page');
expect(await edgeless.isVisible()).toBe(true);
await expect(edgeless).toBeVisible();
const editorWrapperPadding = await page
.locator('.editor-wrapper.edgeless-mode')
@@ -60,15 +60,15 @@ test('Convert to edgeless by editor header items', async ({ page }) => {
const menusEdgelessItem = page.getByTestId('editor-option-menu-edgeless');
await menusEdgelessItem.click({ delay: 100 });
const edgeless = page.locator('affine-edgeless-page');
expect(await edgeless.isVisible()).toBe(true);
await expect(edgeless).toBeVisible();
});
test('Able to insert the title of an untitled page', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
const titleBarTextContent = await page.getByTestId('title-edit-button');
const titleBarTextContent = page.getByTestId('title-edit-button');
await titleBarTextContent.dblclick({ delay: 100 });
const titleContent = await page.getByTestId('title-content');
const titleContent = page.getByTestId('title-content');
await titleContent.fill('test');
await titleContent.blur();
expect(await titleBarTextContent.textContent()).toBe('test');
@@ -77,9 +77,9 @@ test('Able to insert the title of an untitled page', async ({ page }) => {
test('Able to edit the title of an existing page', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
const titleBarTextContent = await page.getByTestId('title-edit-button');
const titleBarTextContent = page.getByTestId('title-edit-button');
await titleBarTextContent.dblclick({ delay: 100 });
const titleContent = await page.getByTestId('title-content');
const titleContent = page.getByTestId('title-content');
await titleContent.fill('test');
await titleContent.blur();
expect(await titleBarTextContent.textContent()).toBe('test');
@@ -94,9 +94,9 @@ test('Clearing out the title bar will remove the page title', async ({
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
const titleBarTextContent = await page.getByTestId('title-edit-button');
const titleBarTextContent = page.getByTestId('title-edit-button');
await titleBarTextContent.dblclick({ delay: 100 });
const titleContent = await page.getByTestId('title-content');
const titleContent = page.getByTestId('title-content');
await titleContent.fill('test');
await titleContent.blur();
expect(await titleBarTextContent.textContent()).toBe('test');
+3 -5
View File
@@ -7,13 +7,11 @@ test('Click right-bottom corner contact icon', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await page.locator('[data-testid=help-island]').click();
const rightBottomContactUs = page.locator(
'[data-testid=right-bottom-contact-us-icon]'
);
expect(await rightBottomContactUs.isVisible()).toEqual(true);
const rightBottomContactUs = page.getByTestId('right-bottom-contact-us-icon');
await expect(rightBottomContactUs).toBeVisible();
await rightBottomContactUs.click();
const title = await page.getByTestId('about-title');
const title = page.getByTestId('about-title');
await expect(title).toBeVisible();
});
@@ -1,8 +1,9 @@
import { test } from '@affine-test/kit/playwright';
import { open404Page } from '@affine-test/kit/utils/load-page';
import { expect } from '@playwright/test';
test('visit 404 page', async ({ page }) => {
await page.goto('http://localhost:8080/404');
await open404Page(page);
const notFoundTip = page.getByTestId('not-found');
await expect(notFoundTip).toBeVisible();
});
+61 -61
View File
@@ -44,15 +44,15 @@ test('image preview should be shown', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await clickNewPageButton(page);
const title = await getBlockSuiteEditorTitle(page);
const title = getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
await importImage(page, 'http://localhost:8081/large-image.png');
await page.locator('img').first().dblclick();
const locator = page.getByTestId('image-preview-modal');
expect(locator.isVisible()).toBeTruthy();
await expect(locator).toBeVisible();
await closeImagePreviewModal(page);
expect(await locator.isVisible()).toBeFalsy();
await expect(locator).not.toBeVisible();
});
test('image go left and right', async ({ page }) => {
@@ -61,7 +61,7 @@ test('image go left and right', async ({ page }) => {
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
const title = getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
await importImage(page, 'http://localhost:8081/large-image.png');
@@ -75,7 +75,7 @@ test('image go left and right', async ({ page }) => {
await closeImagePreviewModal(page);
}
{
const title = await getBlockSuiteEditorTitle(page);
const title = getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
await importImage(page, 'http://localhost:8081/affine-preview.png');
@@ -108,7 +108,7 @@ test('image able to zoom in and out with mouse scroll', async ({ page }) => {
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
const title = getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
await importImage(page, 'http://localhost:8081/large-image.png');
@@ -130,26 +130,26 @@ test('image able to zoom in and out with mouse scroll', async ({ page }) => {
height: window.innerHeight,
}));
// zooom in
// zoom in
await page.mouse.move(width / 2, height / 2);
await page.mouse.wheel(0, 100);
await page.mouse.wheel(0, 100);
await page.mouse.wheel(0, 100);
await page.waitForTimeout(1000);
let imageBoundary = await locator.boundingBox();
let imageWidth = await imageBoundary?.width;
let imageWidth = imageBoundary?.width;
if (imageWidth) {
expect((imageWidth / naturalWidth).toFixed(2)).toBe('0.54');
}
// zooom in
// zoom in
await page.mouse.move(width / 2, height / 2);
await page.mouse.wheel(0, -100);
await page.mouse.wheel(0, -100);
await page.mouse.wheel(0, -100);
await page.waitForTimeout(1000);
imageBoundary = await locator.boundingBox();
imageWidth = await imageBoundary?.width;
imageWidth = imageBoundary?.width;
if (imageWidth) {
expect((imageWidth / naturalWidth).toFixed(2)).toBe('0.84');
}
@@ -161,7 +161,7 @@ test('image able to zoom in and out with button click', async ({ page }) => {
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
const title = getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
await importImage(page, 'http://localhost:8081/large-image.png');
@@ -174,7 +174,7 @@ test('image able to zoom in and out with button click', async ({ page }) => {
expect(blobId).toBeTruthy();
}
const locator = page.getByTestId('image-content');
expect(locator.isVisible()).toBeTruthy();
await expect(locator).toBeVisible();
const naturalWidth = await locator.evaluate(
(img: HTMLImageElement) => img.naturalWidth
);
@@ -187,7 +187,7 @@ test('image able to zoom in and out with button click', async ({ page }) => {
}
await page.waitForTimeout(1000);
let imageBoundary = await locator.boundingBox();
let imageWidth = await imageBoundary?.width;
let imageWidth = imageBoundary?.width;
if (imageWidth) {
expect((imageWidth / naturalWidth).toFixed(2)).toBe('1.04');
}
@@ -195,7 +195,7 @@ test('image able to zoom in and out with button click', async ({ page }) => {
// zooom out
await page.getByTestId('zoom-out-button').dblclick();
imageBoundary = await locator.boundingBox();
imageWidth = await imageBoundary?.width;
imageWidth = imageBoundary?.width;
if (imageWidth) {
expect((imageWidth / naturalWidth).toFixed(2)).toBe('0.84');
}
@@ -207,7 +207,7 @@ test('image should able to go left and right by buttons', async ({ page }) => {
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
const title = getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
await importImage(page, 'http://localhost:8081/large-image.png');
@@ -221,16 +221,14 @@ test('image should able to go left and right by buttons', async ({ page }) => {
await closeImagePreviewModal(page);
}
{
const title = await getBlockSuiteEditorTitle(page);
const title = getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
await importImage(page, 'http://localhost:8081/affine-preview.png');
}
const locator = page.getByTestId('image-preview-modal');
expect(locator.isVisible()).toBeTruthy();
await page.locator('img').first().dblclick();
// ensure the new image was imported
await page.waitForTimeout(1000);
await expect(locator).toBeVisible();
{
const newBlobId = (await locator
.getByTestId('image-content')
@@ -261,7 +259,7 @@ test('image able to fit to screen by button', async ({ page }) => {
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
const title = getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
await importImage(page, 'http://localhost:8081/large-image.png');
@@ -274,7 +272,7 @@ test('image able to fit to screen by button', async ({ page }) => {
expect(blobId).toBeTruthy();
}
const locator = page.getByTestId('image-content');
expect(locator.isVisible()).toBeTruthy();
await expect(locator).toBeVisible();
const naturalWidth = await locator.evaluate(
(img: HTMLImageElement) => img.naturalWidth
);
@@ -289,7 +287,7 @@ test('image able to fit to screen by button', async ({ page }) => {
}
await page.waitForTimeout(1000);
let imageBoundary = await locator.boundingBox();
let imageWidth = await imageBoundary?.width;
let imageWidth = imageBoundary?.width;
if (imageWidth) {
expect((imageWidth / naturalWidth).toFixed(2)).toBe('1.04');
} else {
@@ -302,8 +300,8 @@ test('image able to fit to screen by button', async ({ page }) => {
await locator.getByTestId('fit-to-screen-button').click();
}
imageBoundary = await locator.boundingBox();
imageWidth = await imageBoundary?.width;
const imageHeight = await imageBoundary?.height;
imageWidth = imageBoundary?.width;
const imageHeight = imageBoundary?.height;
if (imageWidth && imageHeight) {
expect(imageWidth).toBeLessThan(viewportWidth);
expect(imageHeight).toBeLessThan(viewportHeight);
@@ -318,7 +316,7 @@ test('image able to reset zoom to 100%', async ({ page }) => {
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
const title = getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
await importImage(page, 'http://localhost:8081/large-image.png');
@@ -331,20 +329,20 @@ test('image able to reset zoom to 100%', async ({ page }) => {
expect(blobId).toBeTruthy();
}
const locator = page.getByTestId('image-content');
expect(locator.isVisible()).toBeTruthy();
await expect(locator).toBeVisible();
const naturalWidth = await locator.evaluate(
(img: HTMLImageElement) => img.naturalWidth
);
await page.waitForTimeout(500);
// zooom in
// zoom in
{
const locator = page.getByTestId('image-preview-modal');
await locator.getByTestId('zoom-in-button').dblclick();
}
await page.waitForTimeout(1000);
let imageBoundary = await locator.boundingBox();
let imageWidth = await imageBoundary?.width;
let imageWidth = imageBoundary?.width;
if (imageWidth) {
expect((imageWidth / naturalWidth).toFixed(2)).toBe('1.04');
} else {
@@ -357,7 +355,7 @@ test('image able to reset zoom to 100%', async ({ page }) => {
await locator.getByTestId('reset-scale-button').click();
}
imageBoundary = await locator.boundingBox();
imageWidth = await imageBoundary?.width;
imageWidth = imageBoundary?.width;
if (imageWidth) {
expect((imageWidth / naturalWidth).toFixed(2)).toBe('1.00');
} else {
@@ -371,7 +369,7 @@ test('image able to copy to clipboard', async ({ page }) => {
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
const title = getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
await importImage(page, 'http://localhost:8081/large-image.png');
@@ -384,11 +382,13 @@ test('image able to copy to clipboard', async ({ page }) => {
expect(blobId).toBeTruthy();
}
const locator = page.getByTestId('image-preview-modal');
expect(locator.isVisible()).toBeTruthy();
await page.waitForTimeout(500);
await expect(locator).toBeVisible();
await locator.getByTestId('copy-to-clipboard-button').click();
await page.on('console', message => {
expect(message.text()).toBe('Image copied to clipboard');
await new Promise<void>(resolve => {
page.on('console', message => {
expect(message.text()).toBe('Image copied to clipboard');
resolve();
});
});
});
@@ -398,7 +398,7 @@ test('image able to download', async ({ page }) => {
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
const title = getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
await importImage(page, 'http://localhost:8081/large-image.png');
@@ -411,7 +411,7 @@ test('image able to download', async ({ page }) => {
expect(blobId).toBeTruthy();
}
const locator = page.getByTestId('image-preview-modal');
expect(locator.isVisible()).toBeTruthy();
await expect(locator).toBeVisible();
const downloadPromise = page.waitForEvent('download');
await locator.getByTestId('download-button').click();
const download = await downloadPromise;
@@ -428,7 +428,7 @@ test('image should only able to move when image is larger than viewport', async
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
const title = getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
await importImage(page, 'http://localhost:8081/large-image.png');
@@ -441,7 +441,7 @@ test('image should only able to move when image is larger than viewport', async
expect(blobId).toBeTruthy();
}
const locator = page.getByTestId('image-content');
expect(locator.isVisible()).toBeTruthy();
await expect(locator).toBeVisible();
const { width, height } = await page.evaluate(() => ({
width: window.innerWidth,
height: window.innerHeight,
@@ -449,7 +449,7 @@ test('image should only able to move when image is larger than viewport', async
let imageBoundary = await locator.boundingBox();
const initialXPos = imageBoundary?.x;
const initialYPos = imageBoundary?.y;
// check will it able to move when zoomed in
// check will it be able to move when zoomed in
{
const locator = page.getByTestId('image-preview-modal');
await locator.getByTestId('zoom-in-button').dblclick();
@@ -463,7 +463,7 @@ test('image should only able to move when image is larger than viewport', async
expect(initialXPos).not.toBe(imageBoundary?.x);
expect(initialYPos).not.toBe(imageBoundary?.y);
// check will it able to move when zoomed out
// check will it be able to move when zoomed out
{
const locator = page.getByTestId('image-preview-modal');
await locator.getByTestId('fit-to-screen-button').click();
@@ -485,7 +485,7 @@ test('image should able to delete and when delete, it will move to previous/next
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
const title = getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
await importImage(page, 'http://localhost:8081/large-image.png');
@@ -499,14 +499,14 @@ test('image should able to delete and when delete, it will move to previous/next
await closeImagePreviewModal(page);
}
{
const title = await getBlockSuiteEditorTitle(page);
const title = getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
await importImage(page, 'http://localhost:8081/affine-preview.png');
}
const locator = page.getByTestId('image-preview-modal');
await expect(locator.isVisible()).toBeTruthy();
await page.locator('img').first().dblclick();
await expect(locator).toBeVisible();
// ensure the new image was imported
await page.waitForTimeout(1000);
{
@@ -523,7 +523,7 @@ test('image should able to delete and when delete, it will move to previous/next
.getAttribute('data-blob-id')) as string;
expect(newBlobId).toBe(blobId);
await closeImagePreviewModal(page);
const title = await getBlockSuiteEditorTitle(page);
const title = getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
await importImage(page, 'http://localhost:8081/affine-preview.png');
@@ -560,7 +560,7 @@ test('tooltips for all buttons should be visible when hovering', async ({
await clickNewPageButton(page);
let blobId: string;
{
const title = await getBlockSuiteEditorTitle(page);
const title = getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
await importImage(page, 'http://localhost:8081/large-image.png');
@@ -577,7 +577,7 @@ test('tooltips for all buttons should be visible when hovering', async ({
await locator.getByTestId('previous-image-button').hover();
await page.waitForTimeout(1000);
{
const element = await page.getByRole('tooltip');
const element = page.getByRole('tooltip');
const previousImageTooltip = await element.getByText('Previous').count();
expect(previousImageTooltip).toBe(1);
}
@@ -585,7 +585,7 @@ test('tooltips for all buttons should be visible when hovering', async ({
await locator.getByTestId('next-image-button').hover();
await page.waitForTimeout(1000);
{
const element = await page.getByRole('tooltip');
const element = page.getByRole('tooltip');
const nextImageTooltip = await element.getByText('Next').count();
expect(nextImageTooltip).toBe(1);
}
@@ -593,7 +593,7 @@ test('tooltips for all buttons should be visible when hovering', async ({
await locator.getByTestId('fit-to-screen-button').hover();
await page.waitForTimeout(1000);
{
const element = await page.getByRole('tooltip');
const element = page.getByRole('tooltip');
const fitToScreenToolTip = await element.getByText('Fit to Screen').count();
expect(fitToScreenToolTip).toBe(1);
}
@@ -601,7 +601,7 @@ test('tooltips for all buttons should be visible when hovering', async ({
await locator.getByTestId('zoom-out-button').hover();
await page.waitForTimeout(1000);
{
const element = await page.getByRole('tooltip');
const element = page.getByRole('tooltip');
const zoomOutToolTip = await element.getByText('Zoom out').count();
expect(zoomOutToolTip).toBe(1);
}
@@ -609,7 +609,7 @@ test('tooltips for all buttons should be visible when hovering', async ({
await locator.getByTestId('reset-scale-button').hover();
await page.waitForTimeout(1000);
{
const element = await page.getByRole('tooltip');
const element = page.getByRole('tooltip');
const resetScaleTooltip = await element.getByText('Reset Scale').count();
expect(resetScaleTooltip).toBe(1);
}
@@ -617,7 +617,7 @@ test('tooltips for all buttons should be visible when hovering', async ({
await locator.getByTestId('zoom-in-button').hover();
await page.waitForTimeout(1000);
{
const element = await page.getByRole('tooltip');
const element = page.getByRole('tooltip');
const zoominToolTip = await element.getByText('Zoom in').count();
expect(zoominToolTip).toBe(1);
}
@@ -625,7 +625,7 @@ test('tooltips for all buttons should be visible when hovering', async ({
await locator.getByTestId('download-button').hover();
await page.waitForTimeout(1000);
{
const element = await page.getByRole('tooltip');
const element = page.getByRole('tooltip');
const downloadTooltip = await element.getByText('Download').count();
expect(downloadTooltip).toBe(1);
}
@@ -633,7 +633,7 @@ test('tooltips for all buttons should be visible when hovering', async ({
await locator.getByTestId('copy-to-clipboard-button').hover();
await page.waitForTimeout(1000);
{
const element = await page.getByRole('tooltip');
const element = page.getByRole('tooltip');
const downloadTooltip = await element
.getByText('Copy to clipboard')
.count();
@@ -643,7 +643,7 @@ test('tooltips for all buttons should be visible when hovering', async ({
await locator.getByTestId('delete-button').hover();
await page.waitForTimeout(500);
{
const element = await page.getByRole('tooltip');
const element = page.getByRole('tooltip');
const downloadTooltip = await element.getByText('Delete').count();
expect(downloadTooltip).toBe(1);
}
@@ -653,7 +653,7 @@ test('keypress esc should close the modal', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await clickNewPageButton(page);
const title = await getBlockSuiteEditorTitle(page);
const title = getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
await importImage(page, 'http://localhost:8081/large-image.png');
@@ -671,18 +671,18 @@ test('when mouse moves outside, the modal should be closed', async ({
await openHomePage(page);
await waitForEditorLoad(page);
await clickNewPageButton(page);
const title = await getBlockSuiteEditorTitle(page);
const title = getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
await importImage(page, 'http://localhost:8081/large-image.png');
await page.locator('img').first().dblclick();
const locator = page.getByTestId('image-preview-modal');
expect(await locator.isVisible()).toBeTruthy();
await expect(locator).toBeVisible();
// animation delay
await page.waitForTimeout(1000);
await page.mouse.click(10, 10);
await page.waitForTimeout(1000);
expect(await locator.isVisible()).toBeFalsy();
await expect(locator).not.toBeVisible();
});
test('caption should be visible and different styles were applied if image zoomed larger than viewport', async ({
@@ -692,7 +692,7 @@ test('caption should be visible and different styles were applied if image zoome
await openHomePage(page);
await waitForEditorLoad(page);
await clickNewPageButton(page);
const title = await getBlockSuiteEditorTitle(page);
const title = getBlockSuiteEditorTitle(page);
await title.click();
await page.keyboard.press('Enter');
await importImage(page, 'http://localhost:8081/large-image.png');
@@ -711,8 +711,8 @@ test('caption should be visible and different styles were applied if image zoome
await expect(captionLocator).toBeVisible();
expect(await captionLocator.innerText()).toBe(sampleCaption);
await page.getByTestId('zoom-in-button').click({ clickCount: 4 });
expect(await captionLocator.isVisible()).not.toBeTruthy();
await expect(captionLocator).not.toBeVisible();
captionLocator = locator.getByTestId('image-caption-zoomedin');
expect(await captionLocator.isVisible()).toBeTruthy();
await expect(captionLocator).toBeVisible();
expect(await captionLocator.innerText()).toBe(sampleCaption);
});
@@ -24,7 +24,7 @@ test('Create new workspace, then delete it', async ({ page, workspace }) => {
await openSettingModal(page);
await openWorkspaceSettingPanel(page, 'Test Workspace');
await page.getByTestId('delete-workspace-button').click();
const workspaceNameDom = await page.getByTestId('workspace-name');
const workspaceNameDom = page.getByTestId('workspace-name');
const currentWorkspaceName = (await workspaceNameDom.evaluate(
node => node.textContent
)) as string;
@@ -51,7 +51,7 @@ test('Create new workspace, then delete it', async ({ page, workspace }) => {
test('Delete last workspace', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
const workspaceNameDom = await page.getByTestId('workspace-name');
const workspaceNameDom = page.getByTestId('workspace-name');
const currentWorkspaceName = await workspaceNameDom.evaluate(
node => node.textContent
);
+2 -2
View File
@@ -10,7 +10,7 @@ import { expect, type Page } from '@playwright/test';
const openQuickSearchByShortcut = async (page: Page) => {
await withCtrlOrMeta(page, () => page.keyboard.press('k', { delay: 50 }));
await page.waitForTimeout(500);
await page.waitForTimeout(1000);
};
const keyboardDownAndSelect = async (page: Page, label: string) => {
@@ -151,6 +151,7 @@ test('Create a new page and search this page', async ({ page }) => {
await page.waitForTimeout(300);
await assertTitle(page, 'test123456');
});
test('Navigate to the 404 page and try to open quick search', async ({
page,
}) => {
@@ -249,7 +250,6 @@ test('assert the recent browse pages are on the recent list', async ({
await page.waitForTimeout(200);
await openQuickSearchByShortcut(page);
await page.waitForTimeout(200);
{
// check does all 3 pages exists on recent page list
const quickSearchItems = page.locator(
+5 -5
View File
@@ -16,7 +16,7 @@ test('Open settings modal', async ({ page }) => {
await waitForEditorLoad(page);
await openSettingModal(page);
const modal = await page.getByTestId('setting-modal');
const modal = page.getByTestId('setting-modal');
await expect(modal).toBeVisible();
});
@@ -69,7 +69,7 @@ test('Change layout width', async ({ page }) => {
await page.getByTestId('full-width-layout-trigger').click();
const editorWrapper = await page.locator('.editor-wrapper');
const editorWrapper = page.locator('.editor-wrapper');
const className = await editorWrapper.getAttribute('class');
expect(className).toContain('full-screen');
});
@@ -79,7 +79,7 @@ test('Open shortcuts panel', async ({ page }) => {
await waitForEditorLoad(page);
await openSettingModal(page);
await openShortcutsPanel(page);
const title = await page.getByTestId('keyboard-shortcuts-title');
const title = page.getByTestId('keyboard-shortcuts-title');
await expect(title).toBeVisible();
});
@@ -88,7 +88,7 @@ test('Open plugins panel', async ({ page }) => {
await waitForEditorLoad(page);
await openSettingModal(page);
await openPluginsPanel(page);
const title = await page.getByTestId('plugins-title');
const title = page.getByTestId('plugins-title');
await expect(title).toBeVisible();
});
@@ -97,7 +97,7 @@ test('Open about panel', async ({ page }) => {
await waitForEditorLoad(page);
await openSettingModal(page);
await openAboutPanel(page);
const title = await page.getByTestId('about-title');
const title = page.getByTestId('about-title');
await expect(title).toBeVisible();
});
+2 -3
View File
@@ -1,7 +1,6 @@
import type { Page } from '@playwright/test';
export const coreUrl = 'http://localhost:8080';
export const prototypeUrl = 'http://localhost:3003';
export async function openHomePage(page: Page) {
await page.goto(coreUrl);
@@ -11,6 +10,6 @@ export async function openPluginPage(page: Page) {
await page.goto(`${coreUrl}/_plugin/index.html`);
}
export async function openPrototypeProviderStatusPage(page: Page) {
await page.goto(`${prototypeUrl}/suite/provider-status.html`);
export async function open404Page(page: Page) {
await page.goto(`${coreUrl}/404`);
}