Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve data migration suite #4124

Merged
merged 1 commit into from
Sep 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/affine-cloud/e2e/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
getLoginCookie,
loginUser,
} from '@affine-test/kit/utils/cloud';
import { waitEditorLoad } from '@affine-test/kit/utils/page-logic';
import { waitForEditorLoad } from '@affine-test/kit/utils/page-logic';
import { expect } from '@playwright/test';

let user: {
Expand Down Expand Up @@ -37,7 +37,7 @@ test('enable cloud success', async ({ page, context }) => {
afterLogin: async () => {
expect(await getLoginCookie(context)).toBeTruthy();
await page.reload();
await waitEditorLoad(page);
await waitForEditorLoad(page);
expect(await getLoginCookie(context)).toBeTruthy();
},
});
Expand Down
4 changes: 2 additions & 2 deletions tests/affine-cloud/e2e/login.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { test } from '@affine-test/kit/playwright';
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 { expect } from '@playwright/test';

test.describe('login', () => {
test('can open login modal in workspace list', async ({ page }) => {
await openHomePage(page);
await waitEditorLoad(page);
await waitForEditorLoad(page);
await clickSideBarCurrentWorkspaceBanner(page);
await page.getByTestId('cloud-signin-button').click({
delay: 200,
Expand Down
71 changes: 13 additions & 58 deletions tests/affine-legacy/0.7.0-canary.18/e2e/basic.spec.ts
Original file line number Diff line number Diff line change
@@ -1,74 +1,29 @@
import { resolve } from 'node:path';

import { test } from '@affine-test/kit/playwright';
import { newPage, waitForEditorLoad } from '@affine-test/kit/utils/page-logic';
import {
check8080Available,
setupProxyServer,
} from '@affine-test/kit/utils/proxy';
import { expect } from '@playwright/test';
import express from 'express';
import { createProxyMiddleware } from 'http-proxy-middleware';

let app: express.Express;
let server: ReturnType<express.Express['listen']>;

process.env.DEBUG = 'http-proxy-middleware*';

async function switchToNext() {
// 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();
});
});
}

test.beforeEach(() => {
app = express();
app.use(express.static(resolve(__dirname, '..', 'static')));
server = app.listen(8081);
});

test.afterEach(() => {
server.close();
});
const { switchToNext } = setupProxyServer(
test,
resolve(__dirname, '..', 'static')
);

test('init page', async ({ page, context }) => {
{
// make sure 8080 is ready
const page = await context.newPage();
await page.goto('http://localhost:8080/');
await page.waitForSelector('v-line', {
timeout: 10000,
});
await page.close();
}
await check8080Available(context);
await page.goto('http://localhost:8081/');
await page.waitForSelector('v-line', {
timeout: 10000,
});
await page.getByTestId('new-page-button').click();
await waitForEditorLoad(page);
await newPage(page);
const locator = page.locator('v-line').nth(0);
await locator.fill('hello');

await switchToNext();
await page.waitForTimeout(1000);
await page.goto('http://localhost:8081/');
await page.waitForSelector('v-line', {
timeout: 10000,
});
await waitForEditorLoad(page);
expect(await page.locator('v-line').nth(0).textContent()).toBe('hello');
});
3 changes: 3 additions & 0 deletions tests/affine-legacy/0.7.0-canary.18/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
},
"include": ["e2e"],
"references": [
{
"path": "../../fixtures"
},
{
"path": "../../kit"
}
Expand Down
73 changes: 19 additions & 54 deletions tests/affine-legacy/0.8.0-canary.7/e2e/basic.spec.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,20 @@
import { resolve } from 'node:path';

import { clickEdgelessModeButton } from '@affine-test/kit/utils/editor';
import { waitForEditorLoad } from '@affine-test/kit/utils/page-logic';
import {
check8080Available,
setupProxyServer,
} from '@affine-test/kit/utils/proxy';
import { expect, test } from '@playwright/test';
import express from 'express';
import { createProxyMiddleware } from 'http-proxy-middleware';

let app: express.Express;
let server: ReturnType<express.Express['listen']>;

process.env.DEBUG = 'http-proxy-middleware*';

async function switchToNext() {
// 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();
});
});
}

test.beforeEach(() => {
app = express();
app.use(express.static(resolve(__dirname, '..', 'static')));
server = app.listen(8081);
});

test.afterEach(() => {
server.close();
});
const { switchToNext } = setupProxyServer(
test,
resolve(__dirname, '..', 'static')
);

