diff --git a/packages/plugins/@nocobase/plugin-map/src/client/__e2e__/schemaInitializer.test.ts b/packages/plugins/@nocobase/plugin-map/src/client/__e2e__/schemaInitializer.test.ts new file mode 100644 index 0000000000..051f37192c --- /dev/null +++ b/packages/plugins/@nocobase/plugin-map/src/client/__e2e__/schemaInitializer.test.ts @@ -0,0 +1,48 @@ +import { expect, test } from '@nocobase/test/e2e'; +import { oneTableWithMap } from './templates'; + +test.describe('where map block can be added', () => { + test('page & popup', async ({ page, mockPage }) => { + const nocoPage = await mockPage(oneTableWithMap).waitForInit(); + await nocoPage.goto(); + + // 1. 在页面中添加地图区块,因为没有配置 Access key 等信息,所以会显示错误提示 + await page.getByLabel('schema-initializer-Grid-page:').hover(); + await page.getByRole('menuitem', { name: 'table Map right' }).hover(); + await page.getByRole('menuitem', { name: 'map', exact: true }).click(); + await page.getByRole('button', { name: 'OK', exact: true }).click(); + await expect( + page + .getByLabel('block-item-CardItem-map-map') + .getByText('Please configure the AccessKey and SecurityJsCode first'), + ).toBeVisible(); + + // 2. 点击跳转按钮去配置页面,配置好后返回刚才的页面,应该能正常显示地图 + await page.getByRole('button', { name: 'Go to the configuration page' }).click(); + if (await page.getByRole('button', { name: 'Edit' }).isVisible()) { + await page.getByRole('button', { name: 'Edit' }).click(); + } + await page.getByLabel('Access key').click(); + await page.getByLabel('Access key').fill('9717a70e44273882bcf5489f72b4e261'); + await page.getByLabel('securityJsCode or serviceHost').click(); + await page.getByLabel('securityJsCode or serviceHost').fill('6876ed2d3a6168b75c4fba852e16c99c'); + await page.getByRole('button', { name: 'Save' }).click(); + await expect(page.locator('.ant-message-notice').getByText('Saved successfully')).toBeVisible(); + await nocoPage.goto(); + await expect(page.getByLabel('block-item-CardItem-map-map').locator('.amap-layer')).toBeVisible(); + + // 3. 在弹窗中添加地图区块,应该能正常显示地图 + await page.getByLabel('block-item-CardItem-map-table').getByLabel('action-Action-Add new-create-').click(); + await page.getByLabel('schema-initializer-Grid-form:').hover(); + await page.getByRole('menuitem', { name: 'point' }).click(); + await expect(page.getByLabel('block-item-CollectionField-').locator('.amap-layer')).toBeVisible(); + + // 4. 最后把地图的设置清空,以免影响到其它测试 + await page.goto('/admin/settings/map'); + await page.getByRole('button', { name: 'Edit' }).click(); + await page.getByLabel('Access key').clear(); + await page.getByLabel('securityJsCode or serviceHost').clear(); + await page.getByRole('button', { name: 'Save' }).click(); + await expect(page.locator('.ant-message-notice').getByText('Saved successfully')).toBeVisible(); + }); +}); diff --git a/packages/plugins/@nocobase/plugin-map/src/client/__e2e__/templates.ts b/packages/plugins/@nocobase/plugin-map/src/client/__e2e__/templates.ts new file mode 100644 index 0000000000..6c20ac9d65 --- /dev/null +++ b/packages/plugins/@nocobase/plugin-map/src/client/__e2e__/templates.ts @@ -0,0 +1,338 @@ +export const oneTableWithMap = { + collections: [ + { + name: 'map', + fields: [ + { + name: 'point', + interface: 'point', + }, + ], + }, + ], + pageSchema: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Page', + 'x-app-version': '0.21.0-alpha.15', + properties: { + kkw0yhoj2v7: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid', + 'x-initializer': 'page:addBlock', + 'x-app-version': '0.21.0-alpha.15', + properties: { + '9i8fyfb05dd': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + 'x-app-version': '0.21.0-alpha.15', + properties: { + '608qygaww2u': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Col', + 'x-app-version': '0.21.0-alpha.15', + properties: { + nokibo5w37z: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-decorator': 'TableBlockProvider', + 'x-acl-action': 'map:list', + 'x-use-decorator-props': 'useTableBlockDecoratorProps', + 'x-decorator-props': { + collection: 'map', + 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', + properties: { + uip6al0wpnq: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-action': 'create', + 'x-acl-action': 'create', + title: "{{t('Add new')}}", + 'x-toolbar': 'ActionSchemaToolbar', + 'x-settings': 'actionSettings:addNew', + 'x-component': 'Action', + 'x-decorator': 'ACLActionProvider', + 'x-component-props': { + openMode: 'drawer', + type: 'primary', + component: 'CreateRecordAction', + icon: 'PlusOutlined', + }, + 'x-align': 'right', + 'x-acl-action-props': { + skipScopeCheck: true, + }, + 'x-app-version': '0.21.0-alpha.15', + properties: { + drawer: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + title: '{{ t("Add record") }}', + 'x-component': 'Action.Container', + 'x-component-props': { + className: 'nb-action-popup', + }, + 'x-app-version': '0.21.0-alpha.15', + properties: { + tabs: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Tabs', + 'x-component-props': {}, + 'x-initializer': 'popup:addTab', + 'x-initializer-props': { + gridInitializer: 'popup:addNew:addBlock', + }, + 'x-app-version': '0.21.0-alpha.15', + properties: { + tab1: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + title: '{{t("Add new")}}', + 'x-component': 'Tabs.TabPane', + 'x-designer': 'Tabs.Designer', + 'x-component-props': {}, + 'x-app-version': '0.21.0-alpha.15', + properties: { + grid: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid', + 'x-initializer': 'popup:addNew:addBlock', + 'x-app-version': '0.21.0-alpha.15', + properties: { + kb4pfm2qld1: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Row', + 'x-app-version': '0.21.0-alpha.15', + properties: { + hoexd0g3zng: { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'Grid.Col', + 'x-app-version': '0.21.0-alpha.15', + properties: { + '3dmeorgypjr': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-acl-action-props': { + skipScopeCheck: true, + }, + 'x-acl-action': 'map:create', + 'x-decorator': 'FormBlockProvider', + 'x-use-decorator-props': 'useCreateFormBlockDecoratorProps', + 'x-decorator-props': { + dataSource: 'main', + collection: 'map', + }, + 'x-toolbar': 'BlockSchemaToolbar', + 'x-settings': 'blockSettings:createForm', + 'x-component': 'CardItem', + 'x-app-version': '0.21.0-alpha.15', + properties: { + '8ijqvnv7ipr': { + _isJSONSchemaObject: true, + version: '2.0', + type: 'void', + 'x-component': 'FormV2', + 'x-use-component-props': 'useCreateFormBlockProps', + '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', + 'x-uid': 'nhb5ckrojg8', + 'x-async': false, + 'x-index': 1, + }, + cn3spxefyf0: { + _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-uid': 'rowvzprfdip', + 'x-async': false, + 'x-index': 2, + }, + }, + 'x-uid': 't3zwje8con4', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'hzqxhqtd8md', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'q6urn5p0yw4', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': '5209bo4teha', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': '50pylphuf3x', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': '45exb2qrbi9', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'ut9rhesppap', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'aiwsk6sq0wx', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'f04owvm9t0f', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'nmpjxsgfxgc', + 'x-async': false, + 'x-index': 1, + }, + fll1bh8w93y: { + _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: { + qyh8y3u567i: { + _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-uid': 'suuyf9afqcg', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'l49nwyyppfy', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'vrdlfpoa7c6', + 'x-async': false, + 'x-index': 2, + }, + }, + 'x-uid': 'ifxjep3ugit', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'tnw8n4rbwhh', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'yrjjp3jl2rg', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': 'sp05st5arhk', + 'x-async': false, + 'x-index': 1, + }, + }, + 'x-uid': '4h4z7pw7j7v', + 'x-async': true, + 'x-index': 1, + }, +};