@nocobase/client-v2 2.2.0-beta.14 → 2.2.0-beta.16

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 (114) hide show
  1. package/es/components/category-tabs/SortableCategoryTabs.d.ts +55 -0
  2. package/es/components/category-tabs/index.d.ts +9 -0
  3. package/es/components/form/ScanInput/useCodeScanner.d.ts +2 -2
  4. package/es/components/form/TypedVariableInput.d.ts +31 -5
  5. package/es/components/form/filter/CollectionFilter.d.ts +2 -0
  6. package/es/components/form/filter/CollectionFilterItem.d.ts +11 -1
  7. package/es/components/form/filter/CollectionFilterPanel.d.ts +2 -0
  8. package/es/components/form/filter/index.d.ts +2 -0
  9. package/es/components/form/filter/useFilterActionProps.d.ts +2 -0
  10. package/es/components/index.d.ts +1 -0
  11. package/es/flow/actions/index.d.ts +1 -1
  12. package/es/flow/actions/linkageRules.d.ts +3 -0
  13. package/es/flow/admin-shell/admin-layout/AdminLayoutMenuModels.d.ts +1 -0
  14. package/es/flow/components/FieldAssignExactDatePicker.d.ts +1 -0
  15. package/es/flow/components/FieldAssignValueInput.d.ts +9 -0
  16. package/es/flow/components/FlowRoute.d.ts +2 -2
  17. package/es/flow/components/RunJSValueEditor.d.ts +1 -0
  18. package/es/flow/components/filter/FilterGroup.d.ts +1 -0
  19. package/es/flow/components/filter/VariableFilterItem.d.ts +6 -1
  20. package/es/flow/index.d.ts +1 -0
  21. package/es/flow/internal/registerDeviceTypeContext.d.ts +10 -0
  22. package/es/flow/models/base/ActionModelCore.d.ts +4 -2
  23. package/es/flow/models/base/BlockGridModel.d.ts +3 -0
  24. package/es/flow/models/base/PageModel/PageModel.d.ts +12 -0
  25. package/es/flow/models/base/PageModel/PageModelTabBar.d.ts +22 -0
  26. package/es/flow/models/base/PageModel/PageTabModel.d.ts +12 -0
  27. package/es/flow/models/blocks/table/TableColumnModel.d.ts +1 -0
  28. package/es/flow/models/fields/DateTimeFieldModel/dateLimit.d.ts +15 -7
  29. package/es/flow-compat/routeTypes.d.ts +1 -0
  30. package/es/index.d.ts +4 -0
  31. package/es/index.mjs +143 -106
  32. package/es/utils/getRouteRuntimeVersion.d.ts +23 -0
  33. package/es/utils/index.d.ts +1 -0
  34. package/lib/index.js +154 -117
  35. package/lib/locale/languageCodes.js +3 -1
  36. package/package.json +8 -7
  37. package/src/__tests__/browserChecker.test.ts +61 -0
  38. package/src/__tests__/getRouteRuntimeVersion.test.ts +68 -0
  39. package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +7 -2
  40. package/src/components/README.md +7 -1
  41. package/src/components/README.zh-CN.md +6 -1
  42. package/src/components/category-tabs/SortableCategoryTabs.tsx +210 -0
  43. package/src/components/category-tabs/index.ts +10 -0
  44. package/src/components/form/JsonTextArea.tsx +4 -0
  45. package/src/components/form/ScanInput/CodeScanner.tsx +61 -34
  46. package/src/components/form/ScanInput/__tests__/CodeScanner.test.tsx +101 -0
  47. package/src/components/form/ScanInput/__tests__/useCodeScanner.test.tsx +114 -18
  48. package/src/components/form/ScanInput/useCodeScanner.ts +166 -23
  49. package/src/components/form/TypedVariableInput.tsx +452 -101
  50. package/src/components/form/__tests__/TypedVariableInput.test.tsx +364 -12
  51. package/src/components/form/filter/CollectionFilter.tsx +4 -0
  52. package/src/components/form/filter/CollectionFilterItem.tsx +32 -7
  53. package/src/components/form/filter/CollectionFilterPanel.tsx +4 -0
  54. package/src/components/form/filter/__tests__/CollectionFilterItem.test.tsx +38 -0
  55. package/src/components/form/filter/__tests__/useFilterActionProps.test.tsx +95 -0
  56. package/src/components/form/filter/index.ts +2 -0
  57. package/src/components/form/filter/useFilterActionProps.ts +37 -6
  58. package/src/components/index.ts +1 -0
  59. package/src/flow/__tests__/FlowRoute.test.tsx +126 -8
  60. package/src/flow/__tests__/PluginFlowEngine.test.ts +58 -0
  61. package/src/flow/actions/__tests__/actionLinkageRules.forkProps.test.ts +314 -0
  62. package/src/flow/actions/__tests__/dataScopeFormValueClear.test.ts +102 -0
  63. package/src/flow/actions/__tests__/linkageRules.tab.test.ts +171 -0
  64. package/src/flow/actions/index.ts +2 -0
  65. package/src/flow/actions/linkageRules.tsx +111 -16
  66. package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +0 -1
  67. package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutComponent.test.tsx +253 -6
  68. package/src/flow/common/Markdown/style.ts +4 -0
  69. package/src/flow/components/BlockItemCard.tsx +2 -2
  70. package/src/flow/components/FieldAssignExactDatePicker.tsx +25 -11
  71. package/src/flow/components/FieldAssignValueInput.tsx +76 -9
  72. package/src/flow/components/FlowRoute.tsx +71 -29
  73. package/src/flow/components/RunJSValueEditor.tsx +9 -1
  74. package/src/flow/components/__tests__/FieldAssignValueInput.context.test.tsx +84 -2
  75. package/src/flow/components/filter/FilterGroup.tsx +33 -5
  76. package/src/flow/components/filter/VariableFilterItem.tsx +158 -10
  77. package/src/flow/components/filter/__tests__/FilterGroup.test.tsx +45 -0
  78. package/src/flow/components/filter/__tests__/VariableFilterItem.leftMetaTree.test.tsx +9 -0
  79. package/src/flow/components/filter/__tests__/VariableFilterItem.test.tsx +70 -1
  80. package/src/flow/index.ts +3 -0
  81. package/src/flow/internal/registerDeviceTypeContext.ts +39 -0
  82. package/src/flow/models/base/ActionModelCore.tsx +11 -2
  83. package/src/flow/models/base/BlockGridModel.tsx +26 -0
  84. package/src/flow/models/base/CollectionBlockModel.tsx +6 -2
  85. package/src/flow/models/base/PageModel/PageModel.tsx +387 -53
  86. package/src/flow/models/base/PageModel/PageModelTabBar.tsx +114 -0
  87. package/src/flow/models/base/PageModel/PageTabModel.tsx +249 -18
  88. package/src/flow/models/base/PageModel/__tests__/PageModel.test.ts +790 -10
  89. package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.module-isolation.test.tsx +130 -0
  90. package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.test.tsx +118 -0
  91. package/src/flow/models/base/PageModel/__tests__/PageTabModel.test.ts +1075 -7
  92. package/src/flow/models/base/__tests__/ActionModelCore.render.test.tsx +49 -0
  93. package/src/flow/models/base/__tests__/BlockGridModel.selectSceneActivation.test.ts +124 -0
  94. package/src/flow/models/base/__tests__/CollectionBlockModel.addAppends.test.ts +41 -0
  95. package/src/flow/models/blocks/filter-form/FilterFormBlockModel.tsx +27 -3
  96. package/src/flow/models/blocks/filter-form/__tests__/defaultValues.wiring.test.ts +32 -4
  97. package/src/flow/models/blocks/js-block/JSBlock.tsx +1 -1
  98. package/src/flow/models/blocks/table/TableBlockModel.tsx +3 -1
  99. package/src/flow/models/blocks/table/TableColumnModel.tsx +30 -1
  100. package/src/flow/models/blocks/table/__tests__/TableBlockModel.quickEditRefresh.test.ts +12 -0
  101. package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +33 -0
  102. package/src/flow/models/fields/DateTimeFieldModel/__tests__/DateTimeNoTzFieldModel.dateLimit.test.tsx +149 -0
  103. package/src/flow/models/fields/DateTimeFieldModel/dateLimit.ts +149 -113
  104. package/src/flow/models/fields/JsonFieldModel.tsx +31 -8
  105. package/src/flow/models/fields/VariableFieldFormModel.tsx +3 -3
  106. package/src/flow/models/fields/__tests__/JsonFieldModel.test.ts +82 -0
  107. package/src/flow/models/fields/__tests__/VariableFieldFormModel.test.tsx +51 -0
  108. package/src/flow/utils/dataScopeFormValueClear.ts +4 -3
  109. package/src/flow-compat/routeTypes.ts +1 -0
  110. package/src/index.ts +4 -0
  111. package/src/locale/languageCodes.ts +3 -1
  112. package/src/nocobase-buildin-plugin/index.tsx +2 -0
  113. package/src/utils/getRouteRuntimeVersion.ts +185 -0
  114. package/src/utils/index.tsx +1 -0
