test(core): rewrite some flaky assertions (#5287)
This commit is contained in:
@@ -142,19 +142,19 @@ test('affine onboarding button', async ({ page }) => {
|
|||||||
await page.getByTestId('help-island').click();
|
await page.getByTestId('help-island').click();
|
||||||
await page.getByTestId('easy-guide').click();
|
await page.getByTestId('easy-guide').click();
|
||||||
const onboardingModal = page.locator('[data-testid=onboarding-modal]');
|
const onboardingModal = page.locator('[data-testid=onboarding-modal]');
|
||||||
expect(await onboardingModal.isVisible()).toEqual(true);
|
await expect(onboardingModal).toBeVisible();
|
||||||
const switchVideo = page.locator(
|
const switchVideo = page.locator(
|
||||||
'[data-testid=onboarding-modal-switch-video]'
|
'[data-testid=onboarding-modal-switch-video]'
|
||||||
);
|
);
|
||||||
expect(await switchVideo.isVisible()).toEqual(true);
|
await expect(switchVideo).toBeVisible();
|
||||||
await page.getByTestId('onboarding-modal-next-button').click();
|
await page.getByTestId('onboarding-modal-next-button').click();
|
||||||
const editingVideo = page.locator(
|
const editingVideo = page.locator(
|
||||||
'[data-testid=onboarding-modal-editing-video]'
|
'[data-testid=onboarding-modal-editing-video]'
|
||||||
);
|
);
|
||||||
expect(await editingVideo.isVisible()).toEqual(true);
|
await expect(editingVideo).toBeVisible();
|
||||||
await page.getByTestId('onboarding-modal-close-button').click();
|
await page.getByTestId('onboarding-modal-close-button').click();
|
||||||
|
|
||||||
expect(await onboardingModal.isVisible()).toEqual(false);
|
await expect(onboardingModal).toBeHidden();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('windows only check', async ({ page }) => {
|
test('windows only check', async ({ page }) => {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ const dragToFavourites = async (
|
|||||||
const dragToCollection = async (page: Page, dragItem: Locator) => {
|
const dragToCollection = async (page: Page, dragItem: Locator) => {
|
||||||
await page.getByTestId('slider-bar-add-collection-button').click();
|
await page.getByTestId('slider-bar-add-collection-button').click();
|
||||||
const input = page.getByTestId('input-collection-title');
|
const input = page.getByTestId('input-collection-title');
|
||||||
await input.isVisible();
|
await expect(input).toBeVisible();
|
||||||
await input.fill('test collection');
|
await input.fill('test collection');
|
||||||
await page.getByTestId('save-collection').click();
|
await page.getByTestId('save-collection').click();
|
||||||
const collection = page.getByTestId('collection-item');
|
const collection = page.getByTestId('collection-item');
|
||||||
|
|||||||
@@ -13,10 +13,11 @@ test('Duplicate page should work', async ({ page }) => {
|
|||||||
await waitForEditorLoad(page);
|
await waitForEditorLoad(page);
|
||||||
await clickNewPageButton(page);
|
await clickNewPageButton(page);
|
||||||
const title = getBlockSuiteEditorTitle(page);
|
const title = getBlockSuiteEditorTitle(page);
|
||||||
await title.pressSequentially('test');
|
await expect(title).toBeVisible();
|
||||||
|
await title.fill('test');
|
||||||
await clickPageMoreActions(page);
|
await clickPageMoreActions(page);
|
||||||
const duplicateButton = page.getByTestId('editor-option-menu-duplicate');
|
const duplicateButton = page.getByTestId('editor-option-menu-duplicate');
|
||||||
await duplicateButton.click({ delay: 100 });
|
await duplicateButton.click();
|
||||||
const title2 = getBlockSuiteEditorTitle(page);
|
const title2 = getBlockSuiteEditorTitle(page);
|
||||||
await expect(title2).toHaveText('test(1)', { timeout: 1000 });
|
await expect(title2).toHaveText('test(1)');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ test('image go left and right', async ({ page }) => {
|
|||||||
await importImage(page, 'http://localhost:8081/affine-preview.png');
|
await importImage(page, 'http://localhost:8081/affine-preview.png');
|
||||||
}
|
}
|
||||||
const locator = page.getByTestId('image-preview-modal');
|
const locator = page.getByTestId('image-preview-modal');
|
||||||
expect(locator.isVisible()).toBeTruthy();
|
await expect(locator).toBeHidden();
|
||||||
await page.locator('img').first().dblclick();
|
await page.locator('img').first().dblclick();
|
||||||
await page.waitForTimeout(1000);
|
await page.waitForTimeout(1000);
|
||||||
{
|
{
|
||||||
@@ -125,7 +125,7 @@ test('image able to zoom in and out with mouse scroll', async ({ page }) => {
|
|||||||
const naturalWidth = await locator.evaluate(
|
const naturalWidth = await locator.evaluate(
|
||||||
(img: HTMLImageElement) => img.naturalWidth
|
(img: HTMLImageElement) => img.naturalWidth
|
||||||
);
|
);
|
||||||
expect(locator.isVisible()).toBeTruthy();
|
await expect(locator).toBeVisible();
|
||||||
const { width, height } = await page.evaluate(() => ({
|
const { width, height } = await page.evaluate(() => ({
|
||||||
width: window.innerWidth,
|
width: window.innerWidth,
|
||||||
height: window.innerHeight,
|
height: window.innerHeight,
|
||||||
@@ -660,10 +660,10 @@ test('keypress esc should close the modal', async ({ page }) => {
|
|||||||
await importImage(page, 'http://localhost:8081/large-image.png');
|
await importImage(page, 'http://localhost:8081/large-image.png');
|
||||||
await page.locator('img').first().dblclick();
|
await page.locator('img').first().dblclick();
|
||||||
const locator = page.getByTestId('image-preview-modal');
|
const locator = page.getByTestId('image-preview-modal');
|
||||||
expect(locator.isVisible()).toBeTruthy();
|
await expect(locator).toBeVisible();
|
||||||
await page.keyboard.press('Escape');
|
await page.keyboard.press('Escape');
|
||||||
await page.waitForTimeout(1000);
|
await page.waitForTimeout(1000);
|
||||||
expect(await locator.isVisible()).toBeFalsy();
|
await expect(locator).toBeHidden();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('when mouse moves outside, the modal should be closed', async ({
|
test('when mouse moves outside, the modal should be closed', async ({
|
||||||
@@ -706,7 +706,7 @@ test('caption should be visible and different styles were applied if image zoome
|
|||||||
await page.getByPlaceholder('Write a caption').fill(sampleCaption);
|
await page.getByPlaceholder('Write a caption').fill(sampleCaption);
|
||||||
await page.locator('img').first().dblclick();
|
await page.locator('img').first().dblclick();
|
||||||
const locator = page.getByTestId('image-preview-modal');
|
const locator = page.getByTestId('image-preview-modal');
|
||||||
expect(await locator.isVisible()).toBeTruthy();
|
await expect(locator).toBeVisible();
|
||||||
await page.waitForTimeout(1000);
|
await page.waitForTimeout(1000);
|
||||||
let captionLocator = locator.getByTestId('image-caption-zoomedout');
|
let captionLocator = locator.getByTestId('image-caption-zoomedout');
|
||||||
await expect(captionLocator).toBeVisible();
|
await expect(captionLocator).toBeVisible();
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ const createAndPinCollection = async (
|
|||||||
delay: 200,
|
delay: 200,
|
||||||
});
|
});
|
||||||
const title = page.getByTestId('input-collection-title');
|
const title = page.getByTestId('input-collection-title');
|
||||||
await title.isVisible();
|
await expect(title).toBeVisible();
|
||||||
await title.fill(options?.collectionName ?? 'test collection');
|
await title.fill(options?.collectionName ?? 'test collection');
|
||||||
await page.getByTestId('save-collection').click();
|
await page.getByTestId('save-collection').click();
|
||||||
await page.waitForTimeout(100);
|
await page.waitForTimeout(100);
|
||||||
@@ -162,7 +162,7 @@ test('add collection from sidebar', async ({ page }) => {
|
|||||||
await expect(nullCollection).toBeVisible();
|
await expect(nullCollection).toBeVisible();
|
||||||
await page.getByTestId('slider-bar-add-collection-button').click();
|
await page.getByTestId('slider-bar-add-collection-button').click();
|
||||||
const title = page.getByTestId('input-collection-title');
|
const title = page.getByTestId('input-collection-title');
|
||||||
await title.isVisible();
|
await expect(title).toBeVisible();
|
||||||
await title.fill('test collection');
|
await title.fill('test collection');
|
||||||
await page.getByTestId('save-collection').click();
|
await page.getByTestId('save-collection').click();
|
||||||
await page.waitForTimeout(100);
|
await page.waitForTimeout(100);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ test('Open shortcuts modal', async ({ page }) => {
|
|||||||
|
|
||||||
const shortcutsIcon = page.locator('[data-testid=shortcuts-icon]');
|
const shortcutsIcon = page.locator('[data-testid=shortcuts-icon]');
|
||||||
await page.waitForTimeout(1000);
|
await page.waitForTimeout(1000);
|
||||||
expect(await shortcutsIcon.isVisible()).toEqual(true);
|
await expect(shortcutsIcon).toBeVisible();
|
||||||
|
|
||||||
await shortcutsIcon.click();
|
await shortcutsIcon.click();
|
||||||
await page.waitForTimeout(1000);
|
await page.waitForTimeout(1000);
|
||||||
|
|||||||
@@ -185,27 +185,8 @@ export async function enableCloudWorkspaceFromShareButton(page: Page) {
|
|||||||
const shareMenuButton = page.getByTestId('local-share-menu-button');
|
const shareMenuButton = page.getByTestId('local-share-menu-button');
|
||||||
await expect(shareMenuButton).toBeVisible();
|
await expect(shareMenuButton).toBeVisible();
|
||||||
|
|
||||||
// FIXME: this is a workaround for the flaky test
|
await shareMenuButton.click();
|
||||||
// For unknown reasons,
|
await expect(page.getByTestId('local-share-menu')).toBeVisible();
|
||||||
// the online ci test on GitHub is unable to detect the local-share-menu,
|
|
||||||
// although it works fine in local testing.
|
|
||||||
// To ensure the tests pass consistently, I’ve made the following temporary adjustments.
|
|
||||||
// {
|
|
||||||
const maxAttempts = 5;
|
|
||||||
let attempt = 0;
|
|
||||||
let menuVisible = false;
|
|
||||||
|
|
||||||
while (!menuVisible && attempt < maxAttempts) {
|
|
||||||
try {
|
|
||||||
await shareMenuButton.click();
|
|
||||||
menuVisible = await page.getByTestId('local-share-menu').isVisible();
|
|
||||||
} catch (e) {
|
|
||||||
console.error(`Attempt ${attempt + 1} failed: ${e}`);
|
|
||||||
attempt += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
expect(menuVisible).toBeTruthy();
|
|
||||||
// }
|
|
||||||
|
|
||||||
await page.getByTestId('share-menu-enable-affine-cloud-button').click();
|
await page.getByTestId('share-menu-enable-affine-cloud-button').click();
|
||||||
await page.getByTestId('confirm-enable-affine-cloud-button').click();
|
await page.getByTestId('confirm-enable-affine-cloud-button').click();
|
||||||
|
|||||||
Reference in New Issue
Block a user