From f411fe59020f70d71ed4be08364c10a350958033 Mon Sep 17 00:00:00 2001 From: hongboji <116709317+hongboji@users.noreply.github.com> Date: Sun, 28 Jul 2024 12:55:47 +0800 Subject: [PATCH 1/3] test: custom action e2e (#4956) --- .../src/e2e/e2ePageObjectModel.ts | 51 +++++++++++++++--- .../plugin-workflow-test/src/e2e/e2eUtils.ts | 54 ++++++++++++++++++- 2 files changed, 98 insertions(+), 7 deletions(-) diff --git a/packages/plugins/@nocobase/plugin-workflow-test/src/e2e/e2ePageObjectModel.ts b/packages/plugins/@nocobase/plugin-workflow-test/src/e2e/e2ePageObjectModel.ts index 2442ad46d..cc861920a 100644 --- a/packages/plugins/@nocobase/plugin-workflow-test/src/e2e/e2ePageObjectModel.ts +++ b/packages/plugins/@nocobase/plugin-workflow-test/src/e2e/e2ePageObjectModel.ts @@ -12,6 +12,8 @@ export class CreateWorkFlow { readonly page: Page; name: Locator; triggerType: Locator; + synchronouslyRadio: Locator; + asynchronouslyRadio: Locator; description: Locator; autoDeleteHistory: Locator; submitButton: Locator; @@ -20,6 +22,8 @@ export class CreateWorkFlow { this.page = page; this.name = page.getByLabel('block-item-CollectionField-workflows-Name').getByRole('textbox'); this.triggerType = page.getByTestId('select-single'); + this.synchronouslyRadio = page.getByLabel('Synchronously', { exact: true }); + this.asynchronouslyRadio = page.getByLabel('Asynchronously', { exact: true }); this.description = page.getByTestId('description-item').getByRole('textbox'); this.autoDeleteHistory = page.getByTestId('select-multiple'); this.submitButton = page.getByLabel('action-Action-Submit-workflows'); @@ -118,7 +122,9 @@ export class ApprovalTriggerNode { this.addBlockButton = page.getByLabel(`schema-initializer-Grid-ApprovalApplyAddBlockButton-${collectionName}`); this.addApplyFormMenu = page.getByRole('menuitem', { name: 'Apply form' }); this.configureFieldsButton = page.getByLabel(`schema-initializer-Grid-form:configureFields-${collectionName}`); - this.configureActionsButton = page.getByLabel(`schema-initializer-ActionBar-ApprovalApplyAddActionButton-${collectionName}`); + this.configureActionsButton = page.getByLabel( + `schema-initializer-ActionBar-ApprovalApplyAddActionButton-${collectionName}`, + ); this.saveDraftSwitch = page.getByRole('menuitem', { name: 'Save draft' }).getByRole('switch'); this.preloadAssociationsDropDown = page.getByTestId('select-field-Preload associations'); this.submitButton = page.getByLabel('action-Action-Submit-workflows'); @@ -170,13 +176,17 @@ export class ApprovalPassthroughModeNode { this.OrRadio = page.getByLabel('Or', { exact: true }); this.AndRadio = page.getByLabel('And', { exact: true }); this.votingRadio = page.getByLabel('Voting', { exact: true }); - this.votingThresholdEditBox = page.getByLabel('block-item-NegotiationConfig-workflows-Negotiation mode').getByRole('spinbutton'); + this.votingThresholdEditBox = page + .getByLabel('block-item-NegotiationConfig-workflows-Negotiation mode') + .getByRole('spinbutton'); this.parallellyRadio = page.getByLabel('Parallelly', { exact: true }); this.sequentiallyRadio = page.getByLabel('Sequentially', { exact: true }); this.goToconfigureButton = page.getByRole('button', { name: 'Go to configure' }); this.addBlockButton = page.getByLabel('schema-initializer-Grid-ApprovalProcessAddBlockButton-workflows'); this.addDetailsMenu = page.getByRole('menuitem', { name: 'Details' }); - this.detailsConfigureFieldsButton = page.getByLabel(`schema-initializer-Grid-details:configureFields-${collectionName}`); + this.detailsConfigureFieldsButton = page.getByLabel( + `schema-initializer-Grid-details:configureFields-${collectionName}`, + ); this.addActionsMenu = page.getByRole('menuitem', { name: 'Actions' }).getByRole('switch'); this.actionsConfigureFieldsButton = page.getByLabel('schema-initializer-Grid-FormItemInitializers-approvalRecords'); this.actionsConfigureActionsButton = page.getByLabel( @@ -239,13 +249,17 @@ export class ApprovalBranchModeNode { this.OrRadio = page.getByLabel('Or', { exact: true }); this.AndRadio = page.getByLabel('And', { exact: true }); this.votingRadio = page.getByLabel('Voting', { exact: true }); - this.votingThresholdEditBox = page.getByLabel('block-item-NegotiationConfig-workflows-Negotiation mode').getByRole('spinbutton'); + this.votingThresholdEditBox = page + .getByLabel('block-item-NegotiationConfig-workflows-Negotiation mode') + .getByRole('spinbutton'); this.parallellyRadio = page.getByLabel('Parallelly', { exact: true }); this.sequentiallyRadio = page.getByLabel('Sequentially', { exact: true }); this.goToconfigureButton = page.getByRole('button', { name: 'Go to configure' }); this.addBlockButton = page.getByLabel('schema-initializer-Grid-ApprovalProcessAddBlockButton-workflows'); this.addDetailsMenu = page.getByRole('menuitem', { name: 'Details' }); - this.detailsConfigureFieldsButton = page.getByLabel(`schema-initializer-Grid-details:configureFields-${collectionName}`); + this.detailsConfigureFieldsButton = page.getByLabel( + `schema-initializer-Grid-details:configureFields-${collectionName}`, + ); this.addActionsMenu = page.getByRole('menuitem', { name: 'Actions' }).getByRole('switch'); this.actionsConfigureFieldsButton = page.getByLabel('schema-initializer-Grid-FormItemInitializers-approvalRecords'); this.actionsConfigureActionsButton = page.getByLabel( @@ -353,6 +367,30 @@ export class FormEventTriggerNode { } } +export class CustomActionEventTriggerNode { + readonly page: Page; + node: Locator; + nodeTitle: Locator; + nodeConfigure: Locator; + collectionDropDown: Locator; + relationalDataDropdown: Locator; + submitButton: Locator; + cancelButton: Locator; + addNodeButton: Locator; + constructor(page: Page, triggerName: string, collectionName: string) { + this.page = page; + this.node = page.getByLabel(`Trigger-${triggerName}`); + this.nodeTitle = page.getByLabel(`Trigger-${triggerName}`).getByRole('textbox'); + this.nodeConfigure = page.getByLabel(`Trigger-${triggerName}`).getByRole('button', { name: 'Configure' }); + this.collectionDropDown = page + .getByLabel('block-item-DataSourceCollectionCascader-workflows-Collection') + .locator('.ant-select-selection-search-input'); + this.relationalDataDropdown = page.getByTestId('select-field-Preload associations'); + this.submitButton = page.getByLabel('action-Action-Submit-workflows'); + this.cancelButton = page.getByLabel('action-Action-Cancel-workflows'); + this.addNodeButton = page.getByLabel('add-button', { exact: true }); + } +} export class CalculationNode { readonly page: Page; node: Locator; @@ -733,5 +771,6 @@ export default module.exports = { ConditionBranchNode, SQLNode, ParallelBranchNode, - ApprovalBranchModeNode + ApprovalBranchModeNode, + CustomActionEventTriggerNode, }; diff --git a/packages/plugins/@nocobase/plugin-workflow-test/src/e2e/e2eUtils.ts b/packages/plugins/@nocobase/plugin-workflow-test/src/e2e/e2eUtils.ts index 5c435c417..92c91cd56 100644 --- a/packages/plugins/@nocobase/plugin-workflow-test/src/e2e/e2eUtils.ts +++ b/packages/plugins/@nocobase/plugin-workflow-test/src/e2e/e2eUtils.ts @@ -808,6 +808,57 @@ export const apiCreateRecordTriggerActionEvent = async ( return (await result.json()).data; }; +// 添加业务表单条数据触发工作流表单事件,triggerWorkflows=key1!field,key2,key3!field.subfield +export const apiTriggerCustomActionEvent = async (collectionName: string, triggerWorkflows: string, data: any) => { + const api = await request.newContext({ + storageState: process.env.PLAYWRIGHT_AUTH_FILE, + }); + const state = await api.storageState(); + const headers = getHeaders(state); + /* + { + "title": "a11", + "enabled": true, + "description": null + } + */ + const result = await api.post(`/api/${collectionName}:trigger?triggerWorkflows=${triggerWorkflows}`, { + headers, + data, + }); + + if (!result.ok()) { + throw new Error(await result.text()); + } + /* + { + "data": { + "id": 1, + "createdAt": "2023-12-12T02:43:53.793Z", + "updatedAt": "2023-12-12T05:41:33.300Z", + "key": "fzk3j2oj4el", + "title": "a11", + "enabled": true, + "description": null + }, + "meta": { + "allowedActions": { + "view": [ + 1 + ], + "update": [ + 1 + ], + "destroy": [ + 1 + ] + } + } + } + */ + return (await result.json()).data; +}; + // 审批中心发起审批 export const apiApplyApprovalEvent = async (data: any) => { const api = await request.newContext({ @@ -1020,5 +1071,6 @@ export default module.exports = { apiCreateRecordTriggerActionEvent, apiApplyApprovalEvent, userLogin, - apiCreateField + apiCreateField, + apiTriggerCustomActionEvent, }; From d2aedd01d067316ed28e811a805ecf54f9f2a5c1 Mon Sep 17 00:00:00 2001 From: Zeke Zhang <958414905@qq.com> Date: Sun, 28 Jul 2024 14:27:05 +0800 Subject: [PATCH 2/3] chore: upgrade playwright to v1.45.3 (#4954) --- lerna.json | 4 +--- packages/core/test/package.json | 2 +- yarn.lock | 28 ++++++++++++++-------------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/lerna.json b/lerna.json index 7ccfef009..f636a3bd0 100644 --- a/lerna.json +++ b/lerna.json @@ -2,9 +2,7 @@ "version": "1.2.25-alpha", "npmClient": "yarn", "useWorkspaces": true, - "npmClientArgs": [ - "--ignore-engines" - ], + "npmClientArgs": ["--ignore-engines"], "command": { "version": { "forcePublish": true, diff --git a/packages/core/test/package.json b/packages/core/test/package.json index e5e0ff444..8c41a411a 100644 --- a/packages/core/test/package.json +++ b/packages/core/test/package.json @@ -52,7 +52,7 @@ "dependencies": { "@faker-js/faker": "8.1.0", "@nocobase/server": "1.2.25-alpha", - "@playwright/test": "^1.44.0", + "@playwright/test": "^1.45.3", "@testing-library/jest-dom": "^6.4.2", "@testing-library/react": "^14.0.0", "@testing-library/react-hooks": "^8.0.1", diff --git a/yarn.lock b/yarn.lock index 4707a7c22..5b99779c8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4894,12 +4894,12 @@ picocolors "^1.0.0" tslib "^2.6.0" -"@playwright/test@^1.44.0": - version "1.44.0" - resolved "https://registry.npmmirror.com/@playwright/test/-/test-1.44.0.tgz#ac7a764b5ee6a80558bdc0fcbc525fcb81f83465" - integrity sha512-rNX5lbNidamSUorBhB4XZ9SQTjAqfe5M+p37Z8ic0jPFBMo5iCtQz1kRWkEMg+rYOKSlVycpQmpqjSFq7LXOfg== +"@playwright/test@^1.45.3": + version "1.45.3" + resolved "https://registry.npmmirror.com/@playwright/test/-/test-1.45.3.tgz#22e9c38b3081d6674b28c6e22f784087776c72e5" + integrity sha512-UKF4XsBfy+u3MFWEH44hva1Q8Da28G6RFtR2+5saw+jgAFQV5yYnB1fu68Mz7fO+5GJF3wgwAIs0UelU8TxFrA== dependencies: - playwright "1.44.0" + playwright "1.45.3" "@pm2/agent@~2.0.0": version "2.0.3" @@ -20512,17 +20512,17 @@ platform@^1.3.1: resolved "https://registry.npmmirror.com/platform/-/platform-1.3.6.tgz#48b4ce983164b209c2d45a107adb31f473a6e7a7" integrity sha512-fnWVljUchTro6RiCFvCXBbNhJc2NijN7oIQxbwsyL0buWJPG85v81ehlHI9fXrJsMNgTofEoWIQeClKpgxFLrg== -playwright-core@1.44.0: - version "1.44.0" - resolved "https://registry.npmmirror.com/playwright-core/-/playwright-core-1.44.0.tgz#316c4f0bca0551ffb88b6eb1c97bc0d2d861b0d5" - integrity sha512-ZTbkNpFfYcGWohvTTl+xewITm7EOuqIqex0c7dNZ+aXsbrLj0qI8XlGKfPpipjm0Wny/4Lt4CJsWJk1stVS5qQ== +playwright-core@1.45.3: + version "1.45.3" + resolved "https://registry.npmmirror.com/playwright-core/-/playwright-core-1.45.3.tgz#e77bc4c78a621b96c3e629027534ee1d25faac93" + integrity sha512-+ym0jNbcjikaOwwSZycFbwkWgfruWvYlJfThKYAlImbxUgdWFO2oW70ojPm4OpE4t6TAo2FY/smM+hpVTtkhDA== -playwright@1.44.0: - version "1.44.0" - resolved "https://registry.npmmirror.com/playwright/-/playwright-1.44.0.tgz#22894e9b69087f6beb639249323d80fe2b5087ff" - integrity sha512-F9b3GUCLQ3Nffrfb6dunPOkE5Mh68tR7zN32L4jCk4FjQamgesGay7/dAAe1WaMEGV04DkdJfcJzjoCKygUaRQ== +playwright@1.45.3: + version "1.45.3" + resolved "https://registry.npmmirror.com/playwright/-/playwright-1.45.3.tgz#75143f73093a6e1467f7097083d2f0846fb8dd2f" + integrity sha512-QhVaS+lpluxCaioejDZ95l4Y4jSFCsBvl2UZkpeXlzxmqS+aABr5c82YmfMHrL6x27nvrvykJAFpkzT2eWdJww== dependencies: - playwright-core "1.44.0" + playwright-core "1.45.3" optionalDependencies: fsevents "2.3.2" From e7275819675b6f35241cc750fd06df5f5bd5a7b0 Mon Sep 17 00:00:00 2001 From: jack zhang <1098626505@qq.com> Date: Sun, 28 Jul 2024 15:44:50 +0800 Subject: [PATCH 3/3] fix: plugin template add locale (#4943) --- .../core/cli/templates/plugin/src/client/locale.ts | 12 ++++++++++++ .../core/cli/templates/plugin/src/locale/en-US.json | 1 + .../core/cli/templates/plugin/src/locale/zh-CN.json | 1 + 3 files changed, 14 insertions(+) create mode 100644 packages/core/cli/templates/plugin/src/client/locale.ts create mode 100644 packages/core/cli/templates/plugin/src/locale/en-US.json create mode 100644 packages/core/cli/templates/plugin/src/locale/zh-CN.json diff --git a/packages/core/cli/templates/plugin/src/client/locale.ts b/packages/core/cli/templates/plugin/src/client/locale.ts new file mode 100644 index 000000000..2cf2a9558 --- /dev/null +++ b/packages/core/cli/templates/plugin/src/client/locale.ts @@ -0,0 +1,12 @@ +import { useTranslation } from 'react-i18next'; + +// @ts-ignore +import pkg from './../../package.json'; + +export function usePluginTranslation() { + return useTranslation([pkg.name, 'client'], { nsMode: 'fallback' }); +} + +export function generatePluginTranslationTemplate(key: string) { + return `{{t('${key}', { ns: ['${pkg.name}', 'client'], nsMode: 'fallback' })}}`; +} diff --git a/packages/core/cli/templates/plugin/src/locale/en-US.json b/packages/core/cli/templates/plugin/src/locale/en-US.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/packages/core/cli/templates/plugin/src/locale/en-US.json @@ -0,0 +1 @@ +{} diff --git a/packages/core/cli/templates/plugin/src/locale/zh-CN.json b/packages/core/cli/templates/plugin/src/locale/zh-CN.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/packages/core/cli/templates/plugin/src/locale/zh-CN.json @@ -0,0 +1 @@ +{}