@@ -0,0 +1,95 @@
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, FlowEngineProvider, type Collection } from '@nocobase/flow-engine';
11
+ import { renderHook } from '@testing-library/react';
12
+ import React from 'react';
13
+ import { describe, expect, it, vi } from 'vitest';
14
+ import { useFilterActionProps } from '../useFilterActionProps';
15
+
16
+ vi.mock('../../../flow/components/filter/useFilterOptions', () => ({
17
+ useFilterOptions: () => [],
18
+ }));
19
+
20
+ vi.mock('../CollectionFilterItem', () => ({
21
+ createCollectionFilterItem: () => undefined,
22
+ }));
23
+
24
+ function makeCollection(): Collection {
25
+ return {
26
+ getFields: () => [{ name: 'title' }, { name: 'type' }],
27
+ } as unknown as Collection;
28
+ }
29
+
30
+ function makeWrapper() {
31
+ const engine = new FlowEngine();
32
+ const Wrapper: React.FC = ({ children }) => <FlowEngineProvider engine={engine}>{children}</FlowEngineProvider>;
33
+ return Wrapper;
34
+ }
35
+
36
+ describe('useFilterActionProps', () => {
37
+ it('seeds the editable group from defaultValue when initialValue is missing', () => {
38
+ const { result } = renderHook(
39
+ () =>
40
+ useFilterActionProps({
41
+ collection: makeCollection(),
42
+ defaultValue: { $and: [{ title: { $includes: '' } }, { type: { $eq: undefined } }] },
43
+ onApply: () => undefined,
44
+ }),
45
+ { wrapper: makeWrapper() },
46
+ );
47
+
48
+ expect(result.current.value).toMatchObject({
49
+ logic: '$and',
50
+ items: [
51
+ { path: 'title', operator: '$includes', value: '' },
52
+ { path: 'type', operator: '$eq', value: undefined },
53
+ ],
54
+ });
55
+ });
56
+
57
+ it('reset restores defaultValue and emits its compiled filter', () => {
58
+ const onApply = vi.fn();
59
+ const { result } = renderHook(
60
+ () =>
61
+ useFilterActionProps({
62
+ collection: makeCollection(),
63
+ defaultValue: { $and: [{ title: { $includes: '' } }, { type: { $eq: undefined } }] },
64
+ initialValue: { $and: [{ title: { $includes: 'abc' } }] },
65
+ onApply,
66
+ }),
67
+ { wrapper: makeWrapper() },
68
+ );
69
+
70
+ result.current.onReset();
71
+
72
+ expect(result.current.value).toMatchObject({
73
+ logic: '$and',
74
+ items: [
75
+ { path: 'title', operator: '$includes', value: '' },
76
+ { path: 'type', operator: '$eq', value: undefined },
77
+ ],
78
+ });
79
+ expect(onApply).toHaveBeenCalledWith(undefined, 'reset');
80
+ });
81
+
82
+ it('counts only effective compiled conditions, so empty default rows do not highlight the button', () => {
83
+ const { result } = renderHook(
84
+ () =>
85
+ useFilterActionProps({
86
+ collection: makeCollection(),
87
+ defaultValue: { $and: [{ title: { $includes: '' } }, { type: { $eq: undefined } }] },
88
+ onApply: () => undefined,
89
+ }),
90
+ { wrapper: makeWrapper() },
91
+ );
92
+
93
+ expect(result.current.conditionCount).toBe(0);
94
+ });
95
+ });
@@ -11,5 +11,7 @@
11
11
  export { CollectionFilter } from './CollectionFilter';
