2023-09-06 10:44:53 +03:00
|
|
|
import { readFile } from 'node:fs/promises';
|
|
|
|
import { resolve } from 'node:path';
|
|
|
|
|
2023-08-29 13:07:05 +03:00
|
|
|
import { test } from '@affine-test/kit/playwright';
|
|
|
|
import {
|
|
|
|
createRandomUser,
|
|
|
|
deleteUser,
|
2023-09-06 10:44:53 +03:00
|
|
|
enableCloudWorkspace,
|
2023-08-29 13:07:05 +03:00
|
|
|
getLoginCookie,
|
2023-08-30 00:30:59 +03:00
|
|
|
loginUser,
|
2023-09-06 10:44:53 +03:00
|
|
|
runPrisma,
|
2023-08-29 13:07:05 +03:00
|
|
|
} from '@affine-test/kit/utils/cloud';
|
2023-09-06 10:44:53 +03:00
|
|
|
import { clickEdgelessModeButton } from '@affine-test/kit/utils/editor';
|
|
|
|
import { coreUrl } from '@affine-test/kit/utils/load-page';
|
|
|
|
import {
|
|
|
|
clickNewPageButton,
|
|
|
|
waitForEditorLoad,
|
|
|
|
} from '@affine-test/kit/utils/page-logic';
|
2023-09-02 08:11:10 +03:00
|
|
|
import { clickSideBarSettingButton } from '@affine-test/kit/utils/sidebar';
|
2023-09-06 10:44:53 +03:00
|
|
|
import { createLocalWorkspace } from '@affine-test/kit/utils/workspace';
|
2023-08-29 13:07:05 +03:00
|
|
|
import { expect } from '@playwright/test';
|
|
|
|
|
|
|
|
let user: {
|
2023-09-06 10:44:53 +03:00
|
|
|
id: string;
|
2023-08-29 13:07:05 +03:00
|
|
|
name: string;
|
|
|
|
email: string;
|
|
|
|
password: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
test.beforeEach(async () => {
|
|
|
|
user = await createRandomUser();
|
|
|
|
});
|
|
|
|
|
2023-09-02 08:11:10 +03:00
|
|
|
test.beforeEach(async ({ page, context }) => {
|
2023-09-02 09:06:47 +03:00
|
|
|
await loginUser(page, user.email, {
|
2023-08-30 00:30:59 +03:00
|
|
|
beforeLogin: async () => {
|
|
|
|
expect(await getLoginCookie(context)).toBeUndefined();
|
|
|
|
},
|
|
|
|
afterLogin: async () => {
|
|
|
|
expect(await getLoginCookie(context)).toBeTruthy();
|
|
|
|
await page.reload();
|
2023-09-02 06:31:07 +03:00
|
|
|
await waitForEditorLoad(page);
|
2023-08-30 00:30:59 +03:00
|
|
|
expect(await getLoginCookie(context)).toBeTruthy();
|
|
|
|
},
|
2023-08-29 13:07:05 +03:00
|
|
|
});
|
|
|
|
});
|
2023-09-02 08:11:10 +03:00
|
|
|
|
|
|
|
test.afterEach(async () => {
|
|
|
|
// if you want to keep the user in the database for debugging,
|
|
|
|
// comment this line
|
|
|
|
await deleteUser(user.email);
|
|
|
|
});
|
|
|
|
|
|
|
|
test.describe('basic', () => {
|
2023-09-06 10:44:53 +03:00
|
|
|
test('migration', async ({ page, browser }) => {
|
|
|
|
let workspaceId: string;
|
|
|
|
{
|
|
|
|
// create the old cloud workspace in another browser
|
|
|
|
const context = await browser.newContext();
|
|
|
|
const page = await context.newPage();
|
|
|
|
await loginUser(page, user.email);
|
|
|
|
await page.reload();
|
|
|
|
await createLocalWorkspace(
|
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
page
|
|
|
|
);
|
|
|
|
await enableCloudWorkspace(page);
|
|
|
|
await clickNewPageButton(page);
|
|
|
|
await waitForEditorLoad(page);
|
|
|
|
// http://localhost:8080/workspace/2bc0b6c8-f68d-4dd3-98a8-be746754f9e1/xxx
|
|
|
|
workspaceId = page.url().split('/')[4];
|
|
|
|
await runPrisma(async client => {
|
|
|
|
const sqls = (
|
|
|
|
await readFile(
|
|
|
|
resolve(__dirname, 'fixtures', '0.9.0-canary.9-snapshots.sql'),
|
|
|
|
'utf-8'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.replaceAll('2bc0b6c8-f68d-4dd3-98a8-be746754f9e1', workspaceId)
|
|
|
|
.split('\n');
|
|
|
|
await client.snapshot.deleteMany({
|
|
|
|
where: {
|
|
|
|
workspaceId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
for (const sql of sqls) {
|
|
|
|
await client.$executeRawUnsafe(sql);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
await page.close();
|
|
|
|
}
|
|
|
|
await page.reload();
|
|
|
|
await page.waitForTimeout(1000);
|
|
|
|
await page.goto(`${coreUrl}/workspace/${workspaceId}/all`);
|
|
|
|
await page.getByTestId('upgrade-workspace').click();
|
|
|
|
await expect(page.getByText('Done, please refresh the page.')).toBeVisible({
|
|
|
|
timeout: 60000,
|
|
|
|
});
|
|
|
|
await page.goto(
|
2023-09-07 01:38:11 +03:00
|
|
|
// page 'F1SX6cgNxy' has edgeless mode
|
|
|
|
`${coreUrl}/workspace/${workspaceId}/F1SX6cgNxy`
|
2023-09-06 10:44:53 +03:00
|
|
|
);
|
|
|
|
await waitForEditorLoad(page);
|
|
|
|
await clickEdgelessModeButton(page);
|
|
|
|
await expect(page.locator('affine-edgeless-page')).toBeVisible({
|
|
|
|
timeout: 1000,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-09-02 08:11:10 +03:00
|
|
|
test('can see and change email and password in setting panel', async ({
|
|
|
|
page,
|
|
|
|
}) => {
|
|
|
|
const newName = 'test name';
|
|
|
|
{
|
|
|
|
await clickSideBarSettingButton(page);
|
|
|
|
const locator = page.getByTestId('user-info-card');
|
|
|
|
expect(locator.getByText(user.email)).toBeTruthy();
|
|
|
|
expect(locator.getByText(user.name)).toBeTruthy();
|
|
|
|
await locator.click({
|
|
|
|
delay: 50,
|
|
|
|
});
|
|
|
|
const nameInput = page.getByPlaceholder('Input account name');
|
|
|
|
await nameInput.clear();
|
|
|
|
await nameInput.type(newName, {
|
|
|
|
delay: 50,
|
|
|
|
});
|
|
|
|
await page.getByTestId('save-user-name').click({
|
|
|
|
delay: 50,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
await page.reload();
|
|
|
|
{
|
|
|
|
await clickSideBarSettingButton(page);
|
|
|
|
const locator = page.getByTestId('user-info-card');
|
|
|
|
expect(locator.getByText(user.email)).toBeTruthy();
|
|
|
|
expect(locator.getByText(newName)).toBeTruthy();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|