mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-07 01:09:54 +08:00
test(core): enable no-floating-promises rule for tests (#11915)
Sometimes, missing `await` in the test code can cause timing issues, leading to test failures. This PR enables the `no-floating-promises` rule for the test code to ensure that such errors do not occur.
This commit is contained in:
@@ -113,7 +113,7 @@ test.describe('AIBasic/Chat', () => {
|
||||
},
|
||||
]);
|
||||
|
||||
expect(page.getByTestId('chat-action-list')).toBeVisible();
|
||||
await expect(page.getByTestId('chat-action-list')).toBeVisible();
|
||||
await utils.chatPanel.makeChat(page, 'Nice to meet you');
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
@@ -458,7 +458,7 @@ test.describe('AIBasic/Chat', () => {
|
||||
await sendButton.click();
|
||||
|
||||
await expect(page.getByTestId('sidebar-tab-content-chat')).toBeVisible();
|
||||
expect(await page.locator('chat-content-images')).toBeVisible();
|
||||
await expect(page.locator('chat-content-images')).toBeVisible();
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
role: 'user',
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -44,7 +44,7 @@ test.describe('AIInsertion/AddToEdgelessAsNote', () => {
|
||||
|
||||
// Delete default note
|
||||
await (await page.waitForSelector('affine-edgeless-note')).click();
|
||||
page.keyboard.press('Delete');
|
||||
await page.keyboard.press('Delete');
|
||||
|
||||
await utils.chatPanel.openChatPanel(page);
|
||||
await utils.chatPanel.makeChat(page, 'Hello');
|
||||
|
||||
@@ -170,7 +170,7 @@ test.describe('AIInsertion/Insert', () => {
|
||||
|
||||
// Delete default note
|
||||
await (await page.waitForSelector('affine-edgeless-note')).click();
|
||||
page.keyboard.press('Delete');
|
||||
await page.keyboard.press('Delete');
|
||||
|
||||
await utils.chatPanel.openChatPanel(page);
|
||||
await utils.chatPanel.makeChat(page, 'Hello');
|
||||
|
||||
@@ -30,6 +30,10 @@ export class ChatPanelUtils {
|
||||
await page.getByTestId('right-sidebar-toggle').click({
|
||||
delay: 200,
|
||||
});
|
||||
await page.waitForTimeout(500); // wait the sidebar stable
|
||||
}
|
||||
if (await page.getByTestId('notification-close-button').isVisible()) {
|
||||
await page.getByTestId('notification-close-button').click();
|
||||
}
|
||||
await page.getByTestId('sidebar-tab-chat').click();
|
||||
await expect(page.getByTestId('sidebar-tab-content-chat')).toBeVisible();
|
||||
@@ -291,14 +295,14 @@ export class ChatPanelUtils {
|
||||
}
|
||||
|
||||
public static async enableNetworkSearch(page: Page) {
|
||||
const networkSearch = await page.getByTestId('chat-network-search');
|
||||
const networkSearch = page.getByTestId('chat-network-search');
|
||||
if ((await networkSearch.getAttribute('data-active')) === 'false') {
|
||||
await networkSearch.click();
|
||||
}
|
||||
}
|
||||
|
||||
public static async disableNetworkSearch(page: Page) {
|
||||
const networkSearch = await page.getByTestId('chat-network-search');
|
||||
const networkSearch = page.getByTestId('chat-network-search');
|
||||
if ((await networkSearch.getAttribute('data-active')) === 'true') {
|
||||
await networkSearch.click();
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ export class EditorUtils {
|
||||
public static async switchToEdgelessMode(page: Page) {
|
||||
const editor = await page.waitForSelector('page-editor');
|
||||
await page.getByTestId('switch-edgeless-mode-button').click();
|
||||
editor.waitForElementState('hidden');
|
||||
await editor.waitForElementState('hidden');
|
||||
await page.waitForSelector('edgeless-editor');
|
||||
try {
|
||||
const edgelessNotificationClose = page.getByTestId(
|
||||
@@ -408,9 +408,7 @@ export class EditorUtils {
|
||||
checkCodeError: this.createAction(page, () =>
|
||||
page.getByTestId('action-check-code-error').click()
|
||||
),
|
||||
continueWithAi: async () => {
|
||||
page.getByTestId('action-continue-with-ai').click();
|
||||
},
|
||||
continueWithAi: () => page.getByTestId('action-continue-with-ai').click(),
|
||||
continueWriting: this.createAction(page, () =>
|
||||
page.getByTestId('action-continue-writing').click()
|
||||
),
|
||||
@@ -596,9 +594,7 @@ export class EditorUtils {
|
||||
checkCodeError: this.createAction(page, () =>
|
||||
page.getByTestId('action-check-code-error').click()
|
||||
),
|
||||
continueWithAi: async () => {
|
||||
page.getByTestId('action-continue-with-ai').click();
|
||||
},
|
||||
continueWithAi: () => page.getByTestId('action-continue-with-ai').click(),
|
||||
continueWriting: this.createAction(page, () =>
|
||||
page.getByTestId('action-continue-writing').click()
|
||||
),
|
||||
|
||||
@@ -164,7 +164,7 @@ test('can sync svg between different browsers', async ({ page, browser }) => {
|
||||
const fileChooserPromise = page.waitForEvent('filechooser');
|
||||
await page.keyboard.press('Enter', { delay: 50 });
|
||||
const fileChooser = await fileChooserPromise;
|
||||
fileChooser.setFiles(Path.dir(import.meta.url).join('logo.svg').value);
|
||||
await fileChooser.setFiles(Path.dir(import.meta.url).join('logo.svg').value);
|
||||
await expect(image).toBeVisible();
|
||||
|
||||
// the user should see the svg
|
||||
|
||||
@@ -28,6 +28,6 @@ test('import from template should work', async ({ page }) => {
|
||||
const btn = page.getByTestId('import-template-to-workspace-btn');
|
||||
|
||||
await btn.isVisible();
|
||||
btn.click();
|
||||
await btn.click();
|
||||
await waitForEditorLoad(page);
|
||||
});
|
||||
|
||||
@@ -48,7 +48,7 @@ test.describe('split list', () => {
|
||||
listLocator.nth(2).locator('.affine-list-block__numbered')
|
||||
).toHaveText('2.');
|
||||
await expect(listLocator.nth(3).locator('rich-text')).toHaveText('ddd');
|
||||
expect(
|
||||
await expect(
|
||||
listLocator.nth(3).locator('.affine-list-block__numbered')
|
||||
).toHaveText('3.');
|
||||
|
||||
|
||||
@@ -137,15 +137,14 @@ test.skip('create multi workspace in the workspace list', async ({
|
||||
await expect(workspaceCards).toHaveCount(3);
|
||||
}
|
||||
|
||||
const workspaceChangePromise = page.evaluate(() => {
|
||||
new Promise(resolve => {
|
||||
await page.getByTestId('draggable-item').nth(2).click();
|
||||
await page.evaluate(async () => {
|
||||
await new Promise(resolve => {
|
||||
window.addEventListener('affine:workspace:change', resolve, {
|
||||
once: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
await page.getByTestId('draggable-item').nth(2).click();
|
||||
await workspaceChangePromise;
|
||||
|
||||
const nextWorkspace = await workspace.current();
|
||||
|
||||
|
||||
@@ -178,7 +178,7 @@ test('add mindmap into frame, then drag root node of mindmap out.', async ({
|
||||
// drag out
|
||||
{
|
||||
const mindmapBound = await getSelectedBound(page);
|
||||
pressEscape(page);
|
||||
await pressEscape(page);
|
||||
await clickView(page, [
|
||||
mindmapBound[0] + 10,
|
||||
mindmapBound[1] + 0.5 * mindmapBound[3],
|
||||
|
||||
@@ -290,8 +290,8 @@ test.describe('lock', () => {
|
||||
await selectAllByKeyboard(page);
|
||||
await dragBetweenViewCoords(page, [100, 100], [150, 150]);
|
||||
|
||||
assertEdgelessElementBound(page, frame, [100, 100, 200, 200]);
|
||||
assertEdgelessElementBound(page, shape, [150, 150, 50, 50]);
|
||||
await assertEdgelessElementBound(page, frame, [100, 100, 200, 200]);
|
||||
await assertEdgelessElementBound(page, shape, [150, 150, 50, 50]);
|
||||
});
|
||||
|
||||
test('locked element should not be scalable and rotatable. unlocking will recover', async ({
|
||||
|
||||
@@ -196,7 +196,7 @@ test.describe('Embed synced doc in edgeless mode', () => {
|
||||
await expect(edgelessNotes).toHaveCount(2);
|
||||
expect(await getSelectedIds(page)).toHaveLength(1);
|
||||
expect(await getSelectedIds(page)).not.toContain(prevIds);
|
||||
expect(edgelessNotes.last()).toBeVisible();
|
||||
await expect(edgelessNotes.last()).toBeVisible();
|
||||
|
||||
const noteBound = await getSelectedBound(page);
|
||||
expect(isIntersected(embedDocBound, noteBound)).toBe(false);
|
||||
|
||||
@@ -27,7 +27,7 @@ export async function initEmbedSyncedDocState(
|
||||
}
|
||||
|
||||
return await page.evaluate(
|
||||
({ data, option }) => {
|
||||
async ({ data, option }) => {
|
||||
const createDoc = async (
|
||||
docId: string,
|
||||
title: string,
|
||||
@@ -69,11 +69,13 @@ export async function initEmbedSyncedDocState(
|
||||
return note ?? null;
|
||||
};
|
||||
|
||||
const docIds = data.map(({ title, content }, index) => {
|
||||
const id = index === 0 ? window.doc.id : `embed-doc-${index}`;
|
||||
createDoc(id, title, content);
|
||||
return id;
|
||||
});
|
||||
const docIds = await Promise.all(
|
||||
data.map(async ({ title, content }, index) => {
|
||||
const id = index === 0 ? window.doc.id : `embed-doc-${index}`;
|
||||
await createDoc(id, title, content);
|
||||
return id;
|
||||
})
|
||||
);
|
||||
|
||||
const { NoteBlockModel, NoteDisplayMode } =
|
||||
window.$blocksuite.affineModel;
|
||||
|
||||
@@ -473,7 +473,7 @@ export async function createEdgelessNoteBlock(
|
||||
) {
|
||||
await setEdgelessTool(page, 'note', undefined, editorIndex);
|
||||
if (position.length === 4) {
|
||||
dragView(
|
||||
await dragView(
|
||||
page,
|
||||
[position[0], position[1]],
|
||||
[position[0] + position[2], position[1] + position[3]]
|
||||
|
||||
@@ -122,7 +122,7 @@ export const addCustomProperty = async (
|
||||
root: Locator | Page,
|
||||
type: string
|
||||
) => {
|
||||
ensureAddPropertyButtonVisible(page, root);
|
||||
await ensureAddPropertyButtonVisible(page, root);
|
||||
await clickAddPropertyButton(root);
|
||||
await page
|
||||
.locator(
|
||||
|
||||
Reference in New Issue
Block a user