12
12
  export type { CollectionFilterProps } from './CollectionFilter';
13
13
  export { CollectionFilterPanel } from './CollectionFilterPanel';
14
+ export { CollectionFilterItem } from './CollectionFilterItem';
15
+ export type { CollectionFilterItemValue } from './CollectionFilterItem';
14
16
  export type { CollectionFilterPanelProps, CollectionFilterPanelRef } from './CollectionFilterPanel';
15
17
  export type { CompiledFilter } from './useFilterActionProps';
@@ -43,6 +43,14 @@ const isCondition = (item: FilterGroupItem): item is CollectionFilterItemValue =
43
43
  typeof (item as CollectionFilterItemValue).path === 'string' &&
44
44
  Object.prototype.hasOwnProperty.call(item, 'operator');
45
45
 
46
+ const cloneFilterGroupItem = (item: FilterGroupItem): FilterGroupItem =>
47
+ isGroup(item) ? { logic: item.logic, items: item.items.map((child) => cloneFilterGroupItem(child)) } : { ...item };
48
+
49
+ const cloneFilterGroup = (group: FilterGroupValue): FilterGroupValue => ({
50
+ logic: group.logic,
51
+ items: group.items.map((item) => cloneFilterGroupItem(item)),
52
+ });
53
+
46
54
  /**
47
55
  * `true` when the rhs of a condition is "no real value yet" — covers `undefined` / `null` / empty string / empty array / empty plain object. Mirrors v1's `removeNullCondition` `isEmpty` predicate so half-filled rows ("Locked time → is → (no date picked yet)") get dropped on Submit instead of being sent to the server as `{lockedTs:{}}` and triggering a 500.
48
56
  */
