refactor: workspace loading logic (#1966)

This commit is contained in:
Himself65
2023-04-16 16:02:41 -05:00
committed by GitHub
parent caa292e097
commit 7bbe67af43
88 changed files with 2684 additions and 2268 deletions

View File

@@ -8,34 +8,32 @@ import {
} from '../../libs/sidebar';
import { getBuiltInUser, loginUser, openHomePage } from '../../libs/utils';
test.describe('affine built in workspace', () => {
test('collaborative', async ({ page, browser }) => {
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 context2 = await browser.newContext();
const page2 = await context2.newPage();
await openHomePage(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.focus('.affine-default-page-block-title');
await page.type('.affine-default-page-block-title', 'hello', {
delay: 100,
});
await page.waitForTimeout(100);
const title = (await page
.locator('.affine-default-page-block-title')
.textContent()) as string;
expect(title.trim()).toBe('hello');
test('collaborative', async ({ page, browser }) => {
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 context2 = await browser.newContext();
const page2 = await context2.newPage();
await openHomePage(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.focus('.affine-default-page-block-title');
await page.type('.affine-default-page-block-title', 'hello', {
delay: 100,
});
await page.waitForTimeout(100);
const title = (await page
.locator('.affine-default-page-block-title')
.textContent()) as string;
expect(title.trim()).toBe('hello');
});

View File

@@ -6,62 +6,56 @@ import { clickNewPageButton } from '../../libs/sidebar';
import { createFakeUser, loginUser, openHomePage } from '../../libs/utils';
import { createWorkspace } from '../../libs/workspace';
test.describe('affine single page', () => {
test('public single page', async ({ page, browser }) => {
// when enable single page, most time the page will crash
test.fail();
await openHomePage(page);
const [a] = await createFakeUser();
await loginUser(page, a);
await waitMarkdownImported(page);
const name = `test-${Date.now()}`;
await createWorkspace({ name }, page);
await waitMarkdownImported(page);
await clickNewPageButton(page);
const page1Id = page.url().split('/').at(-1);
await clickNewPageButton(page);
const page2Id = page.url().split('/').at(-1);
expect(typeof page2Id).toBe('string');
expect(page1Id).not.toBe(page2Id);
const title = 'This is page 2';
await page.locator('[data-block-is-title="true"]').type(title, {
delay: 50,
});
await page.getByTestId('share-menu-button').click();
await page.getByTestId('share-menu-enable-affine-cloud-button').click();
const promise = page.evaluate(
async () =>
new Promise(resolve =>
window.addEventListener('affine-workspace:transform', resolve, {
once: true,
})
)
);
await page.getByTestId('confirm-enable-cloud-button').click();
await promise;
const newPage2Url = page.url().split('/');
newPage2Url[newPage2Url.length - 1] = page2Id as string;
await page.goto(newPage2Url.join('/'));
await page.waitForSelector('v-line');
const currentTitle = await page
.locator('[data-block-is-title="true"]')
.textContent();
expect(currentTitle).toBe(title);
await page.getByTestId('share-menu-button').click();
await page.getByTestId('affine-share-create-link').click();
await page.getByTestId('affine-share-copy-link').click();
const url = await page.evaluate(() => navigator.clipboard.readText());
expect(url.startsWith('http://localhost:8080/public-workspace/')).toBe(
true
);
await page.waitForTimeout(1000);
const context2 = await browser.newContext();
const page2 = await context2.newPage();
await page2.goto(url);
await page2.waitForSelector('v-line');
const currentTitle2 = await page2
.locator('[data-block-is-title="true"]')
.textContent();
expect(currentTitle2).toBe(title);
test('public single page', async ({ page, browser }) => {
await openHomePage(page);
const [a] = await createFakeUser();
await loginUser(page, a);
await waitMarkdownImported(page);
const name = `test-${Date.now()}`;
await createWorkspace({ name }, page);
await waitMarkdownImported(page);
await clickNewPageButton(page);
const page1Id = page.url().split('/').at(-1);
await clickNewPageButton(page);
const page2Id = page.url().split('/').at(-1);
expect(typeof page2Id).toBe('string');
expect(page1Id).not.toBe(page2Id);
const title = 'This is page 2';
await page.locator('[data-block-is-title="true"]').type(title, {
delay: 50,
});
await page.getByTestId('share-menu-button').click();
await page.getByTestId('share-menu-enable-affine-cloud-button').click();
const promise = page.evaluate(
async () =>
new Promise(resolve =>
window.addEventListener('affine-workspace:transform', resolve, {
once: true,
})
)
);
await page.getByTestId('confirm-enable-cloud-button').click();
await promise;
const newPage2Url = page.url().split('/');
newPage2Url[newPage2Url.length - 1] = page2Id as string;
await page.goto(newPage2Url.join('/'));
await page.waitForSelector('v-line');
const currentTitle = await page
.locator('[data-block-is-title="true"]')
.textContent();
expect(currentTitle).toBe(title);
await page.getByTestId('share-menu-button').click();
await page.getByTestId('affine-share-create-link').click();
await page.getByTestId('affine-share-copy-link').click();
const url = await page.evaluate(() => navigator.clipboard.readText());
expect(url.startsWith('http://localhost:8080/public-workspace/')).toBe(true);
await page.waitForTimeout(1000);
const context2 = await browser.newContext();
const page2 = await context2.newPage();
await page2.goto(url);
await page2.waitForSelector('v-line');
const currentTitle2 = await page2
.locator('[data-block-is-title="true"]')
.textContent();
expect(currentTitle2).toBe(title);
});

View File

@@ -10,65 +10,61 @@ import {
import { createFakeUser, loginUser, openHomePage } from '../../libs/utils';
import { createWorkspace } from '../../libs/workspace';
test.describe('affine public workspace', () => {
test('enable public workspace', async ({ page, context }) => {
await openHomePage(page);
const [a] = await createFakeUser();
await loginUser(page, a);
await waitMarkdownImported(page);
const name = `test-${Date.now()}`;
await createWorkspace({ name }, page);
await waitMarkdownImported(page);
await clickSideBarSettingButton(page);
await page.waitForTimeout(50);
await clickPublishPanel(page);
await page.getByTestId('publish-enable-affine-cloud-button').click();
await page.getByTestId('confirm-enable-affine-cloud-button').click();
await page.getByTestId('publish-to-web-button').waitFor({
timeout: 10000,
});
await page.getByTestId('publish-to-web-button').click();
await page.getByTestId('share-url').waitFor({
timeout: 10000,
});
const url = await page.getByTestId('share-url').inputValue();
expect(url.startsWith('http://localhost:8080/public-workspace/')).toBe(
true
);
const page2 = await context.newPage();
await page2.goto(url);
await page2.waitForSelector('thead', {
timeout: 10000,
});
await page2.getByText('Welcome to AFFiNE').click();
test('enable public workspace', async ({ page, context }) => {
await openHomePage(page);
const [a] = await createFakeUser();
await loginUser(page, a);
await waitMarkdownImported(page);
const name = `test-${Date.now()}`;
await createWorkspace({ name }, page);
await waitMarkdownImported(page);
await clickSideBarSettingButton(page);
await page.waitForTimeout(50);
await clickPublishPanel(page);
await page.getByTestId('publish-enable-affine-cloud-button').click();
await page.getByTestId('confirm-enable-affine-cloud-button').click();
await page.getByTestId('publish-to-web-button').waitFor({
timeout: 10000,
});
test('access public workspace page', async ({ page, browser }) => {
await openHomePage(page);
const [a] = await createFakeUser();
await loginUser(page, a);
await waitMarkdownImported(page);
const name = `test-${Date.now()}`;
await createWorkspace({ name }, page);
await waitMarkdownImported(page);
await clickSideBarSettingButton(page);
await page.waitForTimeout(50);
await clickPublishPanel(page);
await page.getByTestId('publish-enable-affine-cloud-button').click();
await page.getByTestId('confirm-enable-affine-cloud-button').click();
await page.getByTestId('publish-to-web-button').waitFor({
timeout: 10000,
});
await page.getByTestId('publish-to-web-button').click();
await page.getByTestId('share-url').waitFor({
timeout: 10000,
});
await clickSideBarAllPageButton(page);
await page.locator('tr').nth(1).click();
const url = page.url();
const context = await browser.newContext();
const page2 = await context.newPage();
await page2.goto(url.replace('workspace', 'public-workspace'));
await page2.waitForSelector('v-line');
await page.getByTestId('publish-to-web-button').click();
await page.getByTestId('share-url').waitFor({
timeout: 10000,
});
const url = await page.getByTestId('share-url').inputValue();
expect(url.startsWith('http://localhost:8080/public-workspace/')).toBe(true);
const page2 = await context.newPage();
await page2.goto(url);
await page2.waitForSelector('thead', {
timeout: 10000,
});
await page2.getByText('Welcome to AFFiNE').click();
});
test('access public workspace page', async ({ page, browser }) => {
await openHomePage(page);
const [a] = await createFakeUser();
await loginUser(page, a);
await waitMarkdownImported(page);
const name = `test-${Date.now()}`;
await createWorkspace({ name }, page);
await waitMarkdownImported(page);
await clickSideBarSettingButton(page);
await page.waitForTimeout(50);
await clickPublishPanel(page);
await page.getByTestId('publish-enable-affine-cloud-button').click();
await page.getByTestId('confirm-enable-affine-cloud-button').click();
await page.getByTestId('publish-to-web-button').waitFor({
timeout: 10000,
});
await page.getByTestId('publish-to-web-button').click();
await page.getByTestId('share-url').waitFor({
timeout: 10000,
});
await clickSideBarAllPageButton(page);
await page.locator('tr').nth(1).click();
const url = page.url();
const context = await browser.newContext();
const page2 = await context.newPage();
await page2.goto(url.replace('workspace', 'public-workspace'));
await page2.waitForSelector('v-line');
});

View File

@@ -21,44 +21,42 @@ import {
openWorkspaceListModal,
} from '../../libs/workspace';
test.describe('affine workspace', () => {
test('should login with user A', async ({ page }) => {
await openHomePage(page);
await waitMarkdownImported(page);
const [a] = await createFakeUser(userA, userB);
await loginUser(page, a);
await clickSideBarCurrentWorkspaceBanner(page);
const footer = page.locator('[data-testid="workspace-list-modal-footer"]');
expect(await footer.getByText(userA.name).isVisible()).toBe(true);
expect(await footer.getByText(userA.email).isVisible()).toBe(true);
await assertCurrentWorkspaceFlavour('local', page);
});
test('should enable affine workspace successfully', async ({ page }) => {
await openHomePage(page);
await waitMarkdownImported(page);
const [a] = await createFakeUser();
await loginUser(page, a);
const name = `test-${Date.now()}`;
await createWorkspace({ name }, page);
await page.waitForTimeout(50);
await clickSideBarSettingButton(page);
await page.waitForTimeout(50);
await clickCollaborationPanel(page);
await page.getByTestId('local-workspace-enable-cloud-button').click();
await page.getByTestId('confirm-enable-cloud-button').click();
await page.waitForSelector("[data-testid='member-length']", {
timeout: 20000,
});
await clickSideBarAllPageButton(page);
await clickNewPageButton(page);
await page.locator('[data-block-is-title="true"]').type('Hello, world!', {
delay: 50,
});
await assertCurrentWorkspaceFlavour('affine', page);
await openWorkspaceListModal(page);
await page.getByTestId('workspace-list-modal-sign-out').click();
await page.waitForTimeout(1000);
await assertCurrentWorkspaceFlavour('local', page);
});
test('should login with user A', async ({ page }) => {
await openHomePage(page);
await waitMarkdownImported(page);
const [a] = await createFakeUser(userA, userB);
await loginUser(page, a);
await clickSideBarCurrentWorkspaceBanner(page);
const footer = page.locator('[data-testid="workspace-list-modal-footer"]');
expect(await footer.getByText(userA.name).isVisible()).toBe(true);
expect(await footer.getByText(userA.email).isVisible()).toBe(true);
await assertCurrentWorkspaceFlavour('local', page);
});
test('should enable affine workspace successfully', async ({ page }) => {
await openHomePage(page);
await waitMarkdownImported(page);
const [a] = await createFakeUser();
await loginUser(page, a);
const name = `test-${Date.now()}`;
await createWorkspace({ name }, page);
await page.waitForTimeout(50);
await clickSideBarSettingButton(page);
await page.waitForTimeout(50);
await clickCollaborationPanel(page);
await page.getByTestId('local-workspace-enable-cloud-button').click();
await page.getByTestId('confirm-enable-cloud-button').click();
await page.waitForSelector("[data-testid='member-length']", {
timeout: 20000,
});
await clickSideBarAllPageButton(page);
await clickNewPageButton(page);
await page.locator('[data-block-is-title="true"]').type('Hello, world!', {
delay: 50,
});
await assertCurrentWorkspaceFlavour('affine', page);
await openWorkspaceListModal(page);
await page.getByTestId('workspace-list-modal-sign-out').click();
await page.waitForTimeout(1000);
await assertCurrentWorkspaceFlavour('local', page);
});