refactor(core): onboarding using new transformer api (#5412)

Use new `transformer` to import onboarding json templates.

The json files are generated via this gist
https://gist.github.com/pengx17/ef92c305ac23123803a1a6a20e31f822

Not using the all-in-one `ZipTransformer` to import onboarding via a zip file.
1. The main concerns is that we still need to serve the blob resources via CDN to reduce user's blob usage. Otherwise the user will get the onboarding images being uploaded to cloud server every time he creates a new workspace. In this PR we extracted parts of the code from `ZipTransformer` in blocksuite and mute some code for uploading blobs.
2. it maybe not necessary to use zip for loading snapshots.

This PR is a short term solution. whether or not to tune the transformer api design may need further discussions.

fix TOV-264
This commit is contained in:
Peng Xiao
2023-12-28 13:59:21 +00:00
parent 954b751e7c
commit 3978b2dfd2
41 changed files with 23414 additions and 10325 deletions

View File

@@ -8,15 +8,12 @@ import {
clickDatePicker,
createFirstFilter,
createPageWithTag,
fillDatePicker,
getPagesCount,
selectDateFromDatePicker,
selectMonthFromMonthPicker,
selectTag,
} from '@affine-test/kit/utils/filter';
import { openHomePage } from '@affine-test/kit/utils/load-page';
import {
clickNewPageButton,
getBlockSuiteEditorTitle,
waitForAllPagesLoad,
waitForEditorLoad,
@@ -85,66 +82,6 @@ test('allow creation of filters by favorite', async ({ page }) => {
);
});
test('allow creation of filters by created time', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await clickNewPageButton(page);
await clickSideBarAllPageButton(page);
await waitForAllPagesLoad(page);
const pageCount = await getPagesCount(page);
expect(pageCount).not.toBe(0);
await createFirstFilter(page, 'Created');
await checkFilterName(page, 'after');
// init date
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
await checkDatePicker(page, yesterday);
expect(await getPagesCount(page)).toBe(1);
// change date
const today = new Date();
await fillDatePicker(page, today);
expect(await getPagesCount(page)).toBe(0);
// change filter
await page.getByTestId('filter-name').click();
await page.getByTestId('filler-tag-before').click();
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
await fillDatePicker(page, tomorrow);
await checkDatePicker(page, tomorrow);
expect(await getPagesCount(page)).toBe(pageCount);
});
test('creation of filters by created time, then click date picker to modify the date', async ({
page,
}) => {
await openHomePage(page);
await waitForEditorLoad(page);
await clickNewPageButton(page);
await clickSideBarAllPageButton(page);
await waitForAllPagesLoad(page);
const pageCount = await getPagesCount(page);
expect(pageCount).not.toBe(0);
await createFirstFilter(page, 'Created');
await checkFilterName(page, 'after');
// init date
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);
await checkDatePicker(page, yesterday);
expect(await getPagesCount(page)).toBe(1);
// change date
const today = new Date();
await selectDateFromDatePicker(page, today);
expect(await getPagesCount(page)).toBe(0);
// change filter
await page.locator('[data-testid="filter-name"]').click();
await page.getByTestId('filler-tag-before').click();
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
await selectDateFromDatePicker(page, tomorrow);
await checkDatePicker(page, tomorrow);
expect(await getPagesCount(page)).toBe(pageCount);
});
test('use monthpicker to modify the month of datepicker', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);

View File

@@ -13,21 +13,33 @@ import { createLocalWorkspace } from '@affine-test/kit/utils/workspace';
import type { Page } from '@playwright/test';
import { expect } from '@playwright/test';
const removeOnboardingPages = async (page: Page) => {
await page.getByTestId('all-pages').click();
await page.getByTestId('page-list-header-selection-checkbox').click();
// click again to select all
await page.getByTestId('page-list-header-selection-checkbox').click();
await page.getByTestId('page-list-toolbar-delete').click();
// confirm delete
await page.getByTestId('confirm-delete-page').click();
};
test.beforeEach(async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
});
const createAndPinCollection = async (
page: Page,
options?: {
collectionName?: string;
skipInitialPage?: boolean;
}
) => {
if (!options?.skipInitialPage) {
await openHomePage(page);
await waitForEditorLoad(page);
}
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('test page');
await page.getByTestId('all-pages').click();
const cell = page.getByTestId('page-list-item-title').getByText('test page');
await expect(cell).toBeVisible();
await page.getByTestId('create-first-filter').click({
@@ -50,6 +62,7 @@ const createAndPinCollection = async (
};
test('Show collections items in sidebar', async ({ page }) => {
await removeOnboardingPages(page);
await createAndPinCollection(page);
const collections = page.getByTestId('collections');
const items = collections.getByTestId('collection-item');
@@ -73,9 +86,7 @@ test('Show collections items in sidebar', async ({ page }) => {
await deleteCollection.click();
await page.waitForTimeout(50);
expect(await items.count()).toBe(0);
await createAndPinCollection(page, {
skipInitialPage: true,
});
await createAndPinCollection(page);
expect(await items.count()).toBe(1);
await clickSideBarAllPageButton(page);
await createLocalWorkspace(
@@ -91,6 +102,7 @@ test('Show collections items in sidebar', async ({ page }) => {
});
test('edit collection', async ({ page }) => {
await removeOnboardingPages(page);
await createAndPinCollection(page);
const collections = page.getByTestId('collections');
const items = collections.getByTestId('collection-item');
@@ -107,6 +119,7 @@ test('edit collection', async ({ page }) => {
});
test('edit collection and change filter date', async ({ page }) => {
await removeOnboardingPages(page);
await createAndPinCollection(page);
const collections = page.getByTestId('collections');
const items = collections.getByTestId('collection-item');
@@ -125,8 +138,6 @@ test('edit collection and change filter date', async ({ page }) => {
});
test('create temporary filter by click tag', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('test page');
@@ -148,8 +159,7 @@ test('create temporary filter by click tag', async ({ page }) => {
});
test('add collection from sidebar', async ({ page }) => {
await openHomePage(page);
await waitForEditorLoad(page);
await removeOnboardingPages(page);
await clickNewPageButton(page);
await getBlockSuiteEditorTitle(page).click();
await getBlockSuiteEditorTitle(page).fill('test page');