@@ -164,6 +172,8 @@ export interface UseFilterActionPropsArgs extends UseFilterOptionsArgs {
164
172
  collection: Collection | undefined;
165
173
  /** Previously compiled filter param used to seed the editable filter group. */
166
174
  initialValue?: CompiledFilter;
175
+ /** Default compiled filter used both for initial empty state and Reset. */
176
+ defaultValue?: CompiledFilter;
167
177
  /**
168
178
  * Called when the user submits or resets the filter popover. Receives the compiled filter param (`undefined` when cleared) and which footer button triggered the call. Typical implementation: `(filter, action) => { listRequest.run(filter); if (action === 'submit') closePopover(); }`.
169
179
  */
@@ -216,12 +226,23 @@ export interface UseFilterActionPropsResult {
216
226
  * ```
217
227
  */
218
228
  export function useFilterActionProps(args: UseFilterActionPropsArgs): UseFilterActionPropsResult {
219
- const { collection, initialValue, onApply, filterableFieldNames, nonfilterableFieldNames, noIgnore, t } = args;
229
+ const {
230
+ collection,
231
+ initialValue,
232
+ defaultValue,
233
+ onApply,
234
+ filterableFieldNames,
235
+ nonfilterableFieldNames,
236
+ noIgnore,
237
+ t,
238
+ } = args;
239
+ const seedValue = initialValue ?? defaultValue;
240
+ const defaultGroup = decompileFilterGroup(defaultValue) || createEmptyGroup();
220
241
 
221
242
  // Held in a ref so the group object identity is stable for the lifetime of the host component — `<FilterContent>` mutates this object directly (push/splice on `items`, swap `logic`), and a fresh observable on every render would reset that internal state.
222
243
  const valueRef = useRef<FilterGroupValue>();
223
244
  if (!valueRef.current) {
224
- valueRef.current = observable(decompileFilterGroup(initialValue) || createEmptyGroup()) as FilterGroupValue;
245
+ valueRef.current = observable(decompileFilterGroup(seedValue) || createEmptyGroup()) as FilterGroupValue;
225
246
  }
226
247
  const value = valueRef.current;
227
248
 
@@ -240,9 +261,10 @@ export function useFilterActionProps(args: UseFilterActionPropsArgs): UseFilterA
240
261
  });
241
262
 
242
263
  const onReset = useMemoizedFn(() => {
243
- value.logic = '$and';
244
- value.items = [];
245
- onApply(undefined, 'reset');
264
+ const next = cloneFilterGroup(defaultGroup);
265
+ value.logic = next.logic;
266
+ value.items = next.items;
267
+ onApply(compileFilterGroup(value), 'reset');
246
268
  });
247
269
 
248
270
  const translate = useMemoizedFn((key: string) => (t ? t(key) : key));
@@ -261,7 +283,16 @@ export function useFilterActionProps(args: UseFilterActionPropsArgs): UseFilterA
261
283
  );
262
284
 
263
285
  // Re-read on each render so `observer`-wrapped hosts re-render when the reactive `items` array length changes. No useMemo needed — the `value` object's identity is stable (held in a ref), but its observable `items.length` is what we actually care about, and the eslint exhaustive-deps rule rightly complains about depending on a mutable property of a stable ref.
264
- const conditionCount = value.items.length;
286
+ const conditionCount = (() => {
287
+ const compiled = compileFilterGroup(value);
288
+ if (compiled?.$and && Array.isArray(compiled.$and)) {
289
+ return compiled.$and.length;
290
+ }
291
+ if (compiled?.$or && Array.isArray(compiled.$or)) {
292
+ return compiled.$or.length;
293
+ }
294
+ return 0;
295
+ })();
265
296
 
266
297
  return { value, options, FilterItem, ctx, onSubmit, onReset, conditionCount };
267
298
  }
@@ -9,6 +9,7 @@
9
9
 
10
10
  export * from './AppComponents';
11
11
  export * from './BlankComponent';
12
+ export * from './category-tabs';
12
13
  export * from './form/table/dnd';
13
14
  export * from './form';
14
15
  export * from './Icon';
@@ -116,6 +116,7 @@ describe('FlowRoute', () => {
116
116
  }),
117
117
  );
118
118
  });
119
+ expect(engine.context.deviceType).toBe('computer');
119
120
 
120
121
  rerender(
121
122
  <FlowEngineProvider engine={engine}>
@@ -581,14 +582,14 @@ describe('FlowRoute', () => {
581
582
  expect(getRouteBySchemaUid).toHaveBeenCalledTimes(1);
582
583
  });
583
584
 
584
- it('should show 404 when current route is a legacy page in v2 runtime', async () => {
585
+ it('should explain how to open a legacy page outside the v2 runtime', async () => {
585
586
  const originalLocation = window.location;
586
587
  const replace = vi.fn();
587
588
  Object.defineProperty(window, 'location', {
588
589
  configurable: true,
589
590
  value: {
590
591
  ...originalLocation,
591
- pathname: '/v2/admin/test-page/tab/tab-1',
592
+ pathname: '/nocobase/v2/apps/jhb20/admin/test-page/tab/tab-1',
592
593
  search: '?from=direct',
593
594
  hash: '#dialog',
594
595
  replace,
@@ -607,9 +608,9 @@ describe('FlowRoute', () => {
607
608
  });
608
609
  engine.context.defineProperty('app', {
609
610
  value: {
610
- getPublicPath: () => '/v2/',
611
+ getPublicPath: () => '/nocobase/v2/',
611
612
  router: {
612
- getBasename: () => '/v2',
613
+ getBasename: () => '/nocobase/v2',
613
614
  },
614
615
  },
615
616
  });
@@ -625,15 +626,25 @@ describe('FlowRoute', () => {
625
626
 
626
627
  render(
627
628
  <FlowEngineProvider engine={engine}>
628
- <MemoryRouter initialEntries={['/flow/test-page']}>
629
+ <MemoryRouter initialEntries={['/nocobase/v2/apps/jhb20/admin/test-page/tab/tab-1?from=direct#dialog']}>
629
630
  <Routes>
630
- <Route path="/flow/:name" element={<FlowRoute />} />
631
+ <Route path="/nocobase/v2/apps/jhb20/admin/:name/*" element={<FlowRoute />} />
631
632
  </Routes>
632
633
  </MemoryRouter>
633
634
  </FlowEngineProvider>,
634
635
  );
635
636
 
636
- expect(await screen.findByText('404')).toBeInTheDocument();
637
+ expect(await screen.findByText('This page is not supported in the /v2/ branch')).toBeInTheDocument();
638
+ expect(
639
+ screen.getByText(
640
+ 'The /v2/ branch only supports new pages. This page is a legacy page. Please open it from the original entry.',
641
+ ),
642
+ ).toBeInTheDocument();
643
+ expect(screen.queryByText('404')).not.toBeInTheDocument();
644
+ expect(screen.getByRole('link', { name: 'Open from the original entry' })).toHaveAttribute(
645
+ 'href',
646
+ '/nocobase/apps/jhb20/admin/test-page/tab/tab-1?from=direct#dialog',
647
+ );
637
648
  expect(replace).not.toHaveBeenCalled();
638
649
  expect(adminLayoutModel.registerRoutePage).not.toHaveBeenCalled();
639
650
  expect(adminLayoutModel.updateRoutePage).not.toHaveBeenCalled();
@@ -706,6 +717,113 @@ describe('FlowRoute', () => {
706
717
  }
707
718
  });
708
719
 
720
+ it('should render 404 for missing FlowModel in notFound mode without routeRepository', async () => {
721
+ const engine = new FlowEngine();
722
+ engine.context.defineProperty('app', {
723
+ value: {
724
+ getPublicPath: () => '/v2/',
725
+ router: {
726
+ getBasename: () => '/v2',
727
+ },
728
+ },
729
+ });
730
+
731
+ const adminLayoutModel: MockAdminLayoutModel = Object.assign(
732
+ engine.createModel({ uid: 'admin-layout-model', use: 'FlowModel' }),
733
+ {
734
+ registerRoutePage: vi.fn(),
735
+ updateRoutePage: vi.fn(),
736
+ unregisterRoutePage: vi.fn(),
737
+ },
738
+ );
739
+
740
+ render(
741
+ <FlowEngineProvider engine={engine}>
742
+ <MemoryRouter initialEntries={['/embed/missing-page']}>
743
+ <Routes>
744
+ <Route path="/embed/:name" element={<FlowRoute legacyPageBehavior="notFound" />} />
745
+ </Routes>
746
+ </MemoryRouter>
747
+ </FlowEngineProvider>,
748
+ );
749
+
750
+ expect(await screen.findByText('404')).toBeInTheDocument();
751
+ expect(adminLayoutModel.registerRoutePage).not.toHaveBeenCalled();
752
+ });
753
+
754
+ it('should bridge by default when routeRepository does not exist', async () => {
755
+ const engine = new FlowEngine();
756
+ engine.context.defineProperty('app', {
757
+ value: {
758
+ getPublicPath: () => '/v2/',
759
+ router: {
760
+ getBasename: () => '/v2',
761
+ },
762
+ },
763
+ });
764
+
765
+ const adminLayoutModel: MockAdminLayoutModel = Object.assign(
766
+ engine.createModel({ uid: 'admin-layout-model', use: 'FlowModel' }),
767
+ {
768
+ registerRoutePage: vi.fn(),
769
+ updateRoutePage: vi.fn(),
770
+ unregisterRoutePage: vi.fn(),
771
+ },
772
+ );
773
+
774
+ render(
775
+ <FlowEngineProvider engine={engine}>
776
+ <MemoryRouter initialEntries={['/flow/missing-page']}>
777
+ <Routes>
778
+ <Route path="/flow/:name" element={<FlowRoute />} />
779
+ </Routes>
780
+ </MemoryRouter>
781
+ </FlowEngineProvider>,
782
+ );
783
+
784
+ await waitFor(() => {
785
+ expect(adminLayoutModel.registerRoutePage).toHaveBeenCalledWith('missing-page', expect.any(Object));
786
+ });
787
+ expect(screen.queryByText('404')).not.toBeInTheDocument();
788
+ });
789
+
790
+ it('should bridge existing FlowModel in notFound mode without routeRepository', async () => {
791
+ const engine = new FlowEngine();
792
+ engine.createModel({ uid: 'test-page', use: 'FlowModel' });
793
+ engine.context.defineProperty('app', {
794
+ value: {
795
+ getPublicPath: () => '/v2/',
796
+ router: {
797
+ getBasename: () => '/v2',
798
+ },
799
+ },
800
+ });
801
+
802
+ const adminLayoutModel: MockAdminLayoutModel = Object.assign(
803
+ engine.createModel({ uid: 'admin-layout-model', use: 'FlowModel' }),
804
+ {
805
+ registerRoutePage: vi.fn(),
806
+ updateRoutePage: vi.fn(),
807
+ unregisterRoutePage: vi.fn(),
808
+ },
809
+ );
810
+
811
+ render(
812
+ <FlowEngineProvider engine={engine}>
813
+ <MemoryRouter initialEntries={['/embed/test-page']}>
814
+ <Routes>
815
+ <Route path="/embed/:name" element={<FlowRoute legacyPageBehavior="notFound" />} />
816
+ </Routes>
817
+ </MemoryRouter>
818
+ </FlowEngineProvider>,
819
+ );
820
+
821
+ await waitFor(() => {
822
+ expect(adminLayoutModel.registerRoutePage).toHaveBeenCalledWith('test-page', expect.any(Object));
823
+ });
824
+ expect(screen.queryByText('404')).not.toBeInTheDocument();
825
+ });
826
+
709
827
  it('should bridge existing FlowModel when behavior is notFound and routeRepository has no route', async () => {
710
828
  const engine = new FlowEngine();
711
829
  engine.setModelRepository({
@@ -1801,7 +1919,7 @@ describe('FlowRoute', () => {
1801
1919
  }
1802
1920
  });
1803
1921
 
1804
- it('should render not found without redirecting when admin route does not exist', async () => {
1922
+ it('should render 404 when route and FlowModel do not exist', async () => {
1805
1923
  const originalLocation = window.location;
1806
1924
  const replace = vi.fn();
1807
1925
  Object.defineProperty(window, 'location', {
@@ -0,0 +1,58 @@
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 { createMockClient, PluginFlowEngine } from '@nocobase/client-v2';
11
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
12
+
13
+ const { detectedDeviceType } = vi.hoisted(() => ({
14
+ detectedDeviceType: { value: 'mobile' },
15
+ }));
16
+
17
+ vi.mock('react-device-detect', () => ({
18
+ get deviceType() {
19
+ return detectedDeviceType.value;
20
+ },
21
+ }));
22
+
23
+ describe('PluginFlowEngine', () => {
24
+ beforeEach(() => {
25
+ detectedDeviceType.value = 'mobile';
26
+ });
27
+
28
+ it('should register the current device type before shared flow components', async () => {
29
+ const app = createMockClient({
30
+ router: {
31
+ type: 'memory',
32
+ initialEntries: ['/'],
33
+ },
34
+ });
35
+ const plugin = new PluginFlowEngine({}, app);
36
+ const addComponents = app.addComponents.bind(app);
37
+ const deviceTypesBeforeComponentRegistration: string[] = [];
38
+ vi.spyOn(app, 'addComponents').mockImplementation((components) => {
39
+ deviceTypesBeforeComponentRegistration.push(app.flowEngine.context.deviceType);
40
+ return addComponents(components);
41
+ });
42
+
43
+ await plugin.load();
44
+
45
+ expect(app.flowEngine.context.deviceType).toBe('mobile');
46
+ expect(deviceTypesBeforeComponentRegistration).toEqual(['mobile']);
47
+ });
48
+
49
+ it('should normalize the browser device type to computer', async () => {
50
+ detectedDeviceType.value = 'browser';
51
+ const app = createMockClient();
52
+ const plugin = new PluginFlowEngine({}, app);
53
+
54
+ await plugin.load();
55
+
56
+ expect(app.flowEngine.context.deviceType).toBe('computer');
57
+ });
58
+ });