chore: add e2e for variables (#4152)

* chore: optimize e2e

* chore: test default value

* chore: data scope

* chore: test Assign field values

* chore: fix e2e

* refactor: extract

* chore: skip failed e2e

* chore: fix failed e2e

* chore: fix T-4133

* chore: fix e2e
This commit is contained in:
Zeke Zhang 2024-04-26 14:26:02 +08:00 committed by GitHub
parent e3408c9ff1
commit ccd2ade2aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
37 changed files with 1552 additions and 308 deletions

View File

@ -2,6 +2,7 @@ import {
Page,
expect,
expectSettingsMenu,
expectSupportedVariables,
oneEmptyForm,
oneEmptyFormWithActions,
oneTableBlockWithActionsAndFormBlocks,
@ -10,7 +11,7 @@ import {
test,
} from '@nocobase/test/e2e';
import { oneEmptyTableWithUsers } from '../../../details-multi/__e2e__/templatesOfBug';
import { T2165, T2174, T3251, T3806, T3815, T3871 } from './templatesOfBug';
import { T2165, T2174, T3251, T3806, T3815, T3871, oneFormAndOneTableWithUsers } from './templatesOfBug';
const clickOption = async (page: Page, optionName: string) => {
await page.getByLabel('block-item-CardItem-general-form').hover();
@ -115,6 +116,13 @@ test.describe('creation form block schema settings', () => {
// 当 singleLineText 字段的值包含 longText 字段的值时,禁用 longText 字段
await openLinkageRules();
await page.getByLabel('variable-button').click();
await expectSupportedVariables(page, [
'Constant',
'Current user',
'Current role',
'Date variables',
'Current form',
]);
await page.getByRole('menuitemcheckbox', { name: 'Current form' }).click();
await page.getByRole('menuitemcheckbox', { name: 'longText' }).click();
await page.getByRole('button', { name: 'OK', exact: true }).click();
@ -187,6 +195,7 @@ test.describe('creation form block schema settings', () => {
await page.getByText('Expression').click();
await page.getByText('xSelect a variable').click();
await expectSupportedVariables(page, ['Current user', 'Current role', 'Date variables', 'Current form']);
await page.getByRole('menuitemcheckbox', { name: 'Current form right' }).click();
await page.getByRole('menuitemcheckbox', { name: 'number' }).click();
await page.getByRole('button', { name: 'OK', exact: true }).click();
@ -309,13 +318,13 @@ test.describe('creation form block schema settings', () => {
// 编辑表单中获取到接口数据后再触发联动规则
await page.getByLabel('action-Action.Link-Edit-').click();
await expect(await page.getByRole('spinbutton').inputValue()).toBe('66');
await expect(page.getByRole('spinbutton')).toHaveValue('66');
await page.getByLabel('drawer-Action.Container-general-Edit record-mask').click();
//新建表单中的赋默认值后的联动规则
await expect(await page.getByLabel('block-item-CardItem-general-')).toBeVisible();
await expect(page.getByLabel('block-item-CardItem-general-')).toBeVisible();
await page.getByLabel('action-Action-Add new-create-').click();
await expect(await page.getByRole('spinbutton').inputValue()).toBe('88');
await expect(page.getByRole('spinbutton')).toHaveValue('88');
});
});
@ -1404,22 +1413,79 @@ test.describe('actions schema settings', () => {
});
});
test('customize: save record', async ({ page, mockPage }) => {
await mockPage(oneEmptyFormWithActions).goto();
test.describe('customize: save record', () => {
test('supported options', async ({ page, mockPage }) => {
await mockPage(oneEmptyFormWithActions).goto();
await expectSettingsMenu({
page,
showMenu: async () => {
await page.getByRole('button', { name: 'Save record' }).hover();
await page.getByRole('button', { name: 'designer-schema-settings-Action-Action.Designer-users' }).hover();
},
supportedOptions: [
'Edit button',
'Assign field values',
'Skip required validation',
'After successful submission',
'Delete',
],
await expectSettingsMenu({
page,
showMenu: async () => {
await page.getByRole('button', { name: 'Save record' }).hover();
await page.getByRole('button', { name: 'designer-schema-settings-Action-Action.Designer-users' }).hover();
},
supportedOptions: [
'Edit button',
'Assign field values',
'Skip required validation',
'After successful submission',
'Delete',
],
});
});
test('Assign field values', async ({ page, mockPage }) => {
await mockPage(oneFormAndOneTableWithUsers).goto();
const openPopup = async () => {
if (!(await page.getByLabel('action-Action-Save record-').isVisible())) {
await page.getByLabel('schema-initializer-ActionBar-createForm:configureActions-users').hover();
await page.getByRole('menuitem', { name: 'Customize right' }).hover();
await page.getByRole('menuitem', { name: 'Save record' }).click();
}
await page.getByLabel('action-Action-Save record-').hover();
await page.getByLabel('designer-schema-settings-Action-actionSettings:saveRecord-users').hover();
await page.getByRole('menuitem', { name: 'Assign field values' }).click();
if (!(await page.getByLabel('block-item-AssignedField-').getByRole('textbox').isVisible())) {
await page.getByLabel('schema-initializer-Grid-assignFieldValuesForm:configureFields-users').hover();
await page.getByRole('menuitem', { name: 'Nickname' }).click();
}
};
const expectNewValue = async (value: string) => {
await page.getByLabel('action-Action-Save record-').click();
await page.getByRole('button', { name: 'OK', exact: true }).click();
await page.getByLabel('action-Action-Refresh-refresh').click();
await expect(page.getByLabel('block-item-CardItem-users-table').getByText(value)).toBeVisible();
};
// 1. 打开 Assign field values 配置弹窗
await openPopup();
// 2. 将 Nickname 字段的值设置为 `123456`
await page.getByLabel('block-item-AssignedField-').getByRole('textbox').click();
await page.getByLabel('block-item-AssignedField-').getByRole('textbox').fill('123456');
await page.getByRole('button', { name: 'Submit' }).click();
// 3. 保存后点击 Save record 按钮,然后刷新表格,应该显示一条 Nickname 为 “123456” 的记录
await expectNewValue('123456');
// 4. 再次打开 Assign field values 配置弹窗,这次为 Nickname 设置一个变量值Current role
await openPopup();
await page.getByLabel('variable-button').click();
await expectSupportedVariables(page, [
'Constant',
'Current user',
'Current role',
'Date variables',
'Current form',
]);
await page.getByRole('menuitemcheckbox', { name: 'Current role' }).click();
await page.getByRole('button', { name: 'Submit' }).click();
// 5. 保存后点击 Save record 按钮,然后刷新表格,应该显示一条 Nickname 为 “root” 的记录
await expectNewValue('root');
});
});
});

View File

@ -8880,3 +8880,296 @@ export const oneTableWithUsersForDeprecatedVariables = {
'x-index': 1,
},
};
export const oneFormAndOneTableWithUsers: PageConfig = {
pageSchema: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Page',
'x-app-version': '0.21.0-alpha.13',
'x-index': 1,
properties: {
a5je3qsyedz: {
_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: {
i19i3rr6vf1: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
'x-app-version': '0.21.0-alpha.15',
'x-index': 1,
properties: {
hfwcy6caqnk: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
'x-app-version': '0.21.0-alpha.15',
'x-index': 1,
properties: {
tldnr8czm49: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-acl-action-props': {
skipScopeCheck: true,
},
'x-acl-action': 'users:create',
'x-decorator': 'FormBlockProvider',
'x-use-decorator-props': 'useCreateFormBlockDecoratorProps',
'x-decorator-props': {
dataSource: 'main',
collection: 'users',
},
'x-toolbar': 'BlockSchemaToolbar',
'x-settings': 'blockSettings:createForm',
'x-component': 'CardItem',
'x-app-version': '0.21.0-alpha.15',
'x-index': 1,
properties: {
'277vnh3hhj8': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'FormV2',
'x-use-component-props': 'useCreateFormBlockProps',
'x-app-version': '0.21.0-alpha.15',
'x-index': 1,
properties: {
grid: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'form:configureFields',
'x-app-version': '0.21.0-alpha.15',
'x-index': 1,
'x-uid': 'ld0indfray1',
'x-async': false,
},
d9cn1kgxckc: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-initializer': 'createForm:configureActions',
'x-component': 'ActionBar',
'x-component-props': {
layout: 'one-column',
style: {
marginTop: 24,
},
},
'x-app-version': '0.21.0-alpha.15',
'x-index': 2,
'x-uid': 'k6zuwp7u9w6',
'x-async': false,
},
},
'x-uid': 'j8aw9rko2z3',
'x-async': false,
},
},
'x-uid': 'kgbqy1na2no',
'x-async': false,
},
},
'x-uid': 'wjnnhu9acbp',
'x-async': false,
},
},
'x-uid': '8g3dnjl6gg1',
'x-async': false,
},
rwialdftgzc: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
'x-app-version': '0.21.0-alpha.15',
'x-index': 2,
properties: {
kwnyh28foid: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
'x-app-version': '0.21.0-alpha.15',
'x-index': 1,
properties: {
luega8f3t66: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-decorator': 'TableBlockProvider',
'x-acl-action': 'users:list',
'x-use-decorator-props': 'useTableBlockDecoratorProps',
'x-decorator-props': {
collection: 'users',
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.15',
'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.15',
'x-index': 1,
properties: {
plqyq56bd1s: {
_isJSONSchemaObject: true,
version: '2.0',
title: '{{ t("Refresh") }}',
'x-action': 'refresh',
'x-component': 'Action',
'x-use-component-props': 'useRefreshActionProps',
'x-toolbar': 'ActionSchemaToolbar',
'x-settings': 'actionSettings:refresh',
'x-component-props': {
icon: 'ReloadOutlined',
},
'x-align': 'right',
type: 'void',
'x-app-version': '0.21.0-alpha.15',
'x-index': 1,
'x-uid': 'tekvxezs7fq',
'x-async': false,
},
},
'x-uid': 'pbiwv4v13ny',
'x-async': false,
},
'2bpww4bg6gl': {
_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.15',
'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.15',
'x-index': 1,
properties: {
dp022t8opyt: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-decorator': 'DndContext',
'x-component': 'Space',
'x-component-props': {
split: '|',
},
'x-app-version': '0.21.0-alpha.15',
'x-index': 1,
'x-uid': 'weeiqquu365',
'x-async': false,
},
},
'x-uid': 'mrbnwas3bjj',
'x-async': false,
},
o86r52gopar: {
_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.15',
'x-index': 2,
properties: {
nickname: {
_isJSONSchemaObject: true,
version: '2.0',
'x-collection-field': 'users.nickname',
'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.15',
'x-index': 1,
'x-uid': 'zhpnmk0jtlm',
'x-async': false,
},
},
'x-uid': 'qo0ipkzabor',
'x-async': false,
},
},
'x-uid': 'j24y8acxaih',
'x-async': false,
},
},
'x-uid': '9ypn04atyla',
'x-async': false,
},
},
'x-uid': 'cpb2pi4emkx',
'x-async': false,
},
},
'x-uid': 'sqzgc43tio1',
'x-async': false,
},
},
'x-uid': '2lsyffpy9uo',
'x-async': false,
},
},
'x-uid': 'u7zfdj6rpa5',
'x-async': true,
},
};

