@nocobase/client-v2 2.1.0-beta.47 → 2.1.0-beta.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/es/components/form/ScanInput/CodeScanner.d.ts +18 -0
  2. package/es/components/form/ScanInput/ScanBox.d.ts +12 -0
  3. package/es/components/form/ScanInput/ScanInput.d.ts +18 -0
  4. package/es/components/form/ScanInput/index.d.ts +11 -0
  5. package/es/components/form/ScanInput/types.d.ts +10 -0
  6. package/es/components/form/ScanInput/useCodeScanner.d.ts +31 -0
  7. package/es/components/form/index.d.ts +1 -0
  8. package/es/flow/models/fields/AssociationFieldModel/RecordPickerFieldModel.d.ts +14 -0
  9. package/es/index.mjs +76 -36
  10. package/lib/index.js +111 -71
  11. package/package.json +8 -7
  12. package/src/components/form/ScanInput/CodeScanner.tsx +219 -0
  13. package/src/components/form/ScanInput/ScanBox.tsx +30 -0
  14. package/src/components/form/ScanInput/ScanInput.tsx +150 -0
  15. package/src/components/form/ScanInput/__tests__/ScanInput.test.tsx +119 -0
  16. package/src/components/form/ScanInput/__tests__/useCodeScanner.test.tsx +123 -0
  17. package/src/components/form/ScanInput/index.ts +12 -0
  18. package/src/components/form/ScanInput/types.ts +12 -0
  19. package/src/components/form/ScanInput/useCodeScanner.ts +136 -0
  20. package/src/components/form/index.tsx +1 -0
  21. package/src/flow/actions/__tests__/actionLinkageRules.race.repro.test.ts +45 -0
  22. package/src/flow/actions/linkageRules.tsx +16 -4
  23. package/src/flow/models/fields/AssociationFieldModel/RecordPickerFieldModel.tsx +111 -26
  24. package/src/flow/models/fields/AssociationFieldModel/__tests__/RecordPickerFieldModel.itemContext.test.ts +61 -0
  25. package/src/flow/models/fields/InputFieldModel.tsx +56 -1
  26. package/src/flow/models/fields/__tests__/InputFieldModel.test.tsx +116 -0
@@ -0,0 +1,116 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ import { FlowEngine } from '@nocobase/flow-engine';
11
+ import { render, screen } from '@testing-library/react';
12
+ import React from 'react';
13
+ import { describe, expect, it, vi } from 'vitest';
14
+ import { InputFieldModel } from '../InputFieldModel';
15
+
16
+ vi.mock('react-i18next', () => ({
17
+ useTranslation: () => ({ t: (key: string) => key }),
18
+ }));
19
+
20
+ function createInputFieldModel(props?: Record<string, unknown>) {
21
+ const engine = new FlowEngine();
22
+ return new InputFieldModel({
23
+ uid: 'input-field-model-test',
24
+ flowEngine: engine,
25
+ props,
26
+ });
27
+ }
28
+
29
+ describe('InputFieldModel', () => {
30
+ it('renders the normal input when scan input is disabled', () => {
31
+ const consoleError = vi.spyOn(console, 'error').mockImplementation(() => undefined);
32
+ const model = createInputFieldModel({ disableManualInput: true, enableScan: false });
33
+
34
+ render(<>{model.render()}</>);
35
+
36
+ expect(screen.getByRole('textbox')).toBeInTheDocument();
37
+ expect(screen.queryByRole('button', { name: 'Scan to input' })).not.toBeInTheDocument();
38
+ expect(consoleError).not.toHaveBeenCalledWith(
39
+ expect.stringContaining('React does not recognize the `disableManualInput` prop'),
40
+ expect.anything(),
41
+ );
42
+
43
+ consoleError.mockRestore();
44
+ });
45
+
46
+ it('renders ScanInput when scan input is enabled', () => {
47
+ const model = createInputFieldModel({ enableScan: true });
48
+
49
+ render(<>{model.render()}</>);
50
+
51
+ expect(screen.getByRole('textbox')).toBeInTheDocument();
52
+ expect(screen.getByRole('button', { name: 'Scan to input' })).toBeInTheDocument();
53
+ });
54
+
55
+ it('stores enableScan and clears disableManualInput when scan input is turned off', () => {
56
+ const model = createInputFieldModel();
57
+ const step = model.getFlow('scanInputSettings')?.steps.enableScan;
58
+ const setProps = vi.fn();
59
+
60
+ step?.handler(
61
+ {
62
+ model: {
63
+ props: { disableManualInput: true },
64
+ setProps,
65
+ },
66
+ },
67
+ { enableScan: false },
68
+ );
69
+
70
+ expect(setProps).toHaveBeenCalledWith({
71
+ enableScan: false,
72
+ disableManualInput: false,
73
+ });
74
+ });
75
+
76
+ it('does not restore manual input disabling after scan input is turned off', () => {
77
+ const model = createInputFieldModel({ enableScan: true, disableManualInput: true });
78
+ const flow = model.getFlow('scanInputSettings');
79
+ const ctx = { model };
80
+
81
+ flow?.steps.enableScan.handler(ctx, { enableScan: false });
82
+ flow?.steps.disableManualInput.handler(ctx, { disableManualInput: true });
83
+
84
+ expect(model.props).toMatchObject({
85
+ enableScan: false,
86
+ disableManualInput: false,
87
+ });
88
+ });
89
+
90
+ it('hides disableManualInput until scan input is enabled', () => {
91
+ const model = createInputFieldModel();
92
+ const step = model.getFlow('scanInputSettings')?.steps.disableManualInput;
93
+
94
+ const hidden = step?.hideInSettings({
95
+ model: {
96
+ props: { enableScan: false },
97
+ getProps: () => ({}),
98
+ },
99
+ });
100
+
101
+ expect(hidden).toBe(true);
102
+ });
103
+
104
+ it('updates disableManualInput visibility from the current enableScan setting params', () => {
105
+ const model = createInputFieldModel({ enableScan: false });
106
+ const step = model.getFlow('scanInputSettings')?.steps.disableManualInput;
107
+
108
+ model.setStepParams('scanInputSettings', 'enableScan', { enableScan: true });
109
+
110
+ expect(step?.hideInSettings({ model })).toBe(false);
111
+
112
+ model.setStepParams('scanInputSettings', 'enableScan', { enableScan: false });
113
+
114
+ expect(step?.hideInSettings({ model })).toBe(true);
115
+ });
116
+ });