test('database migration', async ({ page, context }) => {
{
// make sure 8080 is ready
const page = await context.newPage();
await page.goto('http://localhost:8080/');
await page.waitForSelector('v-line', {
timeout: 10000,
});
await page.close();
}
await check8080Available(context);
await page.goto('http://localhost:8081/');
await page.waitForSelector('v-line', {
timeout: 10000,
Expand All @@ -76,9 +36,14 @@ test('database migration', async ({ page, context }) => {
await page.waitForTimeout(1000);
await page.goto('http://localhost:8081/');
await page.click('text=hello');
await page.waitForSelector('v-line', {
timeout: 10000,
});
await waitForEditorLoad(page);
// check page mode is correct
expect(await page.locator('v-line').nth(0).textContent()).toBe('hello');
expect(await page.locator('affine-database').isVisible()).toBe(true);

// check edgeless mode is correct
await page.getByTestId('switch-edgeless-mode-button').click();
await clickEdgelessModeButton(page);
await page.waitForTimeout(200);
expect(await page.locator('affine-database').isVisible()).toBe(true);
});
10 changes: 9 additions & 1 deletion tests/affine-legacy/0.8.0-canary.7/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@
"esModuleInterop": true,
"outDir": "lib"
},
"include": ["e2e"]
"include": ["e2e"],
"references": [
{
"path": "../../fixtures"
},
{
"path": "../../kit"
}
]
}
18 changes: 9 additions & 9 deletions tests/affine-local/e2e/all-page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
getBlockSuiteEditorTitle,
newPage,
waitEditorLoad,
waitForAllPagesLoad,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import { clickSideBarAllPageButton } from '@affine-test/kit/utils/sidebar';
import type { Page } from '@playwright/test';
Expand All @@ -45,14 +45,14 @@ function getAllPage(page: Page) {

test('all page', async ({ page }) => {
await openHomePage(page);
await waitEditorLoad(page);
await waitForEditorLoad(page);
await clickSideBarAllPageButton(page);
});

test('all page can create new page', async ({ page }) => {
const { clickNewPageButton } = getAllPage(page);
await openHomePage(page);
await waitEditorLoad(page);
await waitForEditorLoad(page);
await clickSideBarAllPageButton(page);
await clickNewPageButton();
const title = getBlockSuiteEditorTitle(page);
Expand All @@ -65,15 +65,15 @@ test('all page can create new page', async ({ page }) => {
test('all page can create new edgeless page', async ({ page }) => {
const { clickNewEdgelessDropdown } = getAllPage(page);
await openHomePage(page);
await waitEditorLoad(page);
await waitForEditorLoad(page);
await clickSideBarAllPageButton(page);
await clickNewEdgelessDropdown();
await expect(page.locator('affine-edgeless-page')).toBeVisible();
});

test('allow creation of filters by favorite', async ({ page }) => {
await openHomePage(page);
await waitEditorLoad(page);
await waitForEditorLoad(page);
await clickSideBarAllPageButton(page);
await createFirstFilter(page, 'Favourited');
await page
Expand All @@ -87,7 +87,7 @@ test('allow creation of filters by favorite', async ({ page }) => {

test('allow creation of filters by created time', async ({ page }) => {
await openHomePage(page);
await waitEditorLoad(page);
await waitForEditorLoad(page);
await newPage(page);
await clickSideBarAllPageButton(page);
await waitForAllPagesLoad(page);
Expand Down Expand Up @@ -122,7 +122,7 @@ test('creation of filters by created time, then click date picker to modify the
page,
}) => {
await openHomePage(page);
await waitEditorLoad(page);
await waitForEditorLoad(page);
await newPage(page);
await clickSideBarAllPageButton(page);
await waitForAllPagesLoad(page);
Expand Down Expand Up @@ -155,7 +155,7 @@ test('creation of filters by created time, then click date picker to modify the

test('use monthpicker to modify the month of datepicker', async ({ page }) => {
await openHomePage(page);
await waitEditorLoad(page);
await waitForEditorLoad(page);
await clickSideBarAllPageButton(page);
await createFirstFilter(page, 'Created');
await checkFilterName(page, 'after');
Expand All @@ -179,7 +179,7 @@ test('use monthpicker to modify the month of datepicker', async ({ page }) => {

test('allow creation of filters by tags', async ({ page }) => {
await openHomePage(page);
await waitEditorLoad(page);
await waitForEditorLoad(page);
await clickSideBarAllPageButton(page);
await waitForAllPagesLoad(page);
const pages = await page.locator('[data-testid="title"]').all();
Expand Down
4 changes: 2 additions & 2 deletions tests/affine-local/e2e/blocksuite/block-hub.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { test } from '@affine-test/kit/playwright';
import { checkBlockHub } from '@affine-test/kit/utils/editor';
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';

test('block-hub should work', async ({ page }) => {
await openHomePage(page);
await waitEditorLoad(page);
await waitForEditorLoad(page);
await checkBlockHub(page);
});
16 changes: 8 additions & 8 deletions tests/affine-local/e2e/blocksuite/editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
getBlockSuiteEditorTitle,
newPage,
waitEditorLoad,
waitForEditorLoad,
} from '@affine-test/kit/utils/page-logic';
import type { Page } from '@playwright/test';
import { expect } from '@playwright/test';
Expand All @@ -19,9 +19,9 @@ const addDatabase = async (page: Page) => {

test('database is useable', async ({ page }) => {
await openHomePage(page);
await waitEditorLoad(page);
await waitForEditorLoad(page);
await newPage(page);
await waitEditorLoad(page);
await waitForEditorLoad(page);
const title = getBlockSuiteEditorTitle(page);
await title.type('test title');
await page.keyboard.press('Enter');
Expand All @@ -30,9 +30,9 @@ test('database is useable', async ({ page }) => {
const database = page.locator('affine-database');
await expect(database).toBeVisible();
await page.reload();
await waitEditorLoad(page);
await waitForEditorLoad(page);
await newPage(page);
await waitEditorLoad(page);
await waitForEditorLoad(page);
const title2 = getBlockSuiteEditorTitle(page);
await title2.type('test title2');
await page.waitForTimeout(500);
Expand All @@ -45,15 +45,15 @@ test('database is useable', async ({ page }) => {

test('link page is useable', async ({ page }) => {
await openHomePage(page);
await waitEditorLoad(page);
await waitForEditorLoad(page);
await newPage(page);
await waitEditorLoad(page);
await waitForEditorLoad(page);
const title = await getBlockSuiteEditorTitle(page);
await title.type('page1');
await page.keyboard.press('Enter');
expect(await title.innerText()).toBe('page1');
await newPage(page);
await waitEditorLoad(page);
await waitForEditorLoad(page);
const title2 = await getBlockSuiteEditorTitle(page);
await title2.type('page2');
await page.keyboard.press('Enter');
Expand Down