test: add coverage on collaborative editing (#1747)
This commit is contained in:
@@ -7,6 +7,8 @@ import { readFile } from 'node:fs/promises';
|
|||||||
|
|
||||||
import { MessageCode } from '@affine/env/constant';
|
import { MessageCode } from '@affine/env/constant';
|
||||||
import { createStatusApis } from '@affine/workspace/affine/api/status';
|
import { createStatusApis } from '@affine/workspace/affine/api/status';
|
||||||
|
import user1 from '@affine-test/fixtures/built-in-user1.json';
|
||||||
|
import user2 from '@affine-test/fixtures/built-in-user2.json';
|
||||||
import { assertExists } from '@blocksuite/global/utils';
|
import { assertExists } from '@blocksuite/global/utils';
|
||||||
import { Workspace } from '@blocksuite/store';
|
import { Workspace } from '@blocksuite/store';
|
||||||
import { faker } from '@faker-js/faker';
|
import { faker } from '@faker-js/faker';
|
||||||
@@ -87,6 +89,33 @@ async function createWorkspace(
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe('api', () => {
|
describe('api', () => {
|
||||||
|
test('built-in mock user', async () => {
|
||||||
|
const data = await 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());
|
||||||
|
loginResponseSchema.parse(data);
|
||||||
|
const data2 = await 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());
|
||||||
|
loginResponseSchema.parse(data2);
|
||||||
|
});
|
||||||
|
|
||||||
test('failed', async () => {
|
test('failed', async () => {
|
||||||
workspaceApis = createWorkspaceApis('http://localhost:10086/404/');
|
workspaceApis = createWorkspaceApis('http://localhost:10086/404/');
|
||||||
const listener = vi.fn(
|
const listener = vi.fn(
|
||||||
|
|||||||
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
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
const userB = require('../fixtures/userB.json');
|
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() {
|
export async function createFakeUser() {
|
||||||
try {
|
try {
|
||||||
const response = await Promise.all([
|
const response = await Promise.all([
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ export async function assertCurrentWorkspaceFlavour(
|
|||||||
flavour: 'affine' | 'local',
|
flavour: 'affine' | 'local',
|
||||||
page: Page
|
page: Page
|
||||||
) {
|
) {
|
||||||
// @ts-expect-error type globalThis.currentWorkspace is not defined in playwright context
|
|
||||||
const actual = await page.evaluate(() => globalThis.currentWorkspace.flavour);
|
const actual = await page.evaluate(() => globalThis.currentWorkspace.flavour);
|
||||||
expect(actual).toBe(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