mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-17 14:27:02 +08:00
test: add coverage on collaborative editing (#1747)
This commit is contained in:
5
tests/fixtures/built-in-user1.json
vendored
Normal file
5
tests/fixtures/built-in-user1.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "debug1",
|
||||
"email": "debug1@toeverything.info",
|
||||
"password": "debug1"
|
||||
}
|
||||
5
tests/fixtures/built-in-user2.json
vendored
Normal file
5
tests/fixtures/built-in-user2.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "debug2",
|
||||
"email": "debug2@toeverything.info",
|
||||
"password": "debug2"
|
||||
}
|
||||
@@ -5,6 +5,38 @@ const userA = require('../fixtures/userA.json');
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const userB = require('../fixtures/userB.json');
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const user1 = require('@affine-test/fixtures/built-in-user1.json');
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const user2 = require('@affine-test/fixtures/built-in-user2.json');
|
||||
|
||||
export async function getBuiltInUser() {
|
||||
return Promise.all([
|
||||
fetch('http://localhost:3000/api/user/token', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
type: 'DebugLoginUser',
|
||||
email: user1.email,
|
||||
password: user1.password,
|
||||
}),
|
||||
}).then(r => r.json()),
|
||||
fetch('http://localhost:3000/api/user/token', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
type: 'DebugLoginUser',
|
||||
email: user2.email,
|
||||
password: user2.password,
|
||||
}),
|
||||
}).then(r => r.json()),
|
||||
]);
|
||||
}
|
||||
|
||||
export async function createFakeUser() {
|
||||
try {
|
||||
const response = await Promise.all([
|
||||
|
||||
@@ -27,7 +27,6 @@ export async function assertCurrentWorkspaceFlavour(
|
||||
flavour: 'affine' | 'local',
|
||||
page: Page
|
||||
) {
|
||||
// @ts-expect-error type globalThis.currentWorkspace is not defined in playwright context
|
||||
const actual = await page.evaluate(() => globalThis.currentWorkspace.flavour);
|
||||
expect(actual).toBe(flavour);
|
||||
}
|
||||
|
||||
40
tests/parallels/affine/affine-built-in-workspace.spec.ts
Normal file
40
tests/parallels/affine/affine-built-in-workspace.spec.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { expect } from '@playwright/test';
|
||||
|
||||
import { waitMarkdownImported } from '../../libs/page-logic';
|
||||
import { test } from '../../libs/playwright';
|
||||
import {
|
||||
clickNewPageButton,
|
||||
clickSideBarCurrentWorkspaceBanner,
|
||||
} from '../../libs/sidebar';
|
||||
import { getBuiltInUser, loginUser, openHomePage } from '../../libs/utils';
|
||||
|
||||
test.describe('affine built in workspace', () => {
|
||||
test('collaborative', async ({ page, context }) => {
|
||||
await openHomePage(page);
|
||||
await waitMarkdownImported(page);
|
||||
const [a, b] = await getBuiltInUser();
|
||||
await loginUser(page, a);
|
||||
await page.reload();
|
||||
await page.waitForTimeout(50);
|
||||
await clickSideBarCurrentWorkspaceBanner(page);
|
||||
await page.getByText('Cloud Workspace').click();
|
||||
const page2 = await context.newPage();
|
||||
await openHomePage(page2);
|
||||
await waitMarkdownImported(page2);
|
||||
await loginUser(page2, b);
|
||||
await page2.reload();
|
||||
await clickSideBarCurrentWorkspaceBanner(page2);
|
||||
await page2.getByText('Joined Workspace').click();
|
||||
await clickNewPageButton(page);
|
||||
const url = page.url();
|
||||
await page2.goto(url);
|
||||
await page.type('.affine-default-page-block-title-container', 'hello', {
|
||||
delay: 50,
|
||||
});
|
||||
await page.waitForTimeout(100);
|
||||
const title = await page
|
||||
.locator('.affine-default-page-block-title-container')
|
||||
.textContent();
|
||||
expect(title.trim()).toBe('hello');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user