Skip to content

Commit

Permalink
test(editor): remove jsx snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
Saul-Mirone committed Dec 31, 2024
1 parent 597b631 commit 7d9a79d
Show file tree
Hide file tree
Showing 46 changed files with 2,653 additions and 1,145 deletions.
444 changes: 41 additions & 403 deletions blocksuite/tests-legacy/attachment.spec.ts

Large diffs are not rendered by default.

107 changes: 10 additions & 97 deletions blocksuite/tests-legacy/clipboard/list.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect } from '@playwright/test';
import type { BlockSnapshot } from '@store/index.js';
import { lightThemeV2 } from '@toeverything/theme/v2';

import { initDatabaseColumn } from '../database/actions.js';
Expand Down Expand Up @@ -53,7 +54,6 @@ import {
assertExists,
assertRichTextModelType,
assertRichTexts,
assertStoreMatchJSX,
assertText,
} from '../utils/asserts.js';
import { scoped, test } from '../utils/playwright.js';
Expand Down Expand Up @@ -437,104 +437,17 @@ test(scoped`should copy and paste of database work`, async ({ page }) => {
await pasteByKeyboard(page);
await page.waitForTimeout(100);

await assertStoreMatchJSX(
page,
/*xml*/ `
<affine:page>
<affine:note
prop:background={
Object {
"dark": "#000000",
"light": "#ffffff",
}
}
prop:displayMode="both"
prop:edgeless={
Object {
"style": Object {
"borderRadius": 8,
"borderSize": 4,
"borderStyle": "none",
"shadowType": "--affine-note-shadow-box",
},
}
}
prop:hidden={false}
prop:index="a0"
prop:lockedBySelf={false}
>
<affine:database
prop:columns="Array [2]"
prop:title="Database 1"
prop:views="Array [1]"
>
<affine:paragraph
prop:collapsed={false}
prop:type="text"
/>
</affine:database>
<affine:database
prop:columns="Array [2]"
prop:title="Database 1"
prop:views="Array [1]"
>
<affine:paragraph
prop:collapsed={false}
prop:type="text"
/>
</affine:database>
<affine:paragraph
prop:collapsed={false}
prop:type="text"
/>
</affine:note>
</affine:page>`
);
let pageJson = await getPageSnapshot(page, false);
let note = (pageJson as BlockSnapshot).children[0];
const database = note.children[0];
expect(database.flavour).toBe('affine:database');

await undoByKeyboard(page);
await assertStoreMatchJSX(
page,
/*xml*/ `
<affine:page>
<affine:note
prop:background={
Object {
"dark": "#000000",
"light": "#ffffff",
}
}
prop:displayMode="both"
prop:edgeless={
Object {
"style": Object {
"borderRadius": 8,
"borderSize": 4,
"borderStyle": "none",
"shadowType": "--affine-note-shadow-box",
},
}
}
prop:hidden={false}
prop:index="a0"
prop:lockedBySelf={false}
>
<affine:database
prop:columns="Array [2]"
prop:title="Database 1"
prop:views="Array [1]"
>
<affine:paragraph
prop:collapsed={false}
prop:type="text"
/>
</affine:database>
<affine:paragraph
prop:collapsed={false}
prop:type="text"
/>
</affine:note>
</affine:page>`
);

pageJson = await getPageSnapshot(page, false);
note = (pageJson as BlockSnapshot).children[0];
const db = note.children.find(child => child.flavour === 'affine:database');
expect(db).toBeDefined();
});