View File

@ -2,6 +2,7 @@ import {
Page,
expect,
expectSettingsMenu,
expectSupportedVariables,
mockUserRecordsWithoutDepartments,
oneEmptyTableBlockWithActions,
oneEmptyTableWithTreeCollection,
@ -11,7 +12,13 @@ import {
twoTableWithAssociationFields,
twoTableWithSameCollection,
} from '@nocobase/test/e2e';
import { T3843, T4032, oneTableWithRoles, twoTableWithAuthorAndBooks } from './templatesOfBug';
import {
T3843,
T4032,
oneTableWithRoles,
oneTableWithUpdateRecord,
twoTableWithAuthorAndBooks,
} from './templatesOfBug';
test.describe('table block schema settings', () => {
test('supported options', async ({ page, mockPage }) => {
@ -184,6 +191,7 @@ test.describe('table block schema settings', () => {
await page.getByTestId('select-filter-field').click();
await page.getByRole('menuitemcheckbox', { name: 'singleLineText' }).click();
await page.getByLabel('variable-button').click();
await expectSupportedVariables(page, ['Constant', 'Current user', 'Current role', 'Date variables']);
await page.getByRole('menuitemcheckbox', { name: 'Current user' }).click();
await page.getByRole('menuitemcheckbox', { name: 'Nickname' }).click();
await page.getByRole('button', { name: 'OK', exact: true }).click();
@ -790,6 +798,67 @@ test.describe('actions schema settings', () => {
],
});
});
test('Assign field values', async ({ page, mockPage, mockRecord }) => {
const nocoPage = await mockPage(oneTableWithUpdateRecord).waitForInit();
await mockRecord('users2');
await nocoPage.goto();
const openPopup = async () => {
if (!(await page.getByLabel('action-Action.Link-Update record-customize:update-users2-table-0').isVisible())) {
await page.getByRole('button', { name: 'Actions', exact: true }).hover();
await page.getByLabel('designer-schema-settings-TableV2.Column-TableV2.ActionColumnDesigner-users2').hover();
await page.getByRole('menuitem', { name: 'Customize right' }).hover();
await page.getByRole('menuitem', { name: 'Update record' }).click();
}
await page.getByLabel('action-Action.Link-Update record-customize:update-users2-table-0').hover();
await page
.getByLabel('designer-schema-settings-Action.Link-actionSettings:updateRecord-users2')
.first()
.hover();
await page.getByRole('menuitem', { name: 'Assign field values' }).click();
if (!(await page.getByLabel('block-item-AssignedField-').getByRole('textbox').isVisible())) {
await page.getByLabel('schema-initializer-Grid-assignFieldValuesForm:configureFields-users').hover();
await page.getByRole('menuitem', { name: 'Nickname' }).click();
}
};
const expectNewValue = async (value: string) => {
await page.getByLabel('action-Action.Link-Update record-customize:update-users2-table-0').click();
await page.getByRole('button', { name: 'OK', exact: true }).click();
await page.getByLabel('action-Action-Refresh-refresh').click();
await expect(page.getByLabel('block-item-CardItem-users2-').getByText(value)).toBeVisible();
};
// 1. 打开 Assign field values 配置弹窗
await openPopup();
// 2. 将 Nickname 字段的值设置为 `123456`
await page.getByLabel('block-item-AssignedField-').getByRole('textbox').click();
await page.getByLabel('block-item-AssignedField-').getByRole('textbox').fill('123456');
await page.getByRole('button', { name: 'Submit' }).click();
// 3. 保存后点击 Save record 按钮,然后刷新表格,应该显示一条 Nickname 为 “123456” 的记录
await expectNewValue('123456');
// 4. 再次打开 Assign field values 配置弹窗,这次为 Nickname 设置一个变量值Current role
await openPopup();
await page.getByLabel('variable-button').click();
await expectSupportedVariables(page, [
'Constant',
'Current user',
'Current role',
'Date variables',
'Current record',
]);
await page.getByRole('menuitemcheckbox', { name: 'Current role' }).click();
await page.getByRole('button', { name: 'Submit' }).click();
// 5. 保存后点击 Save record 按钮,然后刷新表格,应该显示一条 Nickname 为 “root” 的记录
await expectNewValue('root');
});
});
test.describe('add child', () => {

View File

@ -2476,3 +2476,215 @@ export const twoTableWithAuthorAndBooks = {
'x-async': true,
},
};
export const oneTableWithUpdateRecord = {
collections: [
{
name: 'users2',
fields: [
{
name: 'nickname',
interface: 'input',
},
],
},
],
pageSchema: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Page',
'x-index': 1,
properties: {
r9qrai28a9x: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'page:addBlock',
'x-index': 1,
properties: {
x83br30jhba: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
'x-app-version': '0.21.0-alpha.15',
'x-index': 1,
properties: {
abm6suh07io: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
'x-app-version': '0.21.0-alpha.15',
'x-index': 1,
properties: {
ik81gciqx99: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-decorator': 'TableBlockProvider',
'x-acl-action': 'users2:list',
'x-use-decorator-props': 'useTableBlockDecoratorProps',
'x-decorator-props': {
collection: 'users2',
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.15',
'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.15',
'x-index': 1,
properties: {
e6p6pc4i7ru: {
_isJSONSchemaObject: true,
version: '2.0',
title: '{{ t("Refresh") }}',
'x-action': 'refresh',
'x-component': 'Action',
'x-use-component-props': 'useRefreshActionProps',
'x-toolbar': 'ActionSchemaToolbar',
'x-settings': 'actionSettings:refresh',
'x-component-props': {
icon: 'ReloadOutlined',
},
'x-align': 'right',
type: 'void',
'x-app-version': '0.21.0-alpha.15',
'x-index': 1,
'x-uid': 'ganipmn6wdh',
'x-async': false,
},
},
'x-uid': 'su2i79kr385',
'x-async': false,
},
w3g2bnojflu: {
_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.15',
'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.15',
'x-index': 1,
properties: {
'6v6dk8utqur': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-decorator': 'DndContext',
'x-component': 'Space',
'x-component-props': {
split: '|',
},
'x-app-version': '0.21.0-alpha.15',
'x-index': 1,
'x-uid': 'b25k9c1ur9n',
'x-async': false,
},
},
'x-uid': 'hso9ig0msah',
'x-async': false,
},
'3k0ukmw2anz': {
_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.15',
'x-index': 2,
properties: {
nickname: {
_isJSONSchemaObject: true,
version: '2.0',
'x-collection-field': 'users2.nickname',
'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.15',
'x-index': 1,
'x-uid': 'roxn64e6vhx',
'x-async': false,
},
},
'x-uid': 'xx6danutdp0',
'x-async': false,
},
},
'x-uid': 'w3akwbj68s0',
'x-async': false,
},
},
'x-uid': '114glfljrp1',
'x-async': false,
},
},
'x-uid': 'w8l1aaizpwc',
'x-async': false,
},
},
'x-uid': 'ywpa5ajvacs',
'x-async': false,
},
},
'x-uid': 'x9mg721vhua',
'x-async': false,
},
},
'x-uid': 'tilp0ayvsr8',
'x-async': true,
},
};

