test: improve data migration suite (#4124)

This commit is contained in:
Alex Yang
2023-09-01 22:31:07 -05:00
committed by GitHub
parent eb1a21265f
commit 70b5a9deeb
43 changed files with 273 additions and 265 deletions

View File

@@ -1,5 +1,5 @@
import { openHomePage } from '@affine-test/kit/utils/load-page';
import { waitEditorLoad } from '@affine-test/kit/utils/page-logic';
import { waitForEditorLoad } from '@affine-test/kit/utils/page-logic';
import { clickSideBarCurrentWorkspaceBanner } from '@affine-test/kit/utils/sidebar';
import { faker } from '@faker-js/faker';
import { hash } from '@node-rs/argon2';
@@ -76,7 +76,7 @@ export async function loginUser(
}
) {
await openHomePage(page);
await waitEditorLoad(page);
await waitForEditorLoad(page);
await clickSideBarCurrentWorkspaceBanner(page);
await page.getByTestId('cloud-signin-button').click({

View File

@@ -10,3 +10,15 @@ export async function checkBlockHub(page: Page) {
if (!box2) throw new Error('block-hub not found');
expect(box2.height).toBeGreaterThan(box.height);
}
export async function clickEdgelessModeButton(page: Page) {
await page.getByTestId('switch-edgeless-mode-button').click({
delay: 50,
});
}
export async function clickPageModeButton(page: Page) {
return page.getByTestId('switch-page-mode-button').click({
delay: 50,
});
}

View File

@@ -1,7 +1,7 @@
import type { Page } from '@playwright/test';
import { expect } from '@playwright/test';
export async function waitEditorLoad(page: Page) {
export async function waitForEditorLoad(page: Page) {
await page.waitForSelector('v-line', {
timeout: 10000,
});
@@ -19,7 +19,7 @@ export async function newPage(page: Page) {
await page.getByTestId('new-page-button').click({
delay: 100,
});
await waitEditorLoad(page);
await waitForEditorLoad(page);
}
export function getBlockSuiteEditorTitle(page: Page) {
@@ -30,11 +30,6 @@ export async function type(page: Page, content: string, delay = 50) {
await page.keyboard.type(content, { delay });
}
export async function pressEnter(page: Page) {
// avoid flaky test by simulate real user input
await page.keyboard.press('Enter', { delay: 50 });
}
export const createLinkedPage = async (page: Page, pageName?: string) => {
await page.keyboard.type('@', { delay: 50 });
const linkedPagePopover = page.locator('.linked-page-popover');

62
tests/kit/utils/proxy.ts Normal file
View File

@@ -0,0 +1,62 @@
import type Test from '@playwright/test';
import type { BrowserContext } from '@playwright/test';
import express from 'express';
import { createProxyMiddleware } from 'http-proxy-middleware';
import { waitForEditorLoad } from './page-logic';
export async function check8080Available(context: BrowserContext) {
// make sure 8080 is ready
const page = await context.newPage();
await page.goto('http://localhost:8080/');
await waitForEditorLoad(page);
await page.close();
}
export function setupProxyServer(test: typeof Test, dir: string) {
let app: express.Express;
let server: ReturnType<express.Express['listen']>;
test.beforeEach(() => {
app = express();
app.use(express.static(dir));
server = app.listen(8081);
});
test.afterEach(() => {
server.close();
});
return {
get app() {
return app;
},
get server() {
return server;
},
switchToNext: async function () {
// close previous express server
await new Promise<void>((resolve, reject) => {
server.close(err => {
if (err) {
reject(err);
}
resolve();
});
});
app = express();
app.use(
createProxyMiddleware({
target: 'http://localhost:8080',
pathFilter: ['**'],
changeOrigin: true,
})
);
return new Promise<void>(resolve => {
server = app.listen(8081, () => {
console.log('proxy to next.js server');
resolve();
});
});
},
};
}