test(core): enable no-floating-promises rule for tests (#11915)
Sometimes, missing `await` in the test code can cause timing issues, leading to test failures. This PR enables the `no-floating-promises` rule for the test code to ensure that such errors do not occur.
This commit is contained in:
parent
200015a811
commit
a9ad01491c
@ -11,7 +11,7 @@ import { addSampleNotes } from './doc-generator.js';
|
||||
import { createPainterWorker, setupEditor } from './setup.js';
|
||||
|
||||
async function init() {
|
||||
setupEditor('edgeless', [
|
||||
await setupEditor('edgeless', [
|
||||
ParagraphLayoutHandlerExtension,
|
||||
ListLayoutHandlerExtension,
|
||||
ImageLayoutHandlerExtension,
|
||||
@ -29,4 +29,4 @@ async function init() {
|
||||
window.renderer = renderer;
|
||||
}
|
||||
|
||||
init();
|
||||
await init();
|
||||
|
@ -299,7 +299,10 @@ export default tseslint.config(
|
||||
'**/e2e/**/*',
|
||||
],
|
||||
rules: {
|
||||
'@typescript-eslint/no-floating-promises': 0,
|
||||
'@typescript-eslint/no-floating-promises': [
|
||||
'error',
|
||||
{ ignoreVoid: true },
|
||||
],
|
||||
'@typescript-eslint/no-misused-promises': 0,
|
||||
'@typescript-eslint/no-restricted-imports': 0,
|
||||
},
|
||||
|
@ -181,7 +181,7 @@ test('should create session correctly', async t => {
|
||||
);
|
||||
});
|
||||
|
||||
app.switchUser(u1);
|
||||
await app.switchUser(u1);
|
||||
const inviteId = await inviteUser(app, id, u2.email);
|
||||
await app.login(u2);
|
||||
await acceptInviteById(app, id, inviteId, false);
|
||||
@ -329,9 +329,9 @@ test('should fork session correctly', async t => {
|
||||
);
|
||||
});
|
||||
|
||||
app.switchUser(u1);
|
||||
await app.switchUser(u1);
|
||||
const inviteId = await inviteUser(app, id, u2.email);
|
||||
app.switchUser(u2);
|
||||
await app.switchUser(u2);
|
||||
await acceptInviteById(app, id, inviteId, false);
|
||||
await assertForkSession(id, sessionId, randomUUID(), '', async x => {
|
||||
await t.throwsAsync(
|
||||
@ -341,14 +341,14 @@ test('should fork session correctly', async t => {
|
||||
);
|
||||
});
|
||||
|
||||
app.switchUser(u1);
|
||||
await app.switchUser(u1);
|
||||
const histories = await getHistories(app, { workspaceId: id });
|
||||
const latestMessageId = histories
|
||||
.find(h => h.sessionId === forkedSessionId)
|
||||
?.messages.findLast(m => m.role === 'assistant')?.id;
|
||||
t.truthy(latestMessageId, 'should find latest message id');
|
||||
|
||||
app.switchUser(u2);
|
||||
await app.switchUser(u2);
|
||||
await assertForkSession(
|
||||
id,
|
||||
forkedSessionId,
|
||||
@ -654,10 +654,10 @@ test('should reject request from different user', async t => {
|
||||
|
||||
// should reject chat from different user
|
||||
{
|
||||
app.switchUser(u1);
|
||||
await app.switchUser(u1);
|
||||
const messageId = await createCopilotMessage(app, sessionId);
|
||||
{
|
||||
app.switchUser(u2);
|
||||
await app.switchUser(u2);
|
||||
await t.throwsAsync(
|
||||
chatWithText(app, sessionId, messageId),
|
||||
{ instanceOf: Error },
|
||||
@ -723,9 +723,9 @@ test('should reject request that user have not permission', async t => {
|
||||
|
||||
// should able to list history after user have permission
|
||||
{
|
||||
app.switchUser(u1);
|
||||
await app.switchUser(u1);
|
||||
const inviteId = await inviteUser(app, workspaceId, u2.email);
|
||||
app.switchUser(u2);
|
||||
await app.switchUser(u2);
|
||||
await acceptInviteById(app, workspaceId, inviteId, false);
|
||||
|
||||
t.deepEqual(
|
||||
@ -753,7 +753,7 @@ test('should reject request that user have not permission', async t => {
|
||||
'should able to list history'
|
||||
);
|
||||
|
||||
app.switchUser(u1);
|
||||
await app.switchUser(u1);
|
||||
t.deepEqual(
|
||||
await getHistories(app, { workspaceId }),
|
||||
[],
|
||||
|
@ -6,6 +6,6 @@ export const e2e = test;
|
||||
// @ts-expect-error created in prelude.ts
|
||||
export const app: TestingApp = globalThis.app;
|
||||
|
||||
registerCompletionHandler(() => {
|
||||
app.close();
|
||||
registerCompletionHandler(async () => {
|
||||
await app.close();
|
||||
});
|
||||
|
@ -77,7 +77,7 @@ e2e('should leave a workspace', async t => {
|
||||
userId: u2.id,
|
||||
});
|
||||
|
||||
app.switchUser(u2.id);
|
||||
await app.switchUser(u2.id);
|
||||
const { leaveWorkspace } = await app.gql({
|
||||
query: leaveWorkspaceMutation,
|
||||
variables: {
|
||||
@ -182,7 +182,7 @@ e2e('should invite a user by link', async t => {
|
||||
},
|
||||
});
|
||||
|
||||
app.switchUser(u2);
|
||||
await app.switchUser(u2);
|
||||
const accept = await app.gql({
|
||||
query: acceptInviteByInviteIdMutation,
|
||||
variables: {
|
||||
@ -192,7 +192,7 @@ e2e('should invite a user by link', async t => {
|
||||
});
|
||||
t.true(accept.acceptInviteById, 'failed to accept invite');
|
||||
|
||||
app.switchUser(owner);
|
||||
await app.switchUser(owner);
|
||||
const invite2 = await app.gql({
|
||||
query: inviteByEmailMutation,
|
||||
variables: {
|
||||
@ -233,7 +233,7 @@ e2e('should send invitation notification and leave email', async t => {
|
||||
t.is(invitationNotification.payload.inviterId, owner.id);
|
||||
t.is(invitationNotification.payload.inviteId, invite.invite);
|
||||
|
||||
app.switchUser(u2);
|
||||
await app.switchUser(u2);
|
||||
const accept = await app.gql({
|
||||
query: acceptInviteByInviteIdMutation,
|
||||
variables: {
|
||||
|
@ -42,7 +42,7 @@ export class MockCopilotProvider extends OpenAIProvider {
|
||||
model: string = 'test',
|
||||
options: CopilotChatOptions = {}
|
||||
): Promise<string> {
|
||||
this.checkParams({ messages, model, options });
|
||||
await this.checkParams({ messages, model, options });
|
||||
// make some time gap for history test case
|
||||
await sleep(100);
|
||||
return 'generate text to text';
|
||||
@ -53,7 +53,7 @@ export class MockCopilotProvider extends OpenAIProvider {
|
||||
model: string = 'gpt-4.1-mini',
|
||||
options: CopilotChatOptions = {}
|
||||
): AsyncIterable<string> {
|
||||
this.checkParams({ messages, model, options });
|
||||
await this.checkParams({ messages, model, options });
|
||||
|
||||
// make some time gap for history test case
|
||||
await sleep(100);
|
||||
@ -74,7 +74,7 @@ export class MockCopilotProvider extends OpenAIProvider {
|
||||
options: CopilotEmbeddingOptions = { dimensions: DEFAULT_DIMENSIONS }
|
||||
): Promise<number[][]> {
|
||||
messages = Array.isArray(messages) ? messages : [messages];
|
||||
this.checkParams({ embeddings: messages, model, options });
|
||||
await this.checkParams({ embeddings: messages, model, options });
|
||||
|
||||
// make some time gap for history test case
|
||||
await sleep(100);
|
||||
|
@ -90,9 +90,14 @@ const init = async (
|
||||
const workspace = await createWorkspace(app);
|
||||
const teamWorkspace = await createWorkspace(app);
|
||||
{
|
||||
models.workspaceFeature.add(teamWorkspace.id, 'team_plan_v1', 'test', {
|
||||
memberLimit,
|
||||
});
|
||||
await models.workspaceFeature.add(
|
||||
teamWorkspace.id,
|
||||
'team_plan_v1',
|
||||
'test',
|
||||
{
|
||||
memberLimit,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
const invite = async (
|
||||
@ -104,29 +109,29 @@ const init = async (
|
||||
|
||||
{
|
||||
// normal workspace
|
||||
app.switchUser(owner);
|
||||
await app.switchUser(owner);
|
||||
const inviteId = await inviteUser(
|
||||
app,
|
||||
workspace.id,
|
||||
member.email,
|
||||
shouldSendEmail
|
||||
);
|
||||
app.switchUser(member);
|
||||
await app.switchUser(member);
|
||||
await acceptInviteById(app, workspace.id, inviteId, shouldSendEmail);
|
||||
}
|
||||
|
||||
{
|
||||
// team workspace
|
||||
app.switchUser(owner);
|
||||
await app.switchUser(owner);
|
||||
const inviteId = await inviteUser(
|
||||
app,
|
||||
teamWorkspace.id,
|
||||
member.email,
|
||||
shouldSendEmail
|
||||
);
|
||||
app.switchUser(member);
|
||||
await app.switchUser(member);
|
||||
await acceptInviteById(app, teamWorkspace.id, inviteId, shouldSendEmail);
|
||||
app.switchUser(owner);
|
||||
await app.switchUser(owner);
|
||||
await grantMember(app, teamWorkspace.id, member.id, permission);
|
||||
}
|
||||
|
||||
@ -143,7 +148,7 @@ const init = async (
|
||||
members.push(member);
|
||||
}
|
||||
|
||||
app.switchUser(owner);
|
||||
await app.switchUser(owner);
|
||||
const invites = await inviteUsers(
|
||||
app,
|
||||
teamWorkspace.id,
|
||||
@ -154,7 +159,7 @@ const init = async (
|
||||
};
|
||||
|
||||
const getCreateInviteLinkFetcher = async (ws: WorkspaceType) => {
|
||||
app.switchUser(owner);
|
||||
await app.switchUser(owner);
|
||||
const { link } = await createInviteLink(app, ws.id, 'OneDay');
|
||||
const inviteId = link.split('/').pop()!;
|
||||
return [
|
||||
@ -165,7 +170,7 @@ const init = async (
|
||||
return member;
|
||||
},
|
||||
async (userId: string) => {
|
||||
app.switchUser(userId);
|
||||
await app.switchUser(userId);
|
||||
await acceptInviteById(app, ws.id, inviteId, false);
|
||||
},
|
||||
] as const;
|
||||
@ -183,7 +188,7 @@ const init = async (
|
||||
WorkspaceRole.External
|
||||
);
|
||||
|
||||
app.switchUser(owner.id);
|
||||
await app.switchUser(owner.id);
|
||||
return {
|
||||
invite,
|
||||
inviteBatch,
|
||||
@ -204,13 +209,13 @@ test('should be able to invite multiple users', async t => {
|
||||
|
||||
{
|
||||
// no permission
|
||||
app.switchUser(read);
|
||||
await app.switchUser(read);
|
||||
await t.throwsAsync(
|
||||
inviteUsers(app, ws.id, ['test@affine.pro']),
|
||||
{ instanceOf: Error },
|
||||
'should throw error if not manager'
|
||||
);
|
||||
app.switchUser(write);
|
||||
await app.switchUser(write);
|
||||
await t.throwsAsync(
|
||||
inviteUsers(app, ws.id, ['test@affine.pro']),
|
||||
{ instanceOf: Error },
|
||||
@ -222,13 +227,13 @@ test('should be able to invite multiple users', async t => {
|
||||
// manager
|
||||
const m1 = await app.signupV1('m1@affine.pro');
|
||||
const m2 = await app.signupV1('m2@affine.pro');
|
||||
app.switchUser(owner);
|
||||
await app.switchUser(owner);
|
||||
t.is(
|
||||
(await inviteUsers(app, ws.id, [m1.email])).length,
|
||||
1,
|
||||
'should be able to invite user'
|
||||
);
|
||||
app.switchUser(admin);
|
||||
await app.switchUser(admin);
|
||||
t.is(
|
||||
(await inviteUsers(app, ws.id, [m2.email])).length,
|
||||
1,
|
||||
@ -263,7 +268,7 @@ test('should be able to check seat limit', async t => {
|
||||
{ message: 'You have exceeded your workspace member quota.' },
|
||||
'should throw error if exceed member limit'
|
||||
);
|
||||
models.workspaceFeature.add(ws.id, 'team_plan_v1', 'test', {
|
||||
await models.workspaceFeature.add(ws.id, 'team_plan_v1', 'test', {
|
||||
memberLimit: 6,
|
||||
});
|
||||
await t.notThrowsAsync(
|
||||
@ -310,14 +315,14 @@ test('should be able to grant team member permission', async t => {
|
||||
const { app, models } = t.context;
|
||||
const { owner, teamWorkspace: ws, write, read } = await init(app);
|
||||
|
||||
app.switchUser(read);
|
||||
await app.switchUser(read);
|
||||
await t.throwsAsync(
|
||||
grantMember(app, ws.id, write.id, WorkspaceRole.Collaborator),
|
||||
{ instanceOf: Error },
|
||||
'should throw error if not owner'
|
||||
);
|
||||
|
||||
app.switchUser(write);
|
||||
await app.switchUser(write);
|
||||
await t.throwsAsync(
|
||||
grantMember(app, ws.id, read.id, WorkspaceRole.Collaborator),
|
||||
{ instanceOf: Error },
|
||||
@ -326,7 +331,7 @@ test('should be able to grant team member permission', async t => {
|
||||
|
||||
{
|
||||
// owner should be able to grant permission
|
||||
app.switchUser(owner);
|
||||
await app.switchUser(owner);
|
||||
t.true(
|
||||
(await models.workspaceUser.get(ws.id, read.id))?.type ===
|
||||
WorkspaceRole.Collaborator,
|
||||
@ -348,24 +353,24 @@ test('should be able to leave workspace', async t => {
|
||||
const { app } = t.context;
|
||||
const { owner, teamWorkspace: ws, admin, write, read } = await init(app);
|
||||
|
||||
app.switchUser(owner);
|
||||
await app.switchUser(owner);
|
||||
await t.throwsAsync(leaveWorkspace(app, ws.id), {
|
||||
message: 'Owner can not leave the workspace.',
|
||||
});
|
||||
|
||||
app.switchUser(admin);
|
||||
await app.switchUser(admin);
|
||||
t.true(
|
||||
await leaveWorkspace(app, ws.id),
|
||||
'admin should be able to leave workspace'
|
||||
);
|
||||
|
||||
app.switchUser(write);
|
||||
await app.switchUser(write);
|
||||
t.true(
|
||||
await leaveWorkspace(app, ws.id),
|
||||
'write should be able to leave workspace'
|
||||
);
|
||||
|
||||
app.switchUser(read);
|
||||
await app.switchUser(read);
|
||||
t.true(
|
||||
await leaveWorkspace(app, ws.id),
|
||||
'read should be able to leave workspace'
|
||||
@ -378,7 +383,7 @@ test('should be able to revoke team member', async t => {
|
||||
|
||||
{
|
||||
// no permission
|
||||
app.switchUser(read);
|
||||
await app.switchUser(read);
|
||||
await t.throwsAsync(
|
||||
revokeUser(app, ws.id, read.id),
|
||||
{ instanceOf: Error },
|
||||
@ -393,7 +398,7 @@ test('should be able to revoke team member', async t => {
|
||||
|
||||
{
|
||||
// manager
|
||||
app.switchUser(admin);
|
||||
await app.switchUser(admin);
|
||||
t.true(
|
||||
await revokeUser(app, ws.id, read.id),
|
||||
'admin should be able to revoke member'
|
||||
@ -405,7 +410,7 @@ test('should be able to revoke team member', async t => {
|
||||
'should not be able to revoke themselves'
|
||||
);
|
||||
|
||||
app.switchUser(owner);
|
||||
await app.switchUser(owner);
|
||||
t.true(
|
||||
await revokeUser(app, ws.id, write.id),
|
||||
'owner should be able to revoke member'
|
||||
@ -416,7 +421,7 @@ test('should be able to revoke team member', async t => {
|
||||
});
|
||||
|
||||
await revokeUser(app, ws.id, admin.id);
|
||||
app.switchUser(admin);
|
||||
await app.switchUser(admin);
|
||||
await t.throwsAsync(
|
||||
revokeUser(app, ws.id, read.id),
|
||||
{ instanceOf: Error },
|
||||
@ -441,7 +446,7 @@ test('should be able to manage invite link', async t => {
|
||||
[tws, [owner, admin]],
|
||||
] as const) {
|
||||
for (const manager of managers) {
|
||||
app.switchUser(manager.id);
|
||||
await app.switchUser(manager.id);
|
||||
const { link } = await createInviteLink(app, workspace.id, 'OneDay');
|
||||
const { link: currLink } = await getInviteLink(app, workspace.id);
|
||||
t.is(link, currLink, 'should be able to get invite link');
|
||||
@ -453,7 +458,7 @@ test('should be able to manage invite link', async t => {
|
||||
}
|
||||
|
||||
for (const collaborator of [write, read]) {
|
||||
app.switchUser(collaborator.id);
|
||||
await app.switchUser(collaborator.id);
|
||||
await t.throwsAsync(
|
||||
createInviteLink(app, workspace.id, 'OneDay'),
|
||||
{ instanceOf: Error },
|
||||
@ -478,7 +483,7 @@ test('should be able to approve team member', async t => {
|
||||
const { teamWorkspace: tws, owner, admin, write, read } = await init(app, 6);
|
||||
|
||||
{
|
||||
app.switchUser(owner);
|
||||
await app.switchUser(owner);
|
||||
const { link } = await createInviteLink(app, tws.id, 'OneDay');
|
||||
const inviteId = link.split('/').pop()!;
|
||||
|
||||
@ -488,7 +493,7 @@ test('should be able to approve team member', async t => {
|
||||
'should be able to accept invite'
|
||||
);
|
||||
|
||||
app.switchUser(owner);
|
||||
await app.switchUser(owner);
|
||||
const { members } = await getWorkspace(app, tws.id);
|
||||
const memberInvite = members.find(m => m.id === member.id)!;
|
||||
t.is(memberInvite.status, 'UnderReview', 'should be under review');
|
||||
@ -509,21 +514,21 @@ test('should be able to approve team member', async t => {
|
||||
}
|
||||
|
||||
{
|
||||
app.switchUser(admin);
|
||||
await app.switchUser(admin);
|
||||
await t.throwsAsync(
|
||||
approveMember(app, tws.id, 'not_exists_id'),
|
||||
{ instanceOf: Error },
|
||||
'should throw error if member not exists'
|
||||
);
|
||||
|
||||
app.switchUser(write);
|
||||
await app.switchUser(write);
|
||||
await t.throwsAsync(
|
||||
approveMember(app, tws.id, 'not_exists_id'),
|
||||
{ instanceOf: Error },
|
||||
'should throw error if not manager'
|
||||
);
|
||||
|
||||
app.switchUser(read);
|
||||
await app.switchUser(read);
|
||||
await t.throwsAsync(
|
||||
approveMember(app, tws.id, 'not_exists_id'),
|
||||
{ instanceOf: Error },
|
||||
@ -547,7 +552,7 @@ test('should be able to invite by link', async t => {
|
||||
const member = await app.signup();
|
||||
{
|
||||
// check invite link
|
||||
app.switchUser(member);
|
||||
await app.switchUser(member);
|
||||
const info = await getInviteInfo(app, inviteId);
|
||||
t.is(info.workspace.id, ws.id, 'should be able to get invite info');
|
||||
t.falsy(info.status);
|
||||
@ -601,7 +606,7 @@ test('should be able to invite by link', async t => {
|
||||
'should not change status'
|
||||
);
|
||||
|
||||
models.workspaceFeature.add(tws.id, 'team_plan_v1', 'test', {
|
||||
await models.workspaceFeature.add(tws.id, 'team_plan_v1', 'test', {
|
||||
memberLimit: 6,
|
||||
});
|
||||
await models.workspaceUser.refresh(tws.id, 6);
|
||||
@ -616,7 +621,7 @@ test('should be able to invite by link', async t => {
|
||||
'should not change status'
|
||||
);
|
||||
|
||||
models.workspaceFeature.add(tws.id, 'team_plan_v1', 'test', {
|
||||
await models.workspaceFeature.add(tws.id, 'team_plan_v1', 'test', {
|
||||
memberLimit: 7,
|
||||
});
|
||||
await models.workspaceUser.refresh(tws.id, 7);
|
||||
@ -670,7 +675,7 @@ test('should be able to emit events and send notifications', async t => {
|
||||
const { teamWorkspace: tws, owner, createInviteLink } = await init(app);
|
||||
const [, invite] = await createInviteLink(tws);
|
||||
const user = await invite('m3@affine.pro');
|
||||
app.switchUser(owner);
|
||||
await app.switchUser(owner);
|
||||
const { members } = await getWorkspace(app, tws.id);
|
||||
const memberInvite = members.find(m => m.id === user.id)!;
|
||||
const requestRequestNotification = app.queue.last(
|
||||
@ -688,7 +693,7 @@ test('should be able to emit events and send notifications', async t => {
|
||||
'should send review request notification'
|
||||
);
|
||||
|
||||
app.switchUser(owner);
|
||||
await app.switchUser(owner);
|
||||
await revokeUser(app, tws.id, user.id);
|
||||
const requestDeclinedNotification = app.queue.last(
|
||||
'notification.sendInvitationReviewDeclined'
|
||||
@ -735,7 +740,7 @@ test('should be able to emit events and send notifications', async t => {
|
||||
'should emit owner transferred event'
|
||||
);
|
||||
|
||||
app.switchUser(read);
|
||||
await app.switchUser(read);
|
||||
await revokeMember(app, tws.id, owner.id);
|
||||
const [memberRemoved, memberUpdated] = event.emit
|
||||
.getCalls()
|
||||
@ -777,7 +782,7 @@ test('should be able to grant and revoke users role in page', async t => {
|
||||
} = await init(app, 5);
|
||||
const docId = nanoid();
|
||||
|
||||
app.switchUser(admin);
|
||||
await app.switchUser(admin);
|
||||
const res = await grantDocUserRoles(
|
||||
app,
|
||||
ws.id,
|
||||
@ -795,7 +800,7 @@ test('should be able to grant and revoke users role in page', async t => {
|
||||
await grantDocUserRoles(app, ws.id, docId, [read.id], DocRole.Reader);
|
||||
|
||||
// read still be the Manager of this doc
|
||||
app.switchUser(read);
|
||||
await app.switchUser(read);
|
||||
const res = await grantDocUserRoles(
|
||||
app,
|
||||
ws.id,
|
||||
@ -807,7 +812,7 @@ test('should be able to grant and revoke users role in page', async t => {
|
||||
grantDocUserRoles: true,
|
||||
});
|
||||
|
||||
app.switchUser(admin);
|
||||
await app.switchUser(admin);
|
||||
const docUsersList = await docGrantedUsersList(app, ws.id, docId);
|
||||
t.is(docUsersList.workspace.doc.grantedUsersList.totalCount, 3);
|
||||
const externalRole = docUsersList.workspace.doc.grantedUsersList.edges.find(
|
||||
@ -821,7 +826,7 @@ test('should be able to change the default role in page', async t => {
|
||||
const { app } = t.context;
|
||||
const { teamWorkspace: ws, admin } = await init(app, 5);
|
||||
const docId = nanoid();
|
||||
app.switchUser(admin);
|
||||
await app.switchUser(admin);
|
||||
const res = await updateDocDefaultRole(app, ws.id, docId, DocRole.Reader);
|
||||
|
||||
t.deepEqual(res, {
|
||||
@ -840,7 +845,7 @@ test('default page role should be able to override the workspace role', async t
|
||||
|
||||
const docId = nanoid();
|
||||
|
||||
app.switchUser(admin);
|
||||
await app.switchUser(admin);
|
||||
const res = await updateDocDefaultRole(
|
||||
app,
|
||||
workspace.id,
|
||||
@ -854,7 +859,7 @@ test('default page role should be able to override the workspace role', async t
|
||||
|
||||
// reader can manage the page if the page default role is Manager
|
||||
{
|
||||
app.switchUser(read);
|
||||
await app.switchUser(read);
|
||||
const readerRes = await updateDocDefaultRole(
|
||||
app,
|
||||
workspace.id,
|
||||
@ -869,7 +874,7 @@ test('default page role should be able to override the workspace role', async t
|
||||
|
||||
// external can't manage the page even if the page default role is Manager
|
||||
{
|
||||
app.switchUser(external);
|
||||
await app.switchUser(external);
|
||||
await t.throwsAsync(
|
||||
updateDocDefaultRole(app, workspace.id, docId, DocRole.Manager),
|
||||
{
|
||||
@ -884,7 +889,7 @@ test('should be able to grant and revoke doc user role', async t => {
|
||||
const { teamWorkspace: ws, admin, read, external } = await init(app, 5);
|
||||
const docId = nanoid();
|
||||
|
||||
app.switchUser(admin);
|
||||
await app.switchUser(admin);
|
||||
const res = await grantDocUserRoles(
|
||||
app,
|
||||
ws.id,
|
||||
@ -899,7 +904,7 @@ test('should be able to grant and revoke doc user role', async t => {
|
||||
|
||||
// external user can never be able to manage the page
|
||||
{
|
||||
app.switchUser(external);
|
||||
await app.switchUser(external);
|
||||
await t.throwsAsync(
|
||||
grantDocUserRoles(app, ws.id, docId, [read.id], DocRole.Manager),
|
||||
{
|
||||
@ -910,7 +915,7 @@ test('should be able to grant and revoke doc user role', async t => {
|
||||
|
||||
// revoke the role of the external user
|
||||
{
|
||||
app.switchUser(admin);
|
||||
await app.switchUser(admin);
|
||||
const revokeRes = await revokeDocUserRoles(app, ws.id, docId, external.id);
|
||||
|
||||
t.deepEqual(revokeRes, {
|
||||
@ -918,7 +923,7 @@ test('should be able to grant and revoke doc user role', async t => {
|
||||
});
|
||||
|
||||
// external user can't manage the page
|
||||
app.switchUser(external);
|
||||
await app.switchUser(external);
|
||||
await t.throwsAsync(revokeDocUserRoles(app, ws.id, docId, read.id), {
|
||||
message: `You do not have permission to perform Doc.Users.Manage action on doc ${docId}.`,
|
||||
});
|
||||
@ -930,7 +935,7 @@ test('update page default role should throw error if the space does not exist',
|
||||
const { admin } = await init(app, 5);
|
||||
const docId = nanoid();
|
||||
const nonExistWorkspaceId = 'non-exist-workspace';
|
||||
app.switchUser(admin);
|
||||
await app.switchUser(admin);
|
||||
await t.throwsAsync(
|
||||
updateDocDefaultRole(app, nonExistWorkspaceId, docId, DocRole.Manager),
|
||||
{
|
||||
|
@ -47,7 +47,7 @@ const assertAndSnapshotRaw = async (
|
||||
.send(options?.body)
|
||||
.expect(status)
|
||||
.expect(checker);
|
||||
t.notThrowsAsync(res, message);
|
||||
await t.notThrowsAsync(res, message);
|
||||
t.snapshot((await res).body);
|
||||
};
|
||||
|
||||
|
@ -122,7 +122,7 @@ test('should be able to get workspace doc', async t => {
|
||||
const u1 = await app.signupV1('u1@affine.pro');
|
||||
const u2 = await app.signupV1('u2@affine.pro');
|
||||
|
||||
app.switchUser(u1.id);
|
||||
await app.switchUser(u1.id);
|
||||
const workspace = await createWorkspace(app);
|
||||
|
||||
const res1 = await app
|
||||
@ -136,7 +136,7 @@ test('should be able to get workspace doc', async t => {
|
||||
'failed to get doc with u1 token'
|
||||
);
|
||||
|
||||
app.switchUser(u2.id);
|
||||
await app.switchUser(u2.id);
|
||||
await app
|
||||
.GET(`/api/workspaces/${workspace.id}/docs/${workspace.id}`)
|
||||
.expect(403);
|
||||
|
@ -28,12 +28,12 @@ async function randomPut(
|
||||
): Promise<string> {
|
||||
const key = prefix + 'test-key-' + Math.random().toString(16).substring(2, 8);
|
||||
const body = Buffer.from(key);
|
||||
provider.put(key, body);
|
||||
await provider.put(key, body);
|
||||
return key;
|
||||
}
|
||||
|
||||
test.after.always(() => {
|
||||
fs.rm(config.path, { recursive: true });
|
||||
fs.rm(config.path, { recursive: true }).catch(console.error);
|
||||
});
|
||||
|
||||
test('put & get', async t => {
|
||||
|
@ -22,12 +22,18 @@ describe('async-queue', () => {
|
||||
let v = -1;
|
||||
|
||||
// setup 2 pop tasks
|
||||
queue.next().then(next => {
|
||||
v = next;
|
||||
});
|
||||
queue.next().then(next => {
|
||||
v = next;
|
||||
});
|
||||
queue
|
||||
.next()
|
||||
.then(next => {
|
||||
v = next;
|
||||
})
|
||||
.catch(console.error);
|
||||
queue
|
||||
.next()
|
||||
.then(next => {
|
||||
v = next;
|
||||
})
|
||||
.catch(console.error);
|
||||
|
||||
// Wait for 100ms
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
|
@ -82,7 +82,7 @@ const AudioWrapper = () => {
|
||||
e.preventDefault();
|
||||
const file = e.dataTransfer.files[0];
|
||||
if (file && file.type.startsWith('audio/')) {
|
||||
handleFileChange(file);
|
||||
handleFileChange(file).catch(console.error);
|
||||
}
|
||||
},
|
||||
[handleFileChange]
|
||||
@ -92,7 +92,7 @@ const AudioWrapper = () => {
|
||||
(e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (file) {
|
||||
handleFileChange(file);
|
||||
handleFileChange(file).catch(console.error);
|
||||
}
|
||||
},
|
||||
[handleFileChange]
|
||||
|
@ -113,7 +113,7 @@ test.describe('AIBasic/Chat', () => {
|
||||
},
|
||||
]);
|
||||
|
||||
expect(page.getByTestId('chat-action-list')).toBeVisible();
|
||||
await expect(page.getByTestId('chat-action-list')).toBeVisible();
|
||||
await utils.chatPanel.makeChat(page, 'Nice to meet you');
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
@ -458,7 +458,7 @@ test.describe('AIBasic/Chat', () => {
|
||||
await sendButton.click();
|
||||
|
||||
await expect(page.getByTestId('sidebar-tab-content-chat')).toBeVisible();
|
||||
expect(await page.locator('chat-content-images')).toBeVisible();
|
||||
await expect(page.locator('chat-content-images')).toBeVisible();
|
||||
await utils.chatPanel.waitForHistory(page, [
|
||||
{
|
||||
role: 'user',
|
||||
|
File diff suppressed because one or more lines are too long
@ -44,7 +44,7 @@ test.describe('AIInsertion/AddToEdgelessAsNote', () => {
|
||||
|
||||
// Delete default note
|
||||
await (await page.waitForSelector('affine-edgeless-note')).click();
|
||||
page.keyboard.press('Delete');
|
||||
await page.keyboard.press('Delete');
|
||||
|
||||
await utils.chatPanel.openChatPanel(page);
|
||||
await utils.chatPanel.makeChat(page, 'Hello');
|
||||
|
@ -170,7 +170,7 @@ test.describe('AIInsertion/Insert', () => {
|
||||
|
||||
// Delete default note
|
||||
await (await page.waitForSelector('affine-edgeless-note')).click();
|
||||
page.keyboard.press('Delete');
|
||||
await page.keyboard.press('Delete');
|
||||
|
||||
await utils.chatPanel.openChatPanel(page);
|
||||
await utils.chatPanel.makeChat(page, 'Hello');
|
||||
|
@ -30,6 +30,10 @@ export class ChatPanelUtils {
|
||||
await page.getByTestId('right-sidebar-toggle').click({
|
||||
delay: 200,
|
||||
});
|
||||
await page.waitForTimeout(500); // wait the sidebar stable
|
||||
}
|
||||
if (await page.getByTestId('notification-close-button').isVisible()) {
|
||||
await page.getByTestId('notification-close-button').click();
|
||||
}
|
||||
await page.getByTestId('sidebar-tab-chat').click();
|
||||
await expect(page.getByTestId('sidebar-tab-content-chat')).toBeVisible();
|
||||
@ -291,14 +295,14 @@ export class ChatPanelUtils {
|
||||
}
|
||||
|
||||
public static async enableNetworkSearch(page: Page) {
|
||||
const networkSearch = await page.getByTestId('chat-network-search');
|
||||
const networkSearch = page.getByTestId('chat-network-search');
|
||||
if ((await networkSearch.getAttribute('data-active')) === 'false') {
|
||||
await networkSearch.click();
|
||||
}
|
||||
}
|
||||
|
||||
public static async disableNetworkSearch(page: Page) {
|
||||
const networkSearch = await page.getByTestId('chat-network-search');
|
||||
const networkSearch = page.getByTestId('chat-network-search');
|
||||
if ((await networkSearch.getAttribute('data-active')) === 'true') {
|
||||
await networkSearch.click();
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ export class EditorUtils {
|
||||
public static async switchToEdgelessMode(page: Page) {
|
||||
const editor = await page.waitForSelector('page-editor');
|
||||
await page.getByTestId('switch-edgeless-mode-button').click();
|
||||
editor.waitForElementState('hidden');
|
||||
await editor.waitForElementState('hidden');
|
||||
await page.waitForSelector('edgeless-editor');
|
||||
try {
|
||||
const edgelessNotificationClose = page.getByTestId(
|
||||
@ -408,9 +408,7 @@ export class EditorUtils {
|
||||
checkCodeError: this.createAction(page, () =>
|
||||
page.getByTestId('action-check-code-error').click()
|
||||
),
|
||||
continueWithAi: async () => {
|
||||
page.getByTestId('action-continue-with-ai').click();
|
||||
},
|
||||
continueWithAi: () => page.getByTestId('action-continue-with-ai').click(),
|
||||
continueWriting: this.createAction(page, () =>
|
||||
page.getByTestId('action-continue-writing').click()
|
||||
),
|
||||
@ -596,9 +594,7 @@ export class EditorUtils {
|
||||
checkCodeError: this.createAction(page, () =>
|
||||
page.getByTestId('action-check-code-error').click()
|
||||
),
|
||||
continueWithAi: async () => {
|
||||
page.getByTestId('action-continue-with-ai').click();
|
||||
},
|
||||
continueWithAi: () => page.getByTestId('action-continue-with-ai').click(),
|
||||
continueWriting: this.createAction(page, () =>
|
||||
page.getByTestId('action-continue-writing').click()
|
||||
),
|
||||
|
@ -164,7 +164,7 @@ test('can sync svg between different browsers', async ({ page, browser }) => {
|
||||
const fileChooserPromise = page.waitForEvent('filechooser');
|
||||
await page.keyboard.press('Enter', { delay: 50 });
|
||||
const fileChooser = await fileChooserPromise;
|
||||
fileChooser.setFiles(Path.dir(import.meta.url).join('logo.svg').value);
|
||||
await fileChooser.setFiles(Path.dir(import.meta.url).join('logo.svg').value);
|
||||
await expect(image).toBeVisible();
|
||||
|
||||
// the user should see the svg
|
||||
|
@ -28,6 +28,6 @@ test('import from template should work', async ({ page }) => {
|
||||
const btn = page.getByTestId('import-template-to-workspace-btn');
|
||||
|
||||
await btn.isVisible();
|
||||
btn.click();
|
||||
await btn.click();
|
||||
await waitForEditorLoad(page);
|
||||
});
|
||||
|
@ -48,7 +48,7 @@ test.describe('split list', () => {
|
||||
listLocator.nth(2).locator('.affine-list-block__numbered')
|
||||
).toHaveText('2.');
|
||||
await expect(listLocator.nth(3).locator('rich-text')).toHaveText('ddd');
|
||||
expect(
|
||||
await expect(
|
||||
listLocator.nth(3).locator('.affine-list-block__numbered')
|
||||
).toHaveText('3.');
|
||||
|
||||
|
@ -137,15 +137,14 @@ test.skip('create multi workspace in the workspace list', async ({
|
||||
await expect(workspaceCards).toHaveCount(3);
|
||||
}
|
||||
|
||||
const workspaceChangePromise = page.evaluate(() => {
|
||||
new Promise(resolve => {
|
||||
await page.getByTestId('draggable-item').nth(2).click();
|
||||
await page.evaluate(async () => {
|
||||
await new Promise(resolve => {
|
||||
window.addEventListener('affine:workspace:change', resolve, {
|
||||
once: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
await page.getByTestId('draggable-item').nth(2).click();
|
||||
await workspaceChangePromise;
|
||||
|
||||
const nextWorkspace = await workspace.current();
|
||||
|
||||
|
@ -178,7 +178,7 @@ test('add mindmap into frame, then drag root node of mindmap out.', async ({
|
||||
// drag out
|
||||
{
|
||||
const mindmapBound = await getSelectedBound(page);
|
||||
pressEscape(page);
|
||||
await pressEscape(page);
|
||||
await clickView(page, [
|
||||
mindmapBound[0] + 10,
|
||||
mindmapBound[1] + 0.5 * mindmapBound[3],
|
||||
|
@ -290,8 +290,8 @@ test.describe('lock', () => {
|
||||
await selectAllByKeyboard(page);
|
||||
await dragBetweenViewCoords(page, [100, 100], [150, 150]);
|
||||
|
||||
assertEdgelessElementBound(page, frame, [100, 100, 200, 200]);
|
||||
assertEdgelessElementBound(page, shape, [150, 150, 50, 50]);
|
||||
await assertEdgelessElementBound(page, frame, [100, 100, 200, 200]);
|
||||
await assertEdgelessElementBound(page, shape, [150, 150, 50, 50]);
|
||||
});
|
||||
|
||||
test('locked element should not be scalable and rotatable. unlocking will recover', async ({
|
||||
|
@ -196,7 +196,7 @@ test.describe('Embed synced doc in edgeless mode', () => {
|
||||
await expect(edgelessNotes).toHaveCount(2);
|
||||
expect(await getSelectedIds(page)).toHaveLength(1);
|
||||
expect(await getSelectedIds(page)).not.toContain(prevIds);
|
||||
expect(edgelessNotes.last()).toBeVisible();
|
||||
await expect(edgelessNotes.last()).toBeVisible();
|
||||
|
||||
const noteBound = await getSelectedBound(page);
|
||||
expect(isIntersected(embedDocBound, noteBound)).toBe(false);
|
||||
|
@ -27,7 +27,7 @@ export async function initEmbedSyncedDocState(
|
||||
}
|
||||
|
||||
return await page.evaluate(
|
||||
({ data, option }) => {
|
||||
async ({ data, option }) => {
|
||||
const createDoc = async (
|
||||
docId: string,
|
||||
title: string,
|
||||
@ -69,11 +69,13 @@ export async function initEmbedSyncedDocState(
|
||||
return note ?? null;
|
||||
};
|
||||
|
||||
const docIds = data.map(({ title, content }, index) => {
|
||||
const id = index === 0 ? window.doc.id : `embed-doc-${index}`;
|
||||
createDoc(id, title, content);
|
||||
return id;
|
||||
});
|
||||
const docIds = await Promise.all(
|
||||
data.map(async ({ title, content }, index) => {
|
||||
const id = index === 0 ? window.doc.id : `embed-doc-${index}`;
|
||||
await createDoc(id, title, content);
|
||||
return id;
|
||||
})
|
||||
);
|
||||
|
||||
const { NoteBlockModel, NoteDisplayMode } =
|
||||
window.$blocksuite.affineModel;
|
||||
|
@ -473,7 +473,7 @@ export async function createEdgelessNoteBlock(
|
||||
) {
|
||||
await setEdgelessTool(page, 'note', undefined, editorIndex);
|
||||
if (position.length === 4) {
|
||||
dragView(
|
||||
await dragView(
|
||||
page,
|
||||
[position[0], position[1]],
|
||||
[position[0] + position[2], position[1] + position[3]]
|
||||
|
@ -122,7 +122,7 @@ export const addCustomProperty = async (
|
||||
root: Locator | Page,
|
||||
type: string
|
||||
) => {
|
||||
ensureAddPropertyButtonVisible(page, root);
|
||||
await ensureAddPropertyButtonVisible(page, root);
|
||||
await clickAddPropertyButton(root);
|
||||
await page
|
||||
.locator(
|
||||
|
Loading…
x
Reference in New Issue
Block a user