diff --git a/packages/core/client/src/modules/actions/__e2e__/bulk-destroy/basic.test.ts b/packages/core/client/src/modules/actions/__e2e__/bulk-destroy/basic.test.ts new file mode 100644 index 0000000000..a15686af9c --- /dev/null +++ b/packages/core/client/src/modules/actions/__e2e__/bulk-destroy/basic.test.ts @@ -0,0 +1,47 @@ +import { expect, test } from '@nocobase/test/e2e'; +import { oneTableWithGeneral } from './templates'; + +test.describe('bulk-destroy', () => { + test('in table', async ({ page, mockPage, mockRecords }) => { + const nocoPage = await mockPage(oneTableWithGeneral).waitForInit(); + await mockRecords('general', 3); + await nocoPage.goto(); + + await expect(page.getByLabel('block-item-CardItem-general-').getByText('No data')).not.toBeVisible(); + + // 1. 创建一个批量删除按钮 + await page.getByLabel('schema-initializer-ActionBar-').click(); + await page.getByRole('menuitem', { name: 'Delete' }).click(); + + // 2. 选中所有行 + await page.getByLabel('Select all').check(); + + // 3. 点击批量删除按钮,Table 显示无数据 + await page.getByLabel('action-Action-Delete-destroy-').click(); + await page.getByRole('button', { name: 'OK', exact: true }).click(); + await expect(page.getByLabel('block-item-CardItem-general-').getByText('No data')).toBeVisible(); + }); + + test('Secondary confirmation', async ({ page, mockPage, mockRecords }) => { + const nocoPage = await mockPage(oneTableWithGeneral).waitForInit(); + await mockRecords('general', 3); + await nocoPage.goto(); + + await expect(page.getByLabel('block-item-CardItem-general-').getByText('No data')).not.toBeVisible(); + + // 1. 创建一个批量删除按钮,并关闭二次确认 + await page.getByLabel('schema-initializer-ActionBar-').click(); + await page.getByRole('menuitem', { name: 'Delete' }).click(); + await page.getByLabel('action-Action-Delete-destroy-').hover(); + await page.getByLabel('designer-schema-settings-Action-actionSettings:bulkDelete-general').hover(); + await page.getByRole('menuitem', { name: 'Secondary confirmation' }).click(); + await page.mouse.move(500, 0); + + // 2. 选中所有行 + await page.getByLabel('Select all').check(); + + // 3. 点击批量删除按钮,Table 显示无数据 + await page.getByLabel('action-Action-Delete-destroy-').click(); + await expect(page.getByLabel('block-item-CardItem-general-').getByText('No data')).toBeVisible(); + }); +}); diff --git a/packages/core/client/src/modules/actions/__e2e__/bulk-destroy/templates.ts b/packages/core/client/src/modules/actions/__e2e__/bulk-destroy/templates.ts new file mode 100644 index 0000000000..4c35ecfd15 --- /dev/null +++ b/packages/core/client/src/modules/actions/__e2e__/bulk-destroy/templates.ts @@ -0,0 +1,191 @@ +export const oneTableWithGeneral = { + collections: [ + { + name: 'general', + fields: [ + { + name: 'singleLineText', + interface: 'input', + }, + ], + }, + ], + pageSchema: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Page', + properties: { + '8ss8o5y9v1n': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid', + 'x-initializer': 'page:addBlock', + properties: { + csfo7xx40b3: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + 'x-app-version': '0.21.0-alpha.8', + properties: { + tt2a4eaj8lb: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Col', + 'x-app-version': '0.21.0-alpha.8', + properties: { + '8x94ptxomlt': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-decorator': 'TableBlockProvider', + 'x-acl-action': 'general:list', + 'x-use-decorator-props': 'useTableBlockDecoratorProps', + 'x-decorator-props': { + collection: 'general', + 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.8', + 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.8', + 'x-uid': 'hdwhv0s3ld8', + 'x-async': false, + 'x-index': 1, + }, + cxp0n38cdzh: { + _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.8', + 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.8', + properties: { + gl66zpwpgkc: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-decorator': 'DndContext', + 'x-component': 'Space', + 'x-component-props': { + split: '|', + }, + 'x-app-version': '0.21.0-alpha.8', + 'x-uid': 'zjbyke5x5zq', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'stly3z91277', + 'x-async': false, + 'x-index': 1, + }, + dd7u5egw9ue: { + _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.8', + properties: { + singleLineText: { + _isJSONSchemaObject: true, + version: '2.0', + 'x-collection-field': 'general.singleLineText', + '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.8', + 'x-uid': 'hun0avzussa', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': '9buozxehglu', + 'x-async': false, + 'x-index': 2, + }, + }, + 'x-uid': 'rirrh33p5m8', + 'x-async': false, + 'x-index': 2, + }, + }, + 'x-uid': 'n3j1d0y1a9c', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'eo1qycp0ie2', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': '1xji5q6qrvd', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'cati70644yw', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': '8xohxs7zt2z', + 'x-async': true, + 'x-index': 1, + }, +};