View File

@ -1,19 +1,19 @@
import { CloseOutlined, PlusOutlined } from '@ant-design/icons';
import { css } from '@emotion/css';
import { ArrayField } from '@formily/core';
import { spliceArrayState } from '@formily/core/esm/shared/internals';
import { RecursionField, observer, useFieldSchema } from '@formily/react';
import { action } from '@formily/reactive';
import { each } from '@formily/shared';
import { Button, Card, Divider, Tooltip } from 'antd';
import _ from 'lodash';
import React, { useCallback, useContext } from 'react';
import { useTranslation } from 'react-i18next';
import { FormActiveFieldsProvider } from '../../../block-provider/hooks/useFormActiveFields';
import { useCollection } from '../../../data-source';
import {
useCollectionRecord,
useCollectionRecordData,
} from '../../../data-source/collection-record/CollectionRecordProvider';
import { isNewRecord, markRecordAsNew } from '../../../data-source/collection-record/isNewRecord';
import { FlagProvider } from '../../../flag-provider';
import { RecordIndexProvider, RecordProvider } from '../../../record-provider';
import { isPatternDisabled, isSystemField } from '../../../schema-settings';
@ -24,8 +24,6 @@ import {
} from '../../../schema-settings/hooks/useIsAllowToSetDefaultValue';
import { AssociationFieldContext } from './context';
import { SubFormProvider, useAssociationFieldContext } from './hooks';
import { isNewRecord, markRecordAsNew } from '../../../data-source/collection-record/isNewRecord';
import { useCollection } from '../../../data-source';
export const Nester = (props) => {
const { options } = useContext(AssociationFieldContext);
@ -157,14 +155,10 @@ const ToManyNester = observer(
<PlusOutlined
style={{ zIndex: 1000, marginRight: '10px', color: '#a8a3a3' }}
onClick={() => {
void action(() => {
action(() => {
if (!Array.isArray(field.value)) {
field.value = [];
}
spliceArrayState(field as any, {
startIndex: index + 1,
insertCount: 1,
});
field.value.splice(index + 1, 0, markRecordAsNew({}));
each(field.form.fields, (targetField, key) => {
if (!targetField) {
@ -182,11 +176,7 @@ const ToManyNester = observer(
<CloseOutlined
style={{ zIndex: 1000, color: '#a8a3a3' }}
onClick={() => {
void action(() => {
spliceArrayState(field as any, {
startIndex: index,
deleteCount: 1,
});
action(() => {
field.value.splice(index, 1);
return field.onInput(field.value);
});

View File

@ -7,6 +7,7 @@ import { ACLCollectionFieldProvider } from '../../../acl/ACLProvider';
import { useApp } from '../../../application';
import { useFormActiveFields } from '../../../block-provider/hooks/useFormActiveFields';
import { Collection_deprecated } from '../../../collection-manager';
import { CollectionFieldProvider } from '../../../data-source/collection-field/CollectionFieldProvider';
import { GeneralSchemaDesigner } from '../../../schema-settings';
import { useVariables } from '../../../variables';
import useContextVariable from '../../../variables/hooks/useContextVariable';
@ -16,7 +17,6 @@ import { FilterFormDesigner } from './FormItem.FilterFormDesigner';
import { useEnsureOperatorsValid } from './SchemaSettingOptions';
import useLazyLoadDisplayAssociationFieldsOfForm from './hooks/useLazyLoadDisplayAssociationFieldsOfForm';
import useParseDefaultValue from './hooks/useParseDefaultValue';
import { CollectionFieldProvider } from '../../../data-source/collection-field/CollectionFieldProvider';
Item.displayName = 'FormilyFormItem';

View File

@ -24,7 +24,7 @@ const useParseDefaultValue = () => {
const fieldSchema = useFieldSchema();
const variables = useVariables();
const localVariables = useLocalVariables();
const recordV2 = useCollectionRecord();
const record = useCollectionRecord();
const { isInAssignFieldValues, isInSetDefaultValueDialog, isInFormDataTemplate, isInSubTable, isInSubForm } =
useFlag() || {};
const { getField } = useCollection_deprecated();
@ -51,7 +51,7 @@ const useParseDefaultValue = () => {
isInSetDefaultValueDialog ||
isInFormDataTemplate ||
isSubMode(fieldSchema) ||
(!recordV2?.isNew && !isInAssignFieldValues)
(!record?.isNew && !isInAssignFieldValues)
) {
return;
}

View File

@ -199,9 +199,6 @@ export const SchemaSettingsDefaultValue = function DefaultValueConfigure(props:
['x-uid']: fieldSchema['x-uid'],
};
fieldSchema.default = v.default;
if (!v.default && v.default !== 0) {
field.value = null;
}
if (!isVariable(v.default)) {
field.setInitialValue?.(v.default);
}

View File

@ -1047,3 +1047,14 @@ export const mockUserRecordsWithoutDepartments = (mockRecords: ExtendUtils['mock
})),
);
};
/**
*
* @param page
* @param variables
*/
export async function expectSupportedVariables(page: Page, variables: string[]) {
for (const name of variables) {
await expect(page.getByRole('menuitemcheckbox', { name })).toBeVisible();
}
}

View File

@ -6256,6 +6256,475 @@ export const oneTableBlockWithAddNewAndViewAndEditAndBasicFieldsAndSubTable: Pag
},
};
/**
*
*/
export const oneTableBlockWithEditAndSubForm: PageConfig = {
collections: [
...generalWithBasic,
{
name: 'subform',
fields: [
{
name: 'manyToMany',
interface: 'm2m',
target: 'general',
},
],
},
],
pageSchema: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Page',
properties: {
ikn7a785yxy: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'page:addBlock',
properties: {
ymhggvoaw7g: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
'x-app-version': '0.21.0-alpha.15',
properties: {
itbsbwvloui: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
'x-app-version': '0.21.0-alpha.15',
properties: {
'0ynnfgfjgl9': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-decorator': 'TableBlockProvider',
'x-acl-action': 'subform:list',
'x-use-decorator-props': 'useTableBlockDecoratorProps',
'x-decorator-props': {
collection: 'subform',
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.15',
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.15',
'x-uid': 'wvkrzc4gbed',
'x-async': false,
'x-index': 1,
},
c458tgnk7e1: {
_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.15',
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.15',
properties: {
g3whb78e8by: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-decorator': 'DndContext',
'x-component': 'Space',
'x-component-props': {
split: '|',
},
'x-app-version': '0.21.0-alpha.15',
properties: {
'96j8pfb73nd': {
'x-uid': 'jbq7qw7iuht',
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
title: 'Edit record',
'x-action': 'update',
'x-toolbar': 'ActionSchemaToolbar',
'x-settings': 'actionSettings:edit',
'x-component': 'Action.Link',
'x-component-props': {
openMode: 'drawer',
danger: false,
},
'x-decorator': 'ACLActionProvider',
'x-designer-props': {
linkageAction: true,
},
properties: {
drawer: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
title: '{{ t("Edit record") }}',
'x-component': 'Action.Container',
'x-component-props': {
className: 'nb-action-popup',
},
properties: {
tabs: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Tabs',
'x-component-props': {},
'x-initializer': 'popup:addTab',
properties: {
tab1: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
title: '{{t("Edit")}}',
'x-component': 'Tabs.TabPane',
'x-designer': 'Tabs.Designer',
'x-component-props': {},
properties: {
grid: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'popup:common:addBlock',
properties: {
lg7f1thob6s: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
'x-app-version': '0.21.0-alpha.15',
properties: {
njdmuxui5o9: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
'x-app-version': '0.21.0-alpha.15',
properties: {
'1wruwk2ymiy': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-acl-action-props': {
skipScopeCheck: false,
},
'x-acl-action': 'subform:update',
'x-decorator': 'FormBlockProvider',
'x-use-decorator-props':
'useEditFormBlockDecoratorProps',
'x-decorator-props': {
action: 'get',
dataSource: 'main',
collection: 'subform',
},
'x-toolbar': 'BlockSchemaToolbar',
'x-settings': 'blockSettings:editForm',
'x-component': 'CardItem',
'x-app-version': '0.21.0-alpha.15',
properties: {
'1r4nw0s9i1w': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'FormV2',
'x-use-component-props': 'useEditFormBlockProps',
'x-app-version': '0.21.0-alpha.15',
properties: {
grid: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer': 'form:configureFields',
'x-app-version': '0.21.0-alpha.15',
properties: {
'4j2zyvo135s': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Row',
'x-app-version': '0.21.0-alpha.15',
properties: {
'5zclzus2agg': {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid.Col',
'x-app-version': '0.21.0-alpha.15',
properties: {
manyToMany: {
'x-uid': 'hs5l8xki08o',
_isJSONSchemaObject: true,
version: '2.0',
type: 'string',
'x-toolbar':
'FormItemSchemaToolbar',
'x-settings':
'fieldSettings:FormItem',
'x-component': 'CollectionField',
'x-decorator': 'FormItem',
'x-collection-field':
'subform.manyToMany',
'x-component-props': {
fieldNames: {
label: 'id',
value: 'id',
},
mode: 'Nester',
},
'x-app-version': '0.21.0-alpha.15',
properties: {
w16ui5so6ug: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component':
'AssociationField.Nester',
'x-index': 1,
'x-app-version':
'0.21.0-alpha.15',
properties: {
grid: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-component': 'Grid',
'x-initializer':
'form:configureFields',
'x-app-version':
'0.21.0-alpha.15',
properties: {
'52v5gjhuhil': {
_isJSONSchemaObject:
true,
version: '2.0',
type: 'void',
'x-component':
'Grid.Row',
'x-app-version':
'0.21.0-alpha.15',
properties: {
'4j9cytzhwjt': {
_isJSONSchemaObject:
true,
version: '2.0',
type: 'void',
'x-component':
'Grid.Col',
'x-app-version':
'0.21.0-alpha.15',
properties: {
singleLineText: {
_isJSONSchemaObject:
true,
version: '2.0',
type: 'string',
'x-toolbar':
'FormItemSchemaToolbar',
'x-settings':
'fieldSettings:FormItem',
'x-component':
'CollectionField',
'x-decorator':
'FormItem',
'x-collection-field':
'general.singleLineText',
'x-component-props':
{},
'x-app-version':
'0.21.0-alpha.15',
'x-uid':
'heu3ssj95k4',
'x-async':
false,
'x-index': 1,
},
},
'x-uid':
'24aob2c29am',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'e9z1vk94wzt',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'xv2tx1i3asd',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'f8ww2djzw4s',
'x-async': false,
},
},
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'uw8v7gpncme',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'y36de9c1w1q',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'cd8hid8sd8p',
'x-async': false,
'x-index': 1,
},
lbqqyqmfn58: {
_isJSONSchemaObject: true,
version: '2.0',
type: 'void',
'x-initializer': 'editForm:configureActions',
'x-component': 'ActionBar',
'x-component-props': {
layout: 'one-column',
style: {
marginTop: 24,
},
},
'x-app-version': '0.21.0-alpha.15',
'x-uid': 'd7ou1l2pame',
'x-async': false,
'x-index': 2,
},
},
'x-uid': '378pyhe1ouc',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'kqrgr76mqyd',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'tfxy8lqeyzf',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'skx1ugoefxd',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 't24v0l6iv9b',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'ant817mjpxd',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '6ozc65lhnk0',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'lwk8hqr8p79',
'x-async': false,
'x-index': 1,
},
},
'x-async': false,
'x-index': 1,
},
},
'x-uid': '3gzaswo60as',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'gh0ea7odopi',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'u541j0zmw63',
'x-async': false,
'x-index': 2,
},
},
'x-uid': 'gdpm3ailyz7',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'gkc72ed4e3h',
'x-async': false,
'x-index': 1,
},
},
'x-uid': '93cyoyerj1s',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'bykp472klg9',
'x-async': false,
'x-index': 1,
},
},
'x-uid': 'fdlzfzi31ux',
'x-async': true,
'x-index': 1,
},
};
/**
* 1. Table
* 2. Add new Form

View File

@ -2,6 +2,7 @@ import {
Page,
expect,
expectSettingsMenu,
expectSupportedVariables,
mockUserRecordsWithoutDepartments,
oneFilterFormBlockWithAllAssociationFields,
oneTableBlockWithAddNewAndViewAndEditAndAssociationFields,
@ -107,37 +108,44 @@ test.describe('form item & create form', () => {
});
test('Set the data scope', async ({ page, mockPage, mockRecords }) => {
const records = await (async (mockPage, mockRecords) => {
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndAssociationFields).waitForInit();
const recordsOfUser = await mockUserRecordsWithoutDepartments(mockRecords, 3);
await nocoPage.goto();
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndAssociationFields).waitForInit();
const records = await mockUserRecordsWithoutDepartments(mockRecords, 3);
await nocoPage.goto();
return recordsOfUser;
})(mockPage, mockRecords);
await (async (page: Page) => {
await page.getByRole('button', { name: 'Add new' }).click();
})(page);
await (async (page: Page, fieldName: string) => {
await page.getByLabel(`block-item-CollectionField-general-form-general.${fieldName}-${fieldName}`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'oneToOneBelongsTo');
await page.getByRole('button', { name: 'Add new' }).click();
await page
.getByLabel(`block-item-CollectionField-general-form-general.oneToOneBelongsTo-oneToOneBelongsTo`)
.hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.oneToOneBelongsTo`)
.hover();
await page.getByRole('menuitem', { name: 'Set the data scope' }).click();
await page.getByText('Add condition', { exact: true }).click();
await page.getByTestId('select-filter-field').click();
await page.getByRole('menuitemcheckbox', { name: 'ID', exact: true }).click();
await page.getByRole('spinbutton').click();
await page.getByRole('spinbutton').fill(String(records[0].id));
// 测试下可选择的变量有哪些
await page.getByLabel('variable-button').click();
await expectSupportedVariables(page, [
'Constant',
'Current user',
'Current role',
'Date variables',
'Current form',
]);
await page.getByLabel('variable-button').click();
await page.getByRole('button', { name: 'OK', exact: true }).click();
// 再次打开弹窗,设置的值应该还在
await (async (page: Page, fieldName: string) => {
await page.getByLabel(`block-item-CollectionField-general-form-general.${fieldName}-${fieldName}`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'oneToOneBelongsTo');
await page
.getByLabel(`block-item-CollectionField-general-form-general.oneToOneBelongsTo-oneToOneBelongsTo`)
.hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.oneToOneBelongsTo`)
.hover();
await page.getByRole('menuitem', { name: 'Set the data scope' }).click();
await expect(page.getByTestId('select-filter-field')).toHaveText('ID');
await expect(page.getByRole('spinbutton')).toHaveValue(String(records[0].id));
@ -307,38 +315,45 @@ test.describe('form item & edit form', () => {
});
test('Set the data scope', async ({ page, mockPage, mockRecords }) => {
const { recordsOfUser } = await (async (mockPage, mockRecords) => {
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndAssociationFields).waitForInit();
const recordsOfUser = await mockUserRecordsWithoutDepartments(mockRecords, 3);
const record = (await mockRecords('general', 1))[0];
await nocoPage.goto();
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndAssociationFields).waitForInit();
const recordsOfUser = await mockUserRecordsWithoutDepartments(mockRecords, 3);
await mockRecords('general', 1);
await nocoPage.goto();
return { record, recordsOfUser };
})(mockPage, mockRecords);
await (async (page: Page) => {
await page.getByLabel('action-Action.Link-Edit record-update-general-table-0').click();
})(page);
await (async (page: Page, fieldName: string) => {
await page.getByLabel(`block-item-CollectionField-general-form-general.${fieldName}-${fieldName}`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'oneToOneBelongsTo');
await page.getByLabel('action-Action.Link-Edit record-update-general-table-0').click();
await page
.getByLabel(`block-item-CollectionField-general-form-general.oneToOneBelongsTo-oneToOneBelongsTo`)
.hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.oneToOneBelongsTo`)
.hover();
await page.getByRole('menuitem', { name: 'Set the data scope' }).click();
await page.getByText('Add condition', { exact: true }).click();
await page.getByTestId('select-filter-field').click();
await page.getByRole('menuitemcheckbox', { name: 'ID', exact: true }).click();
await page.getByRole('spinbutton').click();
await page.getByRole('spinbutton').fill(String(recordsOfUser[0].id));
// 测试下可选择的变量有哪些
await page.getByLabel('variable-button').click();
await expectSupportedVariables(page, [
'Constant',
'Current user',
'Current role',
'Date variables',
'Current form',
]);
await page.getByLabel('variable-button').click();
await page.getByRole('button', { name: 'OK', exact: true }).click();
// 再次打开弹窗,设置的值应该还在
await (async (page: Page, fieldName: string) => {
await page.getByLabel(`block-item-CollectionField-general-form-general.${fieldName}-${fieldName}`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'oneToOneBelongsTo');
await page
.getByLabel(`block-item-CollectionField-general-form-general.oneToOneBelongsTo-oneToOneBelongsTo`)
.hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.oneToOneBelongsTo`)
.hover();
await page.getByRole('menuitem', { name: 'Set the data scope' }).click();
await expect(page.getByTestId('select-filter-field')).toHaveText('ID');
await expect(page.getByRole('spinbutton')).toHaveValue(String(recordsOfUser[0].id));

View File

@ -38,28 +38,25 @@ test.describe('form item & create form', () => {
test('set default value', async ({ page, mockPage }) => {
await testDefaultValue({
page,
gotoPage: () =>
(async (mockPage) => {
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndChoicesFields).waitForInit();
await nocoPage.goto();
})(mockPage),
openDialog: () =>
(async (page: Page) => {
await page.getByRole('button', { name: 'Add new' }).click();
})(page),
gotoPage: async () => {
await mockPage(oneTableBlockWithAddNewAndViewAndEditAndChoicesFields).goto();
},
openDialog: async () => {
await page.getByRole('button', { name: 'Add new' }).click();
},
closeDialog: () => page.getByLabel('drawer-Action.Container-general-Add record-mask').click(),
showMenu: () =>
(async (page: Page, fieldName: string) => {
await page
.getByLabel(`block-item-CollectionField-general-form-general.${fieldName}-${fieldName}`, { exact: true })
.hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`, {
exact: true,
})
.hover();
})(page, 'checkbox'),
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
showMenu: async () => {
await page
.getByLabel(`block-item-CollectionField-general-form-general.checkbox-checkbox`, { exact: true })
.hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.checkbox`, {
exact: true,
})
.hover();
},
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
inputConstantValue: async () => {
// 默认应该是没有被选中的,点击后应该被选中
await page.getByLabel('block-item-VariableInput-').getByRole('checkbox').click();

View File

@ -57,7 +57,8 @@ test.describe('form item & create form', () => {
})
.hover();
})(page, 'checkboxGroup'),
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').getByLabel('Option1').click();
},

View File

@ -57,7 +57,8 @@ test.describe('form item & create form', () => {
})
.hover();
})(page, 'chinaRegion'),
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').click();
await page.getByRole('menuitemcheckbox', { name: '北京市' }).click();

View File

@ -55,7 +55,8 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'datetime'),
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').getByPlaceholder('Select date').click();
await page.getByText('Today').click();

View File

@ -53,7 +53,8 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'email'),
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
constantValue: 'test@nocobase.com',
variableValue: ['Current user', 'Email'],
expectConstantValue: () =>

View File

@ -2,6 +2,7 @@ import {
Page,
expect,
expectSettingsMenu,
expectSupportedVariables,
mockUserRecordsWithoutDepartments,
oneFilterFormBlockWithAllAssociationFields,
oneTableBlockWithAddNewAndViewAndEditAndAssociationFields,
@ -111,37 +112,40 @@ test.describe('form item & create form', () => {
});
test('Set the data scope', async ({ page, mockPage, mockRecords }) => {
const records = await (async (mockPage, mockRecords) => {
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndAssociationFields).waitForInit();
const recordsOfUser = await mockUserRecordsWithoutDepartments(mockRecords, 3);
await nocoPage.goto();
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndAssociationFields).waitForInit();
const records = await mockUserRecordsWithoutDepartments(mockRecords, 3);
await nocoPage.goto();
return recordsOfUser;
})(mockPage, mockRecords);
await (async (page: Page) => {
await page.getByRole('button', { name: 'Add new' }).click();
})(page);
await (async (page: Page, fieldName: string) => {
await page.getByLabel(`block-item-CollectionField-general-form-general.${fieldName}-${fieldName}`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'oneToOneHasOne');
await page.getByRole('button', { name: 'Add new' }).click();
await page.getByLabel(`block-item-CollectionField-general-form-general.oneToOneHasOne-oneToOneHasOne`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.oneToOneHasOne`)
.hover();
await page.getByRole('menuitem', { name: 'Set the data scope' }).click();
await page.getByText('Add condition', { exact: true }).click();
await page.getByTestId('select-filter-field').click();
await page.getByRole('menuitemcheckbox', { name: 'ID', exact: true }).click();
await page.getByRole('spinbutton').click();
await page.getByRole('spinbutton').fill(String(records[0].id));
// 测试下可选择的变量有哪些
await page.getByLabel('variable-button').click();
await expectSupportedVariables(page, [
'Constant',
'Current user',
'Current role',
'Date variables',
'Current form',
]);
await page.getByLabel('variable-button').click();
await page.getByRole('button', { name: 'OK', exact: true }).click();
// 再次打开弹窗,设置的值应该还在
await (async (page: Page, fieldName: string) => {
await page.getByLabel(`block-item-CollectionField-general-form-general.${fieldName}-${fieldName}`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'oneToOneHasOne');
await page.getByLabel(`block-item-CollectionField-general-form-general.oneToOneHasOne-oneToOneHasOne`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.oneToOneHasOne`)
.hover();
await page.getByRole('menuitem', { name: 'Set the data scope' }).click();
await expect(page.getByTestId('select-filter-field')).toHaveText('ID');
await expect(page.getByRole('spinbutton')).toHaveValue(String(records[0].id));
@ -309,38 +313,41 @@ test.describe('form item & edit form', () => {
});
test('Set the data scope', async ({ page, mockPage, mockRecords }) => {
await (async (mockPage, mockRecords) => {
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndAssociationFields).waitForInit();
const recordsOfUser = await mockUserRecordsWithoutDepartments(mockRecords, 3);
const record = (await mockRecords('general', 1))[0];
await nocoPage.goto();
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndAssociationFields).waitForInit();
await mockUserRecordsWithoutDepartments(mockRecords, 3);
await mockRecords('general', 1);
await nocoPage.goto();
return { record, recordsOfUser };
})(mockPage, mockRecords);
await (async (page: Page) => {
await page.getByLabel('action-Action.Link-Edit record-update-general-table-0').click();
})(page);
await (async (page: Page, fieldName: string) => {
await page.getByLabel(`block-item-CollectionField-general-form-general.${fieldName}-${fieldName}`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'oneToOneHasOne');
await page.getByLabel('action-Action.Link-Edit record-update-general-table-0').click();
await page.getByLabel(`block-item-CollectionField-general-form-general.oneToOneHasOne-oneToOneHasOne`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.oneToOneHasOne`)
.hover();
await page.getByRole('menuitem', { name: 'Set the data scope' }).click();
await page.getByText('Add condition', { exact: true }).click();
await page.getByTestId('select-filter-field').click();
await page.getByRole('menuitemcheckbox', { name: 'ID', exact: true }).click();
await page.getByRole('spinbutton').click();
await page.getByRole('spinbutton').fill('1');
// 测试下可选择的变量有哪些
await page.getByLabel('variable-button').click();
await expectSupportedVariables(page, [
'Constant',
'Current user',
'Current role',
'Date variables',
'Current form',
]);
await page.getByLabel('variable-button').click();
await page.getByRole('button', { name: 'OK', exact: true }).click();
// 再次打开弹窗,设置的值应该还在
await (async (page: Page, fieldName: string) => {
await page.getByLabel(`block-item-CollectionField-general-form-general.${fieldName}-${fieldName}`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'oneToOneHasOne');
await page.getByLabel(`block-item-CollectionField-general-form-general.oneToOneHasOne-oneToOneHasOne`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.oneToOneHasOne`)
.hover();
await page.getByRole('menuitem', { name: 'Set the data scope' }).click();
await expect(page.getByTestId('select-filter-field')).toHaveText('ID');
await expect(page.getByRole('spinbutton')).toHaveValue('1');

View File

@ -53,7 +53,8 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'icon'),
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').getByRole('button', { name: 'Select icon' }).click();
await page.getByLabel('account-book').locator('svg').click();

View File

@ -54,7 +54,8 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'integer'),
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
variableValue: ['Current user', 'ID'], // 值为 1
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').getByRole('spinbutton').click();

View File

@ -56,7 +56,8 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'longText'),
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
constantValue: 'test long text',
variableValue: ['Current user', 'Email'], // 值为 admin@nocobase.com
expectConstantValue: async () => {

View File

@ -2,6 +2,7 @@ import {
Page,
expect,
expectSettingsMenu,
expectSupportedVariables,
mockUserRecordsWithoutDepartments,
oneTableBlockWithAddNewAndViewAndEditAndAssociationFields,
test,
@ -66,7 +67,8 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'manyToMany'),
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').getByTestId('select-object-multiple').click();
await page.getByRole('option', { name: String(recordsOfUser[0].id), exact: true }).click();
@ -132,37 +134,40 @@ test.describe('form item & create form', () => {
});
test('Set the data scope', async ({ page, mockPage, mockRecords }) => {
const records = await (async (mockPage, mockRecords) => {
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndAssociationFields).waitForInit();
const recordsOfUser = await mockUserRecordsWithoutDepartments(mockRecords, 3);
await nocoPage.goto();
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndAssociationFields).waitForInit();
const records = await mockUserRecordsWithoutDepartments(mockRecords, 3);
await nocoPage.goto();
return recordsOfUser;
})(mockPage, mockRecords);
await (async (page: Page) => {
await page.getByRole('button', { name: 'Add new' }).click();
})(page);
await (async (page: Page, fieldName: string) => {
await page.getByLabel(`block-item-CollectionField-general-form-general.${fieldName}-${fieldName}`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'manyToMany');
await page.getByRole('button', { name: 'Add new' }).click();
await page.getByLabel(`block-item-CollectionField-general-form-general.manyToMany-manyToMany`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.manyToMany`)
.hover();
await page.getByRole('menuitem', { name: 'Set the data scope' }).click();
await page.getByText('Add condition', { exact: true }).click();
await page.getByTestId('select-filter-field').click();
await page.getByRole('menuitemcheckbox', { name: 'ID', exact: true }).click();
await page.getByRole('spinbutton').click();
await page.getByRole('spinbutton').fill(String(records[0].id));
// 测试下可选择的变量有哪些
await page.getByLabel('variable-button').click();
await expectSupportedVariables(page, [
'Constant',
'Current user',
'Current role',
'Date variables',
'Current form',
]);
await page.getByLabel('variable-button').click();
await page.getByRole('button', { name: 'OK', exact: true }).click();
// 再次打开弹窗,设置的值应该还在
await (async (page: Page, fieldName: string) => {
await page.getByLabel(`block-item-CollectionField-general-form-general.${fieldName}-${fieldName}`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'manyToMany');
await page.getByLabel(`block-item-CollectionField-general-form-general.manyToMany-manyToMany`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.manyToMany`)
.hover();
await page.getByRole('menuitem', { name: 'Set the data scope' }).click();
await expect(page.getByTestId('select-filter-field')).toHaveText('ID');
await expect(page.getByRole('spinbutton')).toHaveValue(String(records[0].id));

View File

@ -2,6 +2,7 @@ import {
Page,
expect,
expectSettingsMenu,
expectSupportedVariables,
mockUserRecordsWithoutDepartments,
oneTableBlockWithAddNewAndViewAndEditAndAssociationFields,
test,
@ -94,38 +95,41 @@ test.describe('form item & edit form', () => {
});
test('Set the data scope', async ({ page, mockPage, mockRecords }) => {
const { recordsOfUser } = await (async (mockPage, mockRecords) => {
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndAssociationFields).waitForInit();
const recordsOfUser = await mockUserRecordsWithoutDepartments(mockRecords, 3);
const record = (await mockRecords('general', 1))[0];
await nocoPage.goto();
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndAssociationFields).waitForInit();
const recordsOfUser = await mockUserRecordsWithoutDepartments(mockRecords, 3);
await mockRecords('general', 1);
await nocoPage.goto();
return { record, recordsOfUser };
})(mockPage, mockRecords);
await (async (page: Page) => {
await page.getByLabel('action-Action.Link-Edit record-update-general-table-0').click();
})(page);
await (async (page: Page, fieldName: string) => {
await page.getByLabel(`block-item-CollectionField-general-form-general.${fieldName}-${fieldName}`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'manyToMany');
await page.getByLabel('action-Action.Link-Edit record-update-general-table-0').click();
await page.getByLabel(`block-item-CollectionField-general-form-general.manyToMany-manyToMany`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.manyToMany`)
.hover();
await page.getByRole('menuitem', { name: 'Set the data scope' }).click();
await page.getByText('Add condition', { exact: true }).click();
await page.getByTestId('select-filter-field').click();
await page.getByRole('menuitemcheckbox', { name: 'ID', exact: true }).click();
await page.getByRole('spinbutton').click();
await page.getByRole('spinbutton').fill(String(recordsOfUser[0].id));
// 测试下可选择的变量有哪些
await page.getByLabel('variable-button').click();
await expectSupportedVariables(page, [
'Constant',
'Current user',
'Current role',
'Date variables',
'Current form',
]);
await page.getByLabel('variable-button').click();
await page.getByRole('button', { name: 'OK', exact: true }).click();
// 再次打开弹窗,设置的值应该还在
await (async (page: Page, fieldName: string) => {
await page.getByLabel(`block-item-CollectionField-general-form-general.${fieldName}-${fieldName}`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'manyToMany');
await page.getByLabel(`block-item-CollectionField-general-form-general.manyToMany-manyToMany`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.manyToMany`)
.hover();
await page.getByRole('menuitem', { name: 'Set the data scope' }).click();
await expect(page.getByTestId('select-filter-field')).toHaveText('ID');
await expect(page.getByRole('spinbutton')).toHaveValue(String(recordsOfUser[0].id));

View File

@ -2,6 +2,7 @@ import {
Page,
expect,
expectSettingsMenu,
expectSupportedVariables,
mockUserRecordsWithoutDepartments,
oneFilterFormBlockWithAllAssociationFields,
oneTableBlockWithAddNewAndViewAndEditAndAssociationFields,
@ -67,7 +68,8 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'manyToOne'),
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
inputConstantValue: async () => {
await page
.getByLabel('block-item-VariableInput-')
@ -144,37 +146,40 @@ test.describe('form item & create form', () => {
});
test('Set the data scope', async ({ page, mockPage, mockRecords }) => {
const records = await (async (mockPage, mockRecords) => {
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndAssociationFields).waitForInit();
const recordsOfUser = await mockUserRecordsWithoutDepartments(mockRecords, 3);
await nocoPage.goto();
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndAssociationFields).waitForInit();
const records = await mockUserRecordsWithoutDepartments(mockRecords, 3);
await nocoPage.goto();
return recordsOfUser;
})(mockPage, mockRecords);
await (async (page: Page) => {
await page.getByRole('button', { name: 'Add new' }).click();
})(page);
await (async (page: Page, fieldName: string) => {
await page.getByLabel(`block-item-CollectionField-general-form-general.${fieldName}-${fieldName}`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'manyToOne');
await page.getByRole('button', { name: 'Add new' }).click();
await page.getByLabel(`block-item-CollectionField-general-form-general.manyToOne-manyToOne`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.manyToOne`)
.hover();
await page.getByRole('menuitem', { name: 'Set the data scope' }).click();
await page.getByText('Add condition', { exact: true }).click();
await page.getByTestId('select-filter-field').click();
await page.getByRole('menuitemcheckbox', { name: 'ID', exact: true }).click();
await page.getByRole('spinbutton').click();
await page.getByRole('spinbutton').fill(String(records[0].id));
// 测试下可选择的变量有哪些
await page.getByLabel('variable-button').click();
await expectSupportedVariables(page, [
'Constant',
'Current user',
'Current role',
'Date variables',
'Current form',
]);
await page.getByLabel('variable-button').click();
await page.getByRole('button', { name: 'OK', exact: true }).click();
// 再次打开弹窗,设置的值应该还在
await (async (page: Page, fieldName: string) => {
await page.getByLabel(`block-item-CollectionField-general-form-general.${fieldName}-${fieldName}`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'manyToOne');
await page.getByLabel(`block-item-CollectionField-general-form-general.manyToOne-manyToOne`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.manyToOne`)
.hover();
await page.getByRole('menuitem', { name: 'Set the data scope' }).click();
await expect(page.getByTestId('select-filter-field')).toHaveText('ID');
await expect(page.getByRole('spinbutton')).toHaveValue(String(records[0].id));
@ -342,38 +347,41 @@ test.describe('form item & edit form', () => {
});
test('Set the data scope', async ({ page, mockPage, mockRecords }) => {
const { recordsOfUser } = await (async (mockPage, mockRecords) => {
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndAssociationFields).waitForInit();
const recordsOfUser = await mockUserRecordsWithoutDepartments(mockRecords, 3);
const record = (await mockRecords('general', 1))[0];
await nocoPage.goto();
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndAssociationFields).waitForInit();
const recordsOfUser = await mockUserRecordsWithoutDepartments(mockRecords, 3);
await mockRecords('general', 1);
await nocoPage.goto();
return { record, recordsOfUser };
})(mockPage, mockRecords);
await (async (page: Page) => {
await page.getByLabel('action-Action.Link-Edit record-update-general-table-0').click();
})(page);
await (async (page: Page, fieldName: string) => {
await page.getByLabel(`block-item-CollectionField-general-form-general.${fieldName}-${fieldName}`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'manyToOne');
await page.getByLabel('action-Action.Link-Edit record-update-general-table-0').click();
await page.getByLabel(`block-item-CollectionField-general-form-general.manyToOne-manyToOne`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.manyToOne`)
.hover();
await page.getByRole('menuitem', { name: 'Set the data scope' }).click();
await page.getByText('Add condition', { exact: true }).click();
await page.getByTestId('select-filter-field').click();
await page.getByRole('menuitemcheckbox', { name: 'ID', exact: true }).click();
await page.getByRole('spinbutton').click();
await page.getByRole('spinbutton').fill(String(recordsOfUser[0].id));
// 测试下可选择的变量有哪些
await page.getByLabel('variable-button').click();
await expectSupportedVariables(page, [
'Constant',
'Current user',
'Current role',
'Date variables',
'Current form',
]);
await page.getByLabel('variable-button').click();
await page.getByRole('button', { name: 'OK', exact: true }).click();
// 再次打开弹窗,设置的值应该还在
await (async (page: Page, fieldName: string) => {
await page.getByLabel(`block-item-CollectionField-general-form-general.${fieldName}-${fieldName}`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'manyToOne');
await page.getByLabel(`block-item-CollectionField-general-form-general.manyToOne-manyToOne`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.manyToOne`)
.hover();
await page.getByRole('menuitem', { name: 'Set the data scope' }).click();
await expect(page.getByTestId('select-filter-field')).toHaveText('ID');
await expect(page.getByRole('spinbutton')).toHaveValue(String(recordsOfUser[0].id));

View File

@ -53,7 +53,8 @@ test.describe('form item & create form', () => {
})
.hover();
},
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
constantValue: 'test markdown',
expectConstantValue: async () => {
await expect(

View File

@ -57,7 +57,8 @@ test.describe('form item & create form', () => {
})
.hover();
})(page, 'multipleSelect'),
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').getByTestId('select-multiple').click();
await page.getByRole('option', { name: 'Option1' }).click();

View File

@ -54,7 +54,8 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'number'),
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').getByRole('spinbutton').click();
await page.getByLabel('block-item-VariableInput-').getByRole('spinbutton').fill('11.22');

View File

@ -2,6 +2,7 @@ import {
Page,
expect,
expectSettingsMenu,
expectSupportedVariables,
mockUserRecordsWithoutDepartments,
oneFilterFormBlockWithAllAssociationFields,
oneTableBlockWithAddNewAndViewAndEditAndAssociationFields,
@ -110,37 +111,40 @@ test.describe('form item & create form', () => {
});
test('Set the data scope', async ({ page, mockPage, mockRecords }) => {
const records = await (async (mockPage, mockRecords) => {
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndAssociationFields).waitForInit();
const recordsOfUser = await mockUserRecordsWithoutDepartments(mockRecords, 3);
await nocoPage.goto();
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndAssociationFields).waitForInit();
const records = await mockUserRecordsWithoutDepartments(mockRecords, 3);
await nocoPage.goto();
return recordsOfUser;
})(mockPage, mockRecords);
await (async (page: Page) => {
await page.getByRole('button', { name: 'Add new' }).click();
})(page);
await (async (page: Page, fieldName: string) => {
await page.getByLabel(`block-item-CollectionField-general-form-general.${fieldName}-${fieldName}`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'oneToMany');
await page.getByRole('button', { name: 'Add new' }).click();
await page.getByLabel(`block-item-CollectionField-general-form-general.oneToMany-oneToMany`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.oneToMany`)
.hover();
await page.getByRole('menuitem', { name: 'Set the data scope' }).click();
await page.getByText('Add condition', { exact: true }).click();
await page.getByTestId('select-filter-field').click();
await page.getByRole('menuitemcheckbox', { name: 'ID', exact: true }).click();
await page.getByRole('spinbutton').click();
await page.getByRole('spinbutton').fill(String(records[0].id));
// 测试下可选择的变量有哪些
await page.getByLabel('variable-button').click();
await expectSupportedVariables(page, [
'Constant',
'Current user',
'Current role',
'Date variables',
'Current form',
]);
await page.getByLabel('variable-button').click();
await page.getByRole('button', { name: 'OK', exact: true }).click();
// 再次打开弹窗,设置的值应该还在
await (async (page: Page, fieldName: string) => {
await page.getByLabel(`block-item-CollectionField-general-form-general.${fieldName}-${fieldName}`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'oneToMany');
await page.getByLabel(`block-item-CollectionField-general-form-general.oneToMany-oneToMany`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.oneToMany`)
.hover();
await page.getByRole('menuitem', { name: 'Set the data scope' }).click();
await expect(page.getByTestId('select-filter-field')).toHaveText('ID');
await expect(page.getByRole('spinbutton')).toHaveValue(String(records[0].id));
@ -330,38 +334,41 @@ test.describe('form item & edit form', () => {
});
test('Set the data scope', async ({ page, mockPage, mockRecords }) => {
const { record } = await (async (mockPage, mockRecords) => {
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndAssociationFields).waitForInit();
const recordsOfUser = await mockUserRecordsWithoutDepartments(mockRecords, 3);
const record = (await mockRecords('general', 1))[0];
await nocoPage.goto();
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndAssociationFields).waitForInit();
await mockUserRecordsWithoutDepartments(mockRecords, 3);
const record = (await mockRecords('general', 1))[0];
await nocoPage.goto();
return { record, recordsOfUser };
})(mockPage, mockRecords);
await (async (page: Page) => {
await page.getByLabel('action-Action.Link-Edit record-update-general-table-0').click();
})(page);
await (async (page: Page, fieldName: string) => {
await page.getByLabel(`block-item-CollectionField-general-form-general.${fieldName}-${fieldName}`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'oneToMany');
await page.getByLabel('action-Action.Link-Edit record-update-general-table-0').click();
await page.getByLabel(`block-item-CollectionField-general-form-general.oneToMany-oneToMany`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.oneToMany`)
.hover();
await page.getByRole('menuitem', { name: 'Set the data scope' }).click();
await page.getByText('Add condition', { exact: true }).click();
await page.getByTestId('select-filter-field').click();
await page.getByRole('menuitemcheckbox', { name: 'ID', exact: true }).click();
await page.getByRole('spinbutton').click();
await page.getByRole('spinbutton').fill('1');
// 测试下可选择的变量有哪些
await page.getByLabel('variable-button').click();
await expectSupportedVariables(page, [
'Constant',
'Current user',
'Current role',
'Date variables',
'Current form',
]);
await page.getByLabel('variable-button').click();
await page.getByRole('button', { name: 'OK', exact: true }).click();
// 再次打开弹窗,设置的值应该还在
await (async (page: Page, fieldName: string) => {
await page.getByLabel(`block-item-CollectionField-general-form-general.${fieldName}-${fieldName}`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'oneToMany');
await page.getByLabel(`block-item-CollectionField-general-form-general.oneToMany-oneToMany`).hover();
await page
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.oneToMany`)
.hover();
await page.getByRole('menuitem', { name: 'Set the data scope' }).click();
await expect(page.getByTestId('select-filter-field')).toHaveText('ID');
await expect(page.getByRole('spinbutton')).toHaveValue('1');

View File

@ -54,7 +54,8 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'password'),
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
constantValue: 'test112233password',
variableValue: ['Current user', 'Email'], // 值为 admin@nocobase.com
expectConstantValue: async () => {

View File

@ -54,7 +54,8 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'percent'),
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').getByRole('spinbutton').click();
await page.getByLabel('block-item-VariableInput-').getByRole('spinbutton').fill('11.22');

View File

@ -53,7 +53,8 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'phone'),
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
constantValue: '17777777777',
variableValue: ['Current user', 'ID'], // 值为 1
expectConstantValue: async () => {

View File

@ -57,7 +57,8 @@ test.describe('form item & create form', () => {
})
.hover();
})(page, 'radioGroup'),
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').getByLabel('Option2').click();
},

View File

@ -53,7 +53,8 @@ test.describe('form item & create form', () => {
})
.hover();
},
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').locator('.ql-editor').click();
await page.keyboard.type('test rich text');

View File

@ -4,6 +4,7 @@ import {
expectSettingsMenu,
oneTableBlockWithAddNewAndViewAndEditAndBasicFields,
oneTableBlockWithAddNewAndViewAndEditAndBasicFieldsAndSubTable,
oneTableBlockWithEditAndSubForm,
test,
} from '@nocobase/test/e2e';
import { createColumnItem, showSettingsMenu, testDefaultValue, testPattern, testSetValidationRules } from '../../utils';
@ -52,7 +53,8 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.singleLineText`)
.hover();
},
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
constantValue: 'test single line text',
variableValue: ['Current user', 'Email'], // 值为 admin@nocobase.com
expectConstantValue: async () => {
@ -254,6 +256,56 @@ test.describe('form item & edit form', () => {
});
});
test.describe('form item & sub form', () => {
test('set default value', async ({ page, mockPage, mockRecord }) => {
let record;
await testDefaultValue({
page,
async gotoPage() {
const nocoPage = await mockPage(oneTableBlockWithEditAndSubForm).waitForInit();
record = await mockRecord('subform');
await nocoPage.goto();
},
async openDialog() {
await page.getByLabel('action-Action.Link-Edit record-update-subform-table-0').click();
},
async closeDialog() {
await page.getByLabel('drawer-Action.Container-subform-Edit record-mask').click();
},
async showMenu() {
await page.getByLabel('block-item-CollectionField-').nth(1).hover();
await page
.getByRole('button', {
name: 'designer-schema-settings-CollectionField-fieldSettings:FormItem-general-general',
})
.hover();
},
supportedVariables: [
'Constant',
'Current user',
'Current role',
'Date variables',
'Current form',
'Current object',
'Current popup record',
],
variableValue: ['Current user', 'Nickname'],
expectVariableValue: async () => {
await page
.getByLabel('block-item-CollectionField-subform-form-subform.manyToMany-manyToMany')
.getByRole('img', { name: 'plus' })
.first()
.click();
// 在第一条数据下面增加一条数据
await expect(page.getByLabel('block-item-CollectionField-').nth(2).getByRole('textbox')).toHaveValue(
'Super Admin',
);
},
});
});
});
test.describe('form item & view form', () => {
test('supported options', async ({ page, mockPage, mockRecord }) => {
const nocoPage = await mockPage(oneTableBlockWithAddNewAndViewAndEditAndBasicFields).waitForInit();
@ -409,13 +461,13 @@ test.describe('table column & sub-table in edit form', () => {
await page.getByRole('button', { name: 'singleLineText', exact: true }).hover();
await page.getByLabel('designer-schema-settings-TableV2.Column-TableV2.Column.Designer-general').hover();
},
supportVariables: [
supportedVariables: [
'Constant',
'Current user',
'Current role',
'Current form',
'Current object',
// 'Current record',
'Current popup record',
],
variableValue: ['Current user', 'Nickname'],
expectVariableValue: async () => {

View File

@ -57,7 +57,8 @@ test.describe('form item & create form', () => {
})
.hover();
})(page, 'singleSelect'),
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').click();
await page.getByRole('option', { name: 'Option1' }).click();

View File

@ -52,7 +52,8 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.time`)
.hover();
},
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
inputConstantValue: async () => {
await page.getByLabel('block-item-VariableInput-').getByPlaceholder('Select time').click();
await page.getByText('Now').click();

View File

@ -53,7 +53,8 @@ test.describe('form item & create form', () => {
.getByLabel(`designer-schema-settings-CollectionField-FormItem.Designer-general-general.${fieldName}`)
.hover();
})(page, 'url'),
supportVariables: ['Constant', 'Current user', 'Date variables', 'Current form'],
supportedVariables: ['Constant', 'Current user', 'Current role', 'Date variables', 'Current form'],
unsupportedVariables: ['Current popup record'],
constantValue: 'https://nocobase.com',
variableValue: ['Current user', 'Email'], // 值为 admin@nocobase.com
expectConstantValue: async () => {

View File

@ -54,7 +54,8 @@ export async function testDefaultValue({
closeDialog,
gotoPage,
showMenu,
supportVariables,
supportedVariables,
unsupportedVariables,
constantValue,
variableValue,
inputConstantValue,
@ -67,7 +68,9 @@ export async function testDefaultValue({
gotoPage: () => Promise<void>;
showMenu: () => Promise<void>;
/** 支持的变量列表,如:['Current user', 'Date variables', 'Current form'] */
supportVariables: string[];
supportedVariables: string[];
/** 不应该显示出来的变量列表 */
unsupportedVariables?: string[];
/** 常量默认值 */
constantValue?: string | number;
/** 变量默认值 */
@ -81,10 +84,10 @@ export async function testDefaultValue({
}) {
await gotoPage();
await openDialog();
await showMenu();
// 设置一个常量作为默认值
if (constantValue || inputConstantValue) {
// 设置一个常量作为默认值
await showMenu();
await page.getByRole('menuitem', { name: 'Set default value' }).click();
if (inputConstantValue) {
await inputConstantValue();
@ -92,6 +95,14 @@ export async function testDefaultValue({
await page.getByLabel('block-item-VariableInput-').getByRole('textbox').click();
await page.getByLabel('block-item-VariableInput-').getByRole('textbox').fill(String(constantValue));
}
if (supportedVariables || unsupportedVariables) {
await page.getByLabel('variable-button').click();
await testSupportedAndUnsupportedVariables(page, supportedVariables, unsupportedVariables);
// 关闭变量列表
await page.getByLabel('variable-button').click();
}
await page.getByRole('button', { name: 'OK', exact: true }).click();
// 关闭弹窗,然后再次打开后,应该显示刚才设置的默认值
@ -100,14 +111,12 @@ export async function testDefaultValue({
await expectConstantValue?.();
}
// 设置一个变量作为默认值
if (variableValue) {
// 设置一个变量作为默认值
await showMenu();
await page.getByRole('menuitem', { name: 'Set default value' }).click();
await page.getByLabel('variable-button').click();
for (const value of supportVariables) {
await expect(page.getByRole('menuitemcheckbox', { name: value })).toBeVisible();
}
await testSupportedAndUnsupportedVariables(page, supportedVariables, unsupportedVariables);
for (const value of variableValue) {
await page.getByRole('menuitemcheckbox', { name: value }).click();
}
@ -119,6 +128,19 @@ export async function testDefaultValue({
}
}
async function testSupportedAndUnsupportedVariables(
page: Page,
supportedVariables: string[],
unsupportedVariables: string[],
) {
for (const value of supportedVariables) {
await expect(page.getByRole('menuitemcheckbox', { name: value })).toBeVisible();
}
for (const value of unsupportedVariables || []) {
await expect(page.getByRole('menuitemcheckbox', { name: value })).not.toBeVisible();
}
}
export async function testPattern({
page,
gotoPage,
@ -217,7 +239,9 @@ export class CollectionManagerPage {
* @returns
*/
async configureFields(collectionName: string) {
await this.page.getByLabel(`action-Action.Link-Configure fields-collections-${collectionName}`).click();
await this.page
.getByLabel(`action-Action.Link-Configure fields-collections-${collectionName}`, { exact: true })
.click();
return new FieldsSettings(this.page);
}