merge master

This commit is contained in:
tzhangchi
2023-01-03 21:57:33 +08:00
64 changed files with 2171 additions and 1652 deletions

View File

@@ -1,7 +1,11 @@
import { test } from '@playwright/test';
import type { Page } from '@playwright/test';
interface IType {
page: Page;
}
export function loadPage() {
test.beforeEach(async ({ page }) => {
test.beforeEach(async ({ page }: IType) => {
await page.goto('http://localhost:8080');
// waiting for page loading end
// await page.waitForTimeout(1000);

View File

@@ -1,8 +1,10 @@
export async function newPage(page) {
import type { Page } from '@playwright/test';
export async function newPage(page: Page) {
return page.getByTestId('sliderBar').getByText('New Page').click();
}
export async function clickPageMoreActions(page) {
export async function clickPageMoreActions(page: Page) {
return page
.getByTestId('editor-header-items')
.getByRole('button')

View File

@@ -24,21 +24,22 @@ test.describe('Login Flow', () => {
.click();
});
test('Open google firebase page', async ({ page }) => {
await page.getByTestId('current-workspace').click();
await page.waitForTimeout(800);
// why don't we use waitForSelector, It seems that waitForSelector not stable?
await page.getByTestId('open-login-modal').click();
await page.waitForTimeout(800);
const [firebasePage] = await Promise.all([
page.waitForEvent('popup'),
page
.getByRole('button', {
name: 'Google Continue with Google Set up an AFFiNE account to sync data',
})
.click(),
]);
// not stable
// test.skip('Open google firebase page', async ({ page }) => {
// await page.getByTestId('current-workspace').click();
// await page.waitForTimeout(800);
// // why don't we use waitForSelector, It seems that waitForSelector not stable?
// await page.getByTestId('open-login-modal').click();
// await page.waitForTimeout(800);
// const [firebasePage] = await Promise.all([
// page.waitForEvent('popup'),
// page
// .getByRole('button', {
// name: 'Google Continue with Google Set up an AFFiNE account to sync data',
// })
// .click(),
// ]);
expect(firebasePage.url()).toContain('.firebaseapp.com/__/auth/handler');
});
// expect(firebasePage.url()).toContain('.firebaseapp.com/__/auth/handler');
// });
});

View File

@@ -1,38 +1,26 @@
import { test, expect, type Page } from '@playwright/test';
import { loadPage } from './libs/load-page';
import { withCtrlOrMeta } from './libs/keyboard';
import { newPage } from './libs/page-logic';
loadPage();
const openQuickSearchByShortcut = async (page: Page) =>
await withCtrlOrMeta(page, () => page.keyboard.press('k', { delay: 50 }));
async function assertTitleTexts(
page: Page,
texts: string[],
option?: { delay: number }
) {
await page.mouse.move(100, 100);
async function assertTitleTexts(page: Page, texts: string[]) {
const actual = await page
.locator('[class=affine-default-page-block-title]')
.allInnerTexts();
await page.waitForTimeout(option?.delay || 0);
.locator('.affine-default-page-block-title')
.allTextContents();
expect(actual).toEqual(texts);
}
async function assertResultList(
page: Page,
texts: string[],
option?: { delay: number }
) {
await page.mouse.move(100, 100);
async function assertResultList(page: Page, texts: string[]) {
const actual = await page.locator('[cmdk-item]').allInnerTexts();
await page.waitForTimeout(option?.delay || 0);
expect(actual).toEqual(texts);
}
test.describe('Open quick search', () => {
test('Click slider bar button', async ({ page }) => {
await newPage(page);
const quickSearchButton = page.locator(
'[data-testid=sliderBar-quickSearchButton]'
);
@@ -42,7 +30,7 @@ test.describe('Open quick search', () => {
});
test('Click arrowDown icon after title', async ({ page }) => {
//header-quickSearchButton
await newPage(page);
const quickSearchButton = page.locator(
'[data-testid=header-quickSearchButton]'
);
@@ -51,58 +39,48 @@ test.describe('Open quick search', () => {
await expect(quickSearch).toBeVisible();
});
// test('Press the shortcut key cmd+k', async ({ page }) => {
// // why 1000ms page wait?
// page.waitForTimeout(1000);
// await openQuickSearchByShortcut(page);
// const quickSearch = page.locator('[data-testid=quickSearch]');
// await expect(quickSearch).toBeVisible();
// });
test('Press the shortcut key cmd+k', async ({ page }) => {
await newPage(page);
await openQuickSearchByShortcut(page);
const quickSearch = page.locator('[data-testid=quickSearch]');
await expect(quickSearch).toBeVisible();
});
});
test.describe('Add new page in quick search', () => {
// FIXME: not working
test.skip('Create a new page without keyword', async ({ page }) => {
test('Create a new page without keyword', async ({ page }) => {
await newPage(page);
await openQuickSearchByShortcut(page);
const addNewPage = page.locator('[data-testid=quickSearch-addNewPage]');
await addNewPage.click();
await assertTitleTexts(page, [''], { delay: 50 });
await page.waitForTimeout(200);
await assertTitleTexts(page, ['']);
});
test.skip('Create a new page with keyword', async ({ page }) => {
test('Create a new page with keyword', async ({ page }) => {
await newPage(page);
await openQuickSearchByShortcut(page);
await page.keyboard.insertText('test');
await page.keyboard.insertText('test123456');
const addNewPage = page.locator('[data-testid=quickSearch-addNewPage]');
await addNewPage.click();
await assertTitleTexts(page, ['test'], { delay: 50 });
await page.waitForTimeout(200);
await assertTitleTexts(page, ['test123456']);
});
});
test.describe('Search and select', () => {
// test('Search and get results', async ({ page }) => {
// // why 1000ms page wait?
// await openQuickSearchByShortcut(page);
// await page.keyboard.insertText('Welcome');
// await assertResultList(page, ['Welcome to the AFFiNE Alpha'], {
// delay: 50,
// });
// });
//TODO FIXME: This test is not working
test.skip('Create a new page and search this page', async ({ page }) => {
test('Create a new page and search this page', async ({ page }) => {
await newPage(page);
await openQuickSearchByShortcut(page);
await page.keyboard.insertText('Welcome');
await page.keyboard.insertText('test123456');
const addNewPage = page.locator('[data-testid=quickSearch-addNewPage]');
await addNewPage.click();
await page.waitForTimeout(500);
await page.waitForTimeout(200);
await openQuickSearchByShortcut(page);
await page.keyboard.insertText('Welcome');
await assertResultList(page, ['Welcome to the AFFiNE Alpha', 'Welcome']);
await page.keyboard.press('ArrowDown', { delay: 50 });
await page.keyboard.insertText('test123456');
await assertResultList(page, ['test123456']);
await page.keyboard.press('Enter', { delay: 50 });
await assertTitleTexts(page, ['Welcome'], {
delay: 50,
});
await assertTitleTexts(page, ['test123456']);
});
});