test(`copy canvas element and text note in edgeless mode`, async ({ page }) => {
Expand Down
116 changes: 26 additions & 90 deletions blocksuite/tests-legacy/code/crud.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
import {
assertBlockCount,
assertRichTexts,
assertStoreMatchJSX,
assertTitle,
} from '../utils/asserts.js';
import { test } from '../utils/playwright.js';
Expand Down Expand Up @@ -150,9 +149,9 @@ test('use shortcut can create code block', async ({ page }) => {
await expect(locator).toBeVisible();
});

test('change code language can work', async ({ page }) => {
test('change code language can work', async ({ page }, testInfo) => {
await enterPlaygroundRoom(page);
const { codeBlockId } = await initEmptyCodeBlockState(page);
await initEmptyCodeBlockState(page);
await focusRichText(page);

const codeBlockController = getCodeBlock(page);
Expand All @@ -170,26 +169,12 @@ test('change code language can work', async ({ page }) => {
await codeBlockController.codeBlock.hover();
await expect(codeBlockController.languageButton).toHaveText('Rust');

await assertStoreMatchJSX(
page,
/*xml*/ `
<affine:code
prop:caption=""
prop:language="rust"
prop:wrap={false}
/>`,
codeBlockId
expect(await getPageSnapshot(page, true)).toMatchSnapshot(
`${testInfo.title}_1.json`
);
await undoByKeyboard(page);
await assertStoreMatchJSX(
page,
/*xml*/ `
<affine:code
prop:caption=""
prop:language={null}
prop:wrap={false}
/>`,
codeBlockId
expect(await getPageSnapshot(page, true)).toMatchSnapshot(
`${testInfo.title}_2.json`
);

// Can switch to another language
Expand Down Expand Up @@ -273,54 +258,33 @@ test('undo and redo works in code block', async ({ page }) => {
await assertRichTexts(page, ['const a = 10;']);
});

test('toggle code block wrap can work', async ({ page }) => {
test('toggle code block wrap can work', async ({ page }, testInfo) => {
await enterPlaygroundRoom(page);
const { codeBlockId } = await initEmptyCodeBlockState(page);
await initEmptyCodeBlockState(page);

const codeBlockController = getCodeBlock(page);
await assertStoreMatchJSX(
page,
/*xml*/ `
<affine:code
prop:caption=""
prop:language={null}
prop:wrap={false}
/>`,
codeBlockId
expect(await getPageSnapshot(page, true)).toMatchSnapshot(
`${testInfo.title}_1.json`
);

await codeBlockController.codeBlock.hover();
await (await codeBlockController.openMore()).wrapButton.click();

await assertStoreMatchJSX(
page,
/*xml*/ `
<affine:code
prop:caption=""
prop:language={null}
prop:wrap={true}
/>`,
codeBlockId
expect(await getPageSnapshot(page, true)).toMatchSnapshot(
`${testInfo.title}_2.json`
);

await codeBlockController.codeBlock.hover();
await (await codeBlockController.openMore()).cancelWrapButton.click();

await assertStoreMatchJSX(
page,
/*xml*/ `
<affine:code
prop:caption=""
prop:language={null}
prop:wrap={false}
/>`,
codeBlockId
expect(await getPageSnapshot(page, true)).toMatchSnapshot(
`${testInfo.title}_3.json`
);
});

test('add caption works', async ({ page }) => {
test('add caption works', async ({ page }, testInfo) => {
await enterPlaygroundRoom(page);
const { codeBlockId } = await initEmptyCodeBlockState(page);
await initEmptyCodeBlockState(page);

const codeBlockController = getCodeBlock(page);
await codeBlockController.codeBlock.hover();
Expand All @@ -329,59 +293,31 @@ test('add caption works', async ({ page }) => {
await pressEnter(page);
await waitNextFrame(page, 100);

await assertStoreMatchJSX(
page,
/*xml*/ `
<affine:code
prop:caption="BlockSuite"
prop:language={null}
prop:wrap={false}
/>`,
codeBlockId
expect(await getPageSnapshot(page, true)).toMatchSnapshot(
`${testInfo.title}.json`
);
});

test('undo code block wrap can work', async ({ page }) => {
test('undo code block wrap can work', async ({ page }, testInfo) => {
await enterPlaygroundRoom(page);
const { codeBlockId } = await initEmptyCodeBlockState(page);
await initEmptyCodeBlockState(page);
await focusRichText(page);

const codeBlockController = getCodeBlock(page);
await assertStoreMatchJSX(
page,
/*xml*/ `
<affine:code
prop:caption=""
prop:language={null}
prop:wrap={false}
/>`,
codeBlockId
expect(await getPageSnapshot(page, true)).toMatchSnapshot(
`${testInfo.title}_1.json`
);

await codeBlockController.codeBlock.hover();
await (await codeBlockController.openMore()).wrapButton.click();
await assertStoreMatchJSX(
page,
/*xml*/ `
<affine:code
prop:caption=""
prop:language={null}
prop:wrap={true}
/>`,
codeBlockId
expect(await getPageSnapshot(page, true)).toMatchSnapshot(
`${testInfo.title}_2.json`
);

await focusRichText(page);
await undoByKeyboard(page);
await assertStoreMatchJSX(
page,
/*xml*/ `
<affine:code
prop:caption=""
prop:language={null}
prop:wrap={false}
/>`,
codeBlockId
expect(await getPageSnapshot(page, true)).toMatchSnapshot(
`${testInfo.title}_3.json`
);
});

Expand Down
Loading

0 comments on commit 7d9a79d

Please sign in to comment.