2023-12-19 10:17:54 +03:00
|
|
|
import { skipOnboarding, test } from '@affine-test/kit/playwright';
|
2023-09-02 09:06:47 +03:00
|
|
|
import {
|
|
|
|
addUserToWorkspace,
|
|
|
|
createRandomUser,
|
|
|
|
enableCloudWorkspace,
|
2023-10-12 06:26:13 +03:00
|
|
|
enableCloudWorkspaceFromShareButton,
|
2023-09-02 09:06:47 +03:00
|
|
|
loginUser,
|
|
|
|
} from '@affine-test/kit/utils/cloud';
|
2023-11-15 10:49:25 +03:00
|
|
|
import { clickEdgelessModeButton } from '@affine-test/kit/utils/editor';
|
2023-09-02 08:57:04 +03:00
|
|
|
import {
|
|
|
|
clickNewPageButton,
|
|
|
|
getBlockSuiteEditorTitle,
|
|
|
|
waitForEditorLoad,
|
|
|
|
} from '@affine-test/kit/utils/page-logic';
|
2023-12-06 11:03:05 +03:00
|
|
|
import { clickUserInfoCard } from '@affine-test/kit/utils/setting';
|
|
|
|
import { clickSideBarSettingButton } from '@affine-test/kit/utils/sidebar';
|
2023-09-02 08:57:04 +03:00
|
|
|
import { createLocalWorkspace } from '@affine-test/kit/utils/workspace';
|
|
|
|
import { expect } from '@playwright/test';
|
2023-12-06 13:15:03 +03:00
|
|
|
import { resolve } from 'path';
|
2023-09-02 08:57:04 +03:00
|
|
|
|
|
|
|
let user: {
|
2023-09-02 09:06:47 +03:00
|
|
|
id: string;
|
2023-09-02 08:57:04 +03:00
|
|
|
name: string;
|
|
|
|
email: string;
|
|
|
|
password: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
test.beforeEach(async () => {
|
|
|
|
user = await createRandomUser();
|
|
|
|
});
|
|
|
|
|
|
|
|
test.beforeEach(async ({ page }) => {
|
2023-09-02 09:06:47 +03:00
|
|
|
await loginUser(page, user.email);
|
2023-09-02 08:57:04 +03:00
|
|
|
});
|
|
|
|
|
2023-12-06 11:03:05 +03:00
|
|
|
test('can enable share page', async ({ page, browser }) => {
|
|
|
|
await page.reload();
|
|
|
|
await waitForEditorLoad(page);
|
|
|
|
await createLocalWorkspace(
|
2023-09-02 08:57:04 +03:00
|
|
|
{
|
2023-12-06 11:03:05 +03:00
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
page
|
|
|
|
);
|
|
|
|
await enableCloudWorkspaceFromShareButton(page);
|
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
|
|
|
await title.pressSequentially('TEST TITLE', {
|
|
|
|
delay: 50,
|
2023-09-02 08:57:04 +03:00
|
|
|
});
|
2023-12-06 11:03:05 +03:00
|
|
|
await page.keyboard.press('Enter', { delay: 50 });
|
|
|
|
await page.keyboard.type('TEST CONTENT', { delay: 50 });
|
|
|
|
await page.getByTestId('cloud-share-menu-button').click();
|
|
|
|
await page.getByTestId('share-menu-create-link-button').click();
|
|
|
|
await page.getByTestId('share-menu-copy-link-button').click();
|
|
|
|
|
|
|
|
// check share page is accessible
|
|
|
|
{
|
|
|
|
const context = await browser.newContext();
|
2023-12-19 10:17:54 +03:00
|
|
|
await skipOnboarding(context);
|
2023-12-06 11:03:05 +03:00
|
|
|
const url: string = await page.evaluate(() =>
|
|
|
|
navigator.clipboard.readText()
|
2023-11-15 10:49:25 +03:00
|
|
|
);
|
2023-12-06 11:03:05 +03:00
|
|
|
const page2 = await context.newPage();
|
|
|
|
await page2.goto(url);
|
|
|
|
await waitForEditorLoad(page2);
|
|
|
|
const title = getBlockSuiteEditorTitle(page2);
|
|
|
|
expect(await title.innerText()).toBe('TEST TITLE');
|
|
|
|
expect(await page2.textContent('affine-paragraph')).toContain(
|
|
|
|
'TEST CONTENT'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2023-11-15 10:49:25 +03:00
|
|
|
|
2023-12-06 11:03:05 +03:00
|
|
|
test('share page with default edgeless', async ({ page, browser }) => {
|
|
|
|
await page.reload();
|
|
|
|
await waitForEditorLoad(page);
|
|
|
|
await createLocalWorkspace(
|
2023-11-15 10:49:25 +03:00
|
|
|
{
|
2023-12-06 11:03:05 +03:00
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
page
|
|
|
|
);
|
|
|
|
await enableCloudWorkspaceFromShareButton(page);
|
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
|
|
|
await title.pressSequentially('TEST TITLE', {
|
|
|
|
delay: 50,
|
|
|
|
});
|
|
|
|
await page.keyboard.press('Enter', { delay: 50 });
|
|
|
|
await page.keyboard.type('TEST CONTENT', { delay: 50 });
|
|
|
|
await clickEdgelessModeButton(page);
|
|
|
|
await expect(page.locator('affine-edgeless-page')).toBeVisible({
|
|
|
|
timeout: 1000,
|
2023-11-15 10:49:25 +03:00
|
|
|
});
|
2023-12-06 11:03:05 +03:00
|
|
|
await page.getByTestId('cloud-share-menu-button').click();
|
|
|
|
await page.getByTestId('share-menu-create-link-button').click();
|
|
|
|
await page.getByTestId('share-menu-copy-link-button').click();
|
2023-11-15 10:49:25 +03:00
|
|
|
|
2023-12-06 11:03:05 +03:00
|
|
|
// check share page is accessible
|
|
|
|
{
|
2023-09-02 09:06:47 +03:00
|
|
|
const context = await browser.newContext();
|
2023-12-19 10:17:54 +03:00
|
|
|
await skipOnboarding(context);
|
2023-12-06 11:03:05 +03:00
|
|
|
const url: string = await page.evaluate(() =>
|
|
|
|
navigator.clipboard.readText()
|
|
|
|
);
|
2023-09-02 09:06:47 +03:00
|
|
|
const page2 = await context.newPage();
|
2023-12-06 11:03:05 +03:00
|
|
|
await page2.goto(url);
|
2023-09-02 09:06:47 +03:00
|
|
|
await waitForEditorLoad(page2);
|
2023-12-06 11:03:05 +03:00
|
|
|
await expect(page.locator('affine-edgeless-page')).toBeVisible({
|
|
|
|
timeout: 1000,
|
2023-09-07 08:02:21 +03:00
|
|
|
});
|
2023-12-06 11:03:05 +03:00
|
|
|
expect(await page2.textContent('affine-paragraph')).toContain(
|
|
|
|
'TEST CONTENT'
|
2023-09-09 01:02:22 +03:00
|
|
|
);
|
2023-12-06 11:03:05 +03:00
|
|
|
const logo = page2.getByTestId('share-page-logo');
|
|
|
|
const editButton = page2.getByTestId('share-page-edit-button');
|
|
|
|
await expect(editButton).not.toBeVisible();
|
|
|
|
await expect(logo).toBeVisible();
|
|
|
|
}
|
|
|
|
});
|
2023-09-09 01:02:22 +03:00
|
|
|
|
2023-12-06 11:03:05 +03:00
|
|
|
test('can collaborate with other user and name should display when editing', async ({
|
|
|
|
page,
|
|
|
|
browser,
|
|
|
|
}) => {
|
|
|
|
await page.reload();
|
|
|
|
await waitForEditorLoad(page);
|
|
|
|
await createLocalWorkspace(
|
2023-09-09 01:02:22 +03:00
|
|
|
{
|
2023-12-06 11:03:05 +03:00
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
page
|
|
|
|
);
|
|
|
|
await enableCloudWorkspace(page);
|
|
|
|
await clickNewPageButton(page);
|
|
|
|
const currentUrl = page.url();
|
|
|
|
// format: http://localhost:8080/workspace/${workspaceId}/xxx
|
|
|
|
const workspaceId = currentUrl.split('/')[4];
|
|
|
|
const userB = await createRandomUser();
|
|
|
|
const context = await browser.newContext();
|
2023-12-19 10:17:54 +03:00
|
|
|
await skipOnboarding(context);
|
2023-12-06 11:03:05 +03:00
|
|
|
const page2 = await context.newPage();
|
|
|
|
await loginUser(page2, userB.email);
|
|
|
|
await addUserToWorkspace(workspaceId, userB.id, 1 /* READ */);
|
|
|
|
await page2.reload();
|
|
|
|
await waitForEditorLoad(page2);
|
|
|
|
await page2.goto(currentUrl);
|
|
|
|
{
|
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
|
|
|
await title.pressSequentially('TEST TITLE', {
|
|
|
|
delay: 50,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
await page2.waitForTimeout(200);
|
|
|
|
{
|
|
|
|
const title = getBlockSuiteEditorTitle(page2);
|
|
|
|
expect(await title.innerText()).toBe('TEST TITLE');
|
2023-12-15 10:20:50 +03:00
|
|
|
const typingPromise = (async () => {
|
|
|
|
await page.keyboard.press('Enter', { delay: 50 });
|
|
|
|
await page.keyboard.type('TEST CONTENT', { delay: 50 });
|
|
|
|
})();
|
2023-12-06 11:03:05 +03:00
|
|
|
// username should be visible when editing
|
|
|
|
await expect(page2.getByText(user.name)).toBeVisible();
|
|
|
|
await typingPromise;
|
|
|
|
}
|
|
|
|
|
|
|
|
// change username
|
|
|
|
await clickSideBarSettingButton(page);
|
|
|
|
await clickUserInfoCard(page);
|
|
|
|
const input = page.getByTestId('user-name-input');
|
|
|
|
await input.clear();
|
|
|
|
await input.pressSequentially('TEST USER', {
|
|
|
|
delay: 50,
|
2023-09-09 01:02:22 +03:00
|
|
|
});
|
2023-12-06 11:03:05 +03:00
|
|
|
await page.getByTestId('save-user-name').click({
|
|
|
|
delay: 50,
|
2023-09-06 09:58:05 +03:00
|
|
|
});
|
2023-12-06 11:03:05 +03:00
|
|
|
await page.keyboard.press('Escape', {
|
|
|
|
delay: 50,
|
2023-09-12 06:37:59 +03:00
|
|
|
});
|
2023-12-06 11:03:05 +03:00
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
|
|
|
await title.focus();
|
|
|
|
|
|
|
|
{
|
|
|
|
await expect(page2.getByText('TEST USER')).toBeVisible({
|
|
|
|
timeout: 2000,
|
|
|
|
});
|
|
|
|
}
|
2023-09-12 06:37:59 +03:00
|
|
|
});
|
2023-10-16 11:44:09 +03:00
|
|
|
|
2023-12-06 11:03:05 +03:00
|
|
|
test('can sync collections between different browser', async ({
|
|
|
|
page,
|
|
|
|
browser,
|
|
|
|
}) => {
|
|
|
|
await page.reload();
|
|
|
|
await waitForEditorLoad(page);
|
|
|
|
await createLocalWorkspace(
|
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
page
|
|
|
|
);
|
|
|
|
await enableCloudWorkspace(page);
|
|
|
|
await page.getByTestId('slider-bar-add-collection-button').click();
|
|
|
|
const title = page.getByTestId('input-collection-title');
|
|
|
|
await title.isVisible();
|
|
|
|
await title.fill('test collection');
|
|
|
|
await page.getByTestId('save-collection').click();
|
|
|
|
|
|
|
|
{
|
|
|
|
const context = await browser.newContext();
|
2023-12-19 10:17:54 +03:00
|
|
|
await skipOnboarding(context);
|
2023-12-06 11:03:05 +03:00
|
|
|
const page2 = await context.newPage();
|
|
|
|
await loginUser(page2, user.email);
|
|
|
|
await page2.goto(page.url());
|
|
|
|
const collections = page2.getByTestId('collections');
|
|
|
|
await expect(collections.getByText('test collection')).toBeVisible();
|
|
|
|
}
|
2023-10-16 11:44:09 +03:00
|
|
|
});
|
2023-11-10 08:32:51 +03:00
|
|
|
|
|
|
|
test('can sync svg between different browsers', async ({ page, browser }) => {
|
|
|
|
await page.reload();
|
|
|
|
await waitForEditorLoad(page);
|
|
|
|
await createLocalWorkspace(
|
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
},
|
|
|
|
page
|
|
|
|
);
|
|
|
|
await enableCloudWorkspace(page);
|
|
|
|
await clickNewPageButton(page);
|
|
|
|
await waitForEditorLoad(page);
|
|
|
|
|
2023-12-06 13:15:03 +03:00
|
|
|
// upload local svg
|
2023-11-10 08:32:51 +03:00
|
|
|
|
2023-12-06 13:15:03 +03:00
|
|
|
const slashMenu = page.locator(`.slash-menu`);
|
|
|
|
const image = page.locator('affine-image');
|
|
|
|
|
|
|
|
page.evaluate(async () => {
|
|
|
|
window.showOpenFilePicker = undefined;
|
|
|
|
});
|
|
|
|
|
|
|
|
const title = getBlockSuiteEditorTitle(page);
|
|
|
|
await title.pressSequentially('TEST TITLE', {
|
|
|
|
delay: 50,
|
|
|
|
});
|
|
|
|
await page.keyboard.press('Enter', { delay: 50 });
|
|
|
|
await page.waitForTimeout(100);
|
|
|
|
await page.keyboard.type('/', { delay: 50 });
|
|
|
|
await expect(slashMenu).toBeVisible();
|
|
|
|
await page.keyboard.type('image', { delay: 100 });
|
|
|
|
await expect(slashMenu).toBeVisible();
|
|
|
|
await page.keyboard.press('Enter', { delay: 50 });
|
|
|
|
await page.setInputFiles(
|
|
|
|
"input[type='file']",
|
|
|
|
resolve(__dirname, 'logo.svg')
|
|
|
|
);
|
|
|
|
await expect(image).toBeVisible();
|
|
|
|
|
|
|
|
// the user should see the svg
|
|
|
|
// get the image src under "affine-image img"
|
|
|
|
const src1 = await page.locator('affine-image img').getAttribute('src');
|
|
|
|
expect(src1).not.toBeNull();
|
|
|
|
|
|
|
|
// fetch the actual src1 resource in the browser
|
|
|
|
const svg1 = await page.evaluate(
|
|
|
|
src =>
|
|
|
|
fetch(src!)
|
|
|
|
.then(res => res.blob())
|
|
|
|
.then(blob => blob.text()),
|
|
|
|
src1
|
|
|
|
);
|
2023-11-10 08:32:51 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
const context = await browser.newContext();
|
2023-12-19 10:17:54 +03:00
|
|
|
await skipOnboarding(context);
|
2023-11-10 08:32:51 +03:00
|
|
|
const page2 = await context.newPage();
|
|
|
|
await loginUser(page2, user.email);
|
|
|
|
await page2.goto(page.url());
|
|
|
|
|
2023-12-06 13:15:03 +03:00
|
|
|
// second user should see the svg
|
2023-11-10 08:32:51 +03:00
|
|
|
// get the image src under "affine-image img"
|
2023-12-06 13:15:03 +03:00
|
|
|
const src2 = await page2.locator('affine-image img').getAttribute('src');
|
|
|
|
expect(src2).not.toBeNull();
|
2023-11-10 08:32:51 +03:00
|
|
|
|
2023-12-06 13:15:03 +03:00
|
|
|
// fetch the actual src2 resource in the browser
|
|
|
|
const svg2 = await page2.evaluate(
|
|
|
|
src =>
|
|
|
|
fetch(src!)
|
|
|
|
.then(res => res.blob())
|
|
|
|
.then(blob => blob.text()),
|
|
|
|
src2
|
|
|
|
);
|
2023-11-10 08:32:51 +03:00
|
|
|
|
2023-12-06 13:15:03 +03:00
|
|
|
expect(svg2).toEqual(svg1);
|
2023-11-10 08:32:51 +03:00
|
|
|
}
|
|
|
|
});
|