test: add e2e (#4121)

* test: connecting two blocks connected by a foreign key

* test: save as template, then delete it
This commit is contained in:
Zeke Zhang 2024-04-21 22:24:00 +08:00 committed by GitHub
parent 451bcca06f
commit 03cf42db9b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 416 additions and 2 deletions

View File

@ -11,7 +11,7 @@ import {
twoTableWithAssociationFields,
twoTableWithSameCollection,
} from '@nocobase/test/e2e';
import { T3843, T4032, oneTableWithRoles } from './templatesOfBug';
import { T3843, T4032, oneTableWithRoles, twoTableWithAuthorAndBooks } from './templatesOfBug';
test.describe('table block schema settings', () => {
test('supported options', async ({ page, mockPage }) => {
@ -305,7 +305,29 @@ test.describe('table block schema settings', () => {
await expect(page.getByLabel('block-item-CardItem-users-table').getByRole('row', { name: 'Root' })).toBeVisible();
});
test('connecting two blocks connected by a foreign key', async ({ page, mockPage, mockRecords }) => {});
test('connecting two blocks connected by a foreign key', async ({ page, mockPage, mockRecords }) => {
const nocoPage = await mockPage(twoTableWithAuthorAndBooks).waitForInit();
const authors = await mockRecords('author', 3);
await nocoPage.goto();
// 1. 将 author 表通过外键连接到 books 表
await page.getByLabel('block-item-CardItem-author-').hover();
await page.getByLabel('designer-schema-settings-CardItem-blockSettings:table-author').hover();
await page.getByRole('menuitem', { name: 'Connect data blocks right' }).hover();
await page.getByRole('menuitem', { name: 'books ' }).click();
await page.getByRole('option', { name: 'authorId [Foreign key]' }).click();
// 2. 点击 author 表的某一行books 表的数据会被筛选为当前点中行的数据
await page.getByLabel('block-item-CardItem-author-').getByText(authors[0].name).click();
for (const book of authors[0].books) {
await expect(page.getByLabel('block-item-CardItem-books-').getByText(book.name)).toBeVisible();
}
for (const book of authors[1].books) {
await expect(page.getByLabel('block-item-CardItem-books-').getByText(book.name)).not.toBeVisible();
}
});
test('should immediately show in the drop-down menu of Connect data blocks when adding a block for the first time', async ({
page,

View File

@ -0,0 +1,23 @@
import { expect, test } from '@nocobase/test/e2e';
test.describe('save as template', () => {
test('save as template, then delete it', async ({ page, mockPage, clearBlockTemplates }) => {
// 1. 创建一个区块,然后保存为模板
await mockPage().goto();
await page.getByLabel('schema-initializer-Grid-page:').hover();
await page.getByRole('menuitem', { name: 'table Table right' }).hover();
await page.getByRole('menuitem', { name: 'Users' }).click();
await page.getByLabel('block-item-CardItem-users-').hover();
await page.getByLabel('designer-schema-settings-CardItem-blockSettings:table-users').hover();
await page.getByRole('menuitem', { name: 'Save as template' }).click();
await page.getByRole('button', { name: 'OK', exact: true }).click();
// 2. 删除模板
await clearBlockTemplates();
// 3. 再次回到页面,应该显示“模板已删除字样”
await page.reload();
await expect(page.getByText('The block template "')).toBeVisible();
await expect(page.getByRole('button', { name: 'Delete' })).toBeVisible();
});
});

View File

@ -2107,3 +2107,372 @@ export const T4005 = {
'x-index': 1,
},
};
export const twoTableWithAuthorAndBooks = {
collections: [
{
name: 'author',
fields: [
{
name: 'books',
interface: 'o2m',
foreignKey: 'authorId',
target: 'books',
},
{
name: 'name',
interface: 'input',
},
],
},
{
name: 'books',
fields: [
{
name: 'authorId',
interface: 'integer',
target: 'author',
isForeignKey: true,
},
{
name: 'name',
interface: 'input',
},
],
},
],
pageSchema: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Page',
'x-app-version': '0.21.0-alpha.13',
'x-index': 1,
properties: {
'1i8ni0myw2y': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'page:addBlock',
'x-app-version': '0.21.0-alpha.13',
'x-index': 1,
properties: {
'9e58y8qieln': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
'x-app-version': '0.21.0-alpha.13',
'x-index': 1,
properties: {
i50s2rlk4ar: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
'x-app-version': '0.21.0-alpha.13',
'x-index': 1,
properties: {
ddk1nef97tf: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-decorator': 'TableBlockProvider',
'x-acl-action': 'author:list',
'x-use-decorator-props': 'useTableBlockDecoratorProps',
'x-decorator-props': {
collection: 'author',
dataSource: 'main',
action: 'list',
params: {
pageSize: 20,
},
rowKey: 'id',
showIndex: true,
dragSort: false,
},
'x-toolbar': 'BlockSchemaToolbar',
'x-settings': 'blockSettings:table',
'x-component': 'CardItem',
'x-filter-targets': [],
'x-app-version': '0.21.0-alpha.13',
'x-index': 1,
properties: {
actions: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-initializer': 'table:configureActions',
'x-component': 'ActionBar',
'x-component-props': {
style: {
marginBottom: 'var(--nb-spacing)',
},
},
'x-app-version': '0.21.0-alpha.13',
'x-index': 1,
'x-uid': '4yrqtiyaivp',
'x-async': false,
},
frdw8x1f09m: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'array',
'x-initializer': 'table:configureColumns',
'x-component': 'TableV2',
'x-use-component-props': 'useTableBlockProps',
'x-component-props': {
rowKey: 'id',
rowSelection: {
type: 'checkbox',
},
},
'x-app-version': '0.21.0-alpha.13',
'x-index': 2,
properties: {
actions: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
title: '{{ t("Actions") }}',
'x-action-column': 'actions',
'x-decorator': 'TableV2.Column.ActionBar',
'x-component': 'TableV2.Column',
'x-designer': 'TableV2.ActionColumnDesigner',
'x-initializer': 'table:configureItemActions',
'x-app-version': '0.21.0-alpha.13',
'x-index': 1,
properties: {
uw13f1l61js: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-decorator': 'DndContext',
'x-component': 'Space',
'x-component-props': {
split: '|',
},
'x-app-version': '0.21.0-alpha.13',
'x-index': 1,
'x-uid': 'pabqet5c7ct',
'x-async': false,
},
},
'x-uid': 'zvfoxrwhxqh',
'x-async': false,
},
'9m5k78j7th3': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-decorator': 'TableV2.Column.Decorator',
'x-toolbar': 'TableColumnSchemaToolbar',
'x-settings': 'fieldSettings:TableColumn',
'x-component': 'TableV2.Column',
'x-app-version': '0.21.0-alpha.13',
properties: {
name: {
_isJSONSchemaObject: true,
version: '2.0',
'x-collection-field': 'author.name',
'x-component': 'CollectionField',
'x-component-props': {
ellipsis: true,
},
'x-read-pretty': true,
'x-decorator': null,
'x-decorator-props': {
labelStyle: {
display: 'none',
},
},
'x-app-version': '0.21.0-alpha.13',
'x-uid': 'xvcufxzv8to',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '1nvi0qrq85c',
'x-async': false,
'x-index': 2,
},
},
'x-uid': 'sal6mjrumuk',
'x-async': false,
},
},
'x-uid': '6leevx6ln8m',
'x-async': false,
},
},
'x-uid': 'fpkthksicg6',
'x-async': false,
},
},
'x-uid': 'vymaiz1eihz',
'x-async': false,
},
tje5moj54zp: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
'x-app-version': '0.21.0-alpha.13',
'x-index': 2,
properties: {
vql8xk7icqm: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
'x-app-version': '0.21.0-alpha.13',
'x-index': 1,
properties: {
z8pmpx202xi: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-decorator': 'TableBlockProvider',
'x-acl-action': 'books:list',
'x-use-decorator-props': 'useTableBlockDecoratorProps',
'x-decorator-props': {
collection: 'books',
dataSource: 'main',
action: 'list',
params: {
pageSize: 20,
},
rowKey: 'id',
showIndex: true,
dragSort: false,
},
'x-toolbar': 'BlockSchemaToolbar',
'x-settings': 'blockSettings:table',
'x-component': 'CardItem',
'x-filter-targets': [],
'x-app-version': '0.21.0-alpha.13',
'x-index': 1,
properties: {
actions: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-initializer': 'table:configureActions',
'x-component': 'ActionBar',
'x-component-props': {
style: {
marginBottom: 'var(--nb-spacing)',
},
},
'x-app-version': '0.21.0-alpha.13',
'x-index': 1,
'x-uid': '3d0o79v11e8',
'x-async': false,
},
j8som9wt9uj: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'array',
'x-initializer': 'table:configureColumns',
'x-component': 'TableV2',
'x-use-component-props': 'useTableBlockProps',
'x-component-props': {
rowKey: 'id',
rowSelection: {
type: 'checkbox',
},
},
'x-app-version': '0.21.0-alpha.13',
'x-index': 2,
properties: {
actions: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
title: '{{ t("Actions") }}',
'x-action-column': 'actions',
'x-decorator': 'TableV2.Column.ActionBar',
'x-component': 'TableV2.Column',
'x-designer': 'TableV2.ActionColumnDesigner',
'x-initializer': 'table:configureItemActions',
'x-app-version': '0.21.0-alpha.13',
'x-index': 1,
properties: {
jm9u46tzak6: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-decorator': 'DndContext',
'x-component': 'Space',
'x-component-props': {
split: '|',
},
'x-app-version': '0.21.0-alpha.13',
'x-index': 1,
'x-uid': 'aw5jz41g7va',
'x-async': false,
},
},
'x-uid': 'nkhmuqxiehk',
'x-async': false,
},
j9trhyy867k: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-decorator': 'TableV2.Column.Decorator',
'x-toolbar': 'TableColumnSchemaToolbar',
'x-settings': 'fieldSettings:TableColumn',
'x-component': 'TableV2.Column',
'x-app-version': '0.21.0-alpha.13',
properties: {
name: {
_isJSONSchemaObject: true,
version: '2.0',
'x-collection-field': 'books.name',
'x-component': 'CollectionField',
'x-component-props': {
ellipsis: true,
},
'x-read-pretty': true,
'x-decorator': null,
'x-decorator-props': {
labelStyle: {
display: 'none',
},
},
'x-app-version': '0.21.0-alpha.13',
'x-uid': 'lopjr1lbm71',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '1ceugk5f8fj',
'x-async': false,
'x-index': 2,
},
},
'x-uid': 'x9prv8hr3a6',
'x-async': false,
},
},
'x-uid': 'puzu4rwwxly',
'x-async': false,
},
},
'x-uid': 'j900c1u029s',
'x-async': false,
},
},
'x-uid': 'f165ng4ho06',
'x-async': false,
},
},
'x-uid': 'nga7wa4cmxd',
'x-async': false,
},
},
'x-uid': 'osodxd9u6vt',
'x-async': true,
},
};