@nocobase/client-v2 2.1.31 → 2.2.0-alpha.10
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.
- package/es/APIClient.d.ts +1 -3
- package/es/BaseApplication.d.ts +2 -0
- package/es/PluginSettingsManager.d.ts +33 -0
- package/es/RouteRepository.d.ts +29 -6
- package/es/RouterManager.d.ts +15 -0
- package/es/authRedirect.d.ts +1 -0
- package/es/components/category-tabs/SortableCategoryTabs.d.ts +55 -0
- package/es/components/category-tabs/index.d.ts +9 -0
- package/es/components/form/TypedVariableInput.d.ts +31 -5
- package/es/components/form/filter/CollectionFilter.d.ts +2 -0
- package/es/components/form/filter/CollectionFilterItem.d.ts +11 -1
- package/es/components/form/filter/CollectionFilterPanel.d.ts +2 -0
- package/es/components/form/filter/index.d.ts +2 -0
- package/es/components/form/filter/useFilterActionProps.d.ts +2 -0
- package/es/components/index.d.ts +2 -0
- package/es/entry-actions/EntryActionManager.d.ts +24 -0
- package/es/entry-actions/index.d.ts +9 -0
- package/es/flow/actions/index.d.ts +1 -1
- package/es/flow/actions/linkageRules.d.ts +2 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.d.ts +2 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuFlowUtils.d.ts +2 -1
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuModels.d.ts +3 -0
- package/es/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.d.ts +3 -2
- package/es/flow/admin-shell/admin-layout/AdminLayoutSlotModels.d.ts +5 -0
- package/es/flow/admin-shell/admin-layout/AppListRender.d.ts +2 -1
- package/es/flow/admin-shell/admin-layout/AppSwitcherActionPanelModel.d.ts +24 -0
- package/es/flow/admin-shell/admin-layout/index.d.ts +1 -0
- package/es/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.d.ts +6 -0
- package/es/flow/admin-shell/admin-layout/useApplications.d.ts +7 -2
- package/es/flow/components/FieldAssignExactDatePicker.d.ts +1 -0
- package/es/flow/components/FieldAssignValueInput.d.ts +9 -0
- package/es/flow/components/RunJSValueEditor.d.ts +1 -0
- package/es/flow/components/filter/FilterGroup.d.ts +1 -0
- package/es/flow/components/filter/VariableFilterItem.d.ts +6 -1
- package/es/flow/index.d.ts +1 -0
- package/es/flow/models/base/ActionModelCore.d.ts +2 -0
- package/es/flow/models/base/GridModel.d.ts +1 -1
- package/es/flow/models/base/PageModel/PageModel.d.ts +12 -0
- package/es/flow/models/base/PageModel/PageModelTabBar.d.ts +22 -0
- package/es/flow/models/base/PageModel/PageTabModel.d.ts +12 -0
- package/es/flow/models/blocks/form/value-runtime/runtime.d.ts +9 -0
- package/es/flow-compat/routeTypes.d.ts +1 -0
- package/es/index.d.ts +7 -1
- package/es/index.mjs +223 -135
- package/es/utils/getRouteRuntimeVersion.d.ts +23 -0
- package/es/utils/index.d.ts +1 -0
- package/lib/index.js +220 -132
- package/package.json +7 -7
- package/src/APIClient.ts +1 -10
- package/src/Application.tsx +4 -0
- package/src/BaseApplication.tsx +2 -0
- package/src/PluginSettingsManager.ts +53 -0
- package/src/RouteRepository.ts +151 -24
- package/src/RouterManager.tsx +142 -1
- package/src/__tests__/PluginSettingsManager.test.ts +13 -0
- package/src/__tests__/RouteRepository.test.ts +239 -0
- package/src/__tests__/RouterManager.test.ts +125 -0
- package/src/__tests__/app.test.tsx +18 -0
- package/src/__tests__/authRedirect.test.ts +17 -0
- package/src/__tests__/browserChecker.test.ts +61 -0
- package/src/__tests__/exports.test.ts +16 -0
- package/src/__tests__/getRouteRuntimeVersion.test.ts +68 -0
- package/src/__tests__/nocobase-buildin-plugin-auth.test.tsx +28 -0
- package/src/__tests__/plugin-manager.test.tsx +44 -2
- package/src/__tests__/settings-center.test.tsx +40 -1
- package/src/authRedirect.ts +38 -0
- package/src/components/README.md +7 -1
- package/src/components/README.zh-CN.md +6 -1
- package/src/components/category-tabs/SortableCategoryTabs.tsx +210 -0
- package/src/components/category-tabs/index.ts +10 -0
- package/src/components/form/JsonTextArea.tsx +4 -0
- package/src/components/form/TypedVariableInput.tsx +452 -101
- package/src/components/form/__tests__/TypedVariableInput.test.tsx +364 -12
- package/src/components/form/filter/CollectionFilter.tsx +4 -0
- package/src/components/form/filter/CollectionFilterItem.tsx +32 -7
- package/src/components/form/filter/CollectionFilterPanel.tsx +4 -0
- package/src/components/form/filter/__tests__/CollectionFilterItem.test.tsx +38 -0
- package/src/components/form/filter/__tests__/useFilterActionProps.test.tsx +95 -0
- package/src/components/form/filter/index.ts +2 -0
- package/src/components/form/filter/useFilterActionProps.ts +37 -6
- package/src/components/index.ts +2 -0
- package/src/entry-actions/EntryActionManager.ts +76 -0
- package/src/entry-actions/index.ts +10 -0
- package/src/flow/__tests__/FlowRoute.test.tsx +1084 -145
- package/src/flow/actions/__tests__/linkageRules.tab.test.ts +171 -0
- package/src/flow/actions/customVariable.tsx +1 -2
- package/src/flow/actions/index.ts +2 -0
- package/src/flow/actions/linkageRules.tsx +65 -8
- package/src/flow/actions/runjs.tsx +2 -14
- package/src/flow/admin-shell/BaseLayoutModel.tsx +13 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutComponent.tsx +46 -13
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.test.tsx +486 -0
- package/src/flow/admin-shell/admin-layout/AdminLayoutEntryGuard.tsx +64 -8
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuFlowUtils.ts +5 -3
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuModels.tsx +61 -9
- package/src/flow/admin-shell/admin-layout/AdminLayoutMenuUtils.tsx +71 -8
- package/src/flow/admin-shell/admin-layout/AdminLayoutModel.tsx +1 -1
- package/src/flow/admin-shell/admin-layout/AdminLayoutSlotModels.tsx +23 -9
- package/src/flow/admin-shell/admin-layout/AppListRender.tsx +13 -2
- package/src/flow/admin-shell/admin-layout/AppSwitcherActionPanelModel.tsx +289 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutComponent.test.tsx +435 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutMenuModels.test.ts +99 -0
- package/src/flow/admin-shell/admin-layout/__tests__/AdminLayoutModel.test.tsx +77 -0
- package/src/flow/admin-shell/admin-layout/__tests__/TopbarActionsBar.test.tsx +214 -2
- package/src/flow/admin-shell/admin-layout/index.ts +1 -0
- package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.test.ts +20 -0
- package/src/flow/admin-shell/admin-layout/resolveAdminRouteRuntimeTarget.ts +33 -5
- package/src/flow/admin-shell/admin-layout/useApplications.tsx +81 -12
- package/src/flow/components/DefaultValue.tsx +1 -2
- package/src/flow/components/FieldAssignExactDatePicker.tsx +25 -11
- package/src/flow/components/FieldAssignValueInput.tsx +76 -9
- package/src/flow/components/FlowRoute.tsx +185 -28
- package/src/flow/components/RunJSValueEditor.tsx +9 -1
- package/src/flow/components/__tests__/FieldAssignValueInput.context.test.tsx +84 -2
- package/src/flow/components/code-editor/__tests__/useCodeRunner.test.tsx +2 -17
- package/src/flow/components/code-editor/hooks/useCodeRunner.ts +2 -14
- package/src/flow/components/code-editor/runjsDiagnostics.ts +8 -45
- package/src/flow/components/filter/FilterGroup.tsx +33 -5
- package/src/flow/components/filter/VariableFilterItem.tsx +158 -10
- package/src/flow/components/filter/__tests__/FilterGroup.test.tsx +45 -0
- package/src/flow/components/filter/__tests__/VariableFilterItem.leftMetaTree.test.tsx +9 -0
- package/src/flow/components/filter/__tests__/VariableFilterItem.test.tsx +70 -1
- package/src/flow/index.ts +1 -0
- package/src/flow/models/actions/JSActionModel.tsx +2 -7
- package/src/flow/models/actions/JSCollectionActionModel.tsx +2 -7
- package/src/flow/models/actions/JSItemActionModel.tsx +2 -7
- package/src/flow/models/actions/JSRecordActionModel.tsx +2 -7
- package/src/flow/models/base/ActionModel.tsx +21 -8
- package/src/flow/models/base/ActionModelCore.tsx +5 -0
- package/src/flow/models/base/GridModel.tsx +38 -7
- package/src/flow/models/base/PageModel/PageModel.tsx +387 -53
- package/src/flow/models/base/PageModel/PageModelTabBar.tsx +114 -0
- package/src/flow/models/base/PageModel/PageTabModel.tsx +186 -3
- package/src/flow/models/base/PageModel/__tests__/PageModel.test.ts +790 -14
- package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.module-isolation.test.tsx +130 -0
- package/src/flow/models/base/PageModel/__tests__/PageModelTabBar.test.tsx +118 -0
- package/src/flow/models/base/PageModel/__tests__/PageTabModel.test.ts +586 -1
- package/src/flow/models/base/__tests__/ActionModel.test.ts +83 -0
- package/src/flow/models/base/__tests__/GridModel.dragSnapshotContainer.test.ts +239 -1
- package/src/flow/models/base/__tests__/transformRowsToSingleColumn.test.ts +48 -0
- package/src/flow/models/blocks/filter-form/FilterFormBlockModel.tsx +1 -2
- package/src/flow/models/blocks/filter-form/FilterFormJSActionModel.tsx +2 -7
- package/src/flow/models/blocks/form/JSFormActionModel.tsx +2 -7
- package/src/flow/models/blocks/form/value-runtime/__tests__/runtime.test.ts +87 -0
- package/src/flow/models/blocks/form/value-runtime/rules.ts +2 -2
- package/src/flow/models/blocks/form/value-runtime/runtime.ts +91 -0
- package/src/flow/models/blocks/js-block/JSBlock.tsx +2 -7
- package/src/flow/models/blocks/table/JSColumnModel.tsx +1 -9
- package/src/flow/models/blocks/table/TableActionsColumnModel.tsx +1 -1
- package/src/flow/models/blocks/table/TableBlockModel.tsx +13 -3
- package/src/flow/models/blocks/table/__tests__/TableActionsColumnModel.test.tsx +54 -0
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.mobileSettingsButtons.test.tsx +78 -0
- package/src/flow/models/fields/JSEditableFieldModel.tsx +2 -11
- package/src/flow/models/fields/JSFieldModel.tsx +2 -7
- package/src/flow/models/fields/JSItemModel.tsx +2 -14
- package/src/flow/models/fields/VariableFieldFormModel.tsx +3 -3
- package/src/flow/models/fields/__tests__/VariableFieldFormModel.test.tsx +51 -0
- package/src/flow/models/topbar/TopbarActionModel.tsx +168 -10
- package/src/flow-compat/Popover.tsx +43 -4
- package/src/flow-compat/__tests__/Popover.test.tsx +34 -0
- package/src/flow-compat/routeTypes.ts +1 -0
- package/src/index.ts +13 -1
- package/src/layout-manager/__tests__/LayoutRoute.test.tsx +41 -1
- package/src/nocobase-buildin-plugin/index.tsx +19 -3
- package/src/settings-center/AdminSettingsLayout.tsx +10 -2
- package/src/settings-center/SystemSettingsPage.tsx +0 -1
- package/src/settings-center/plugin-manager/PluginCard.tsx +2 -2
- package/src/settings-center/utils.tsx +0 -6
- package/src/utils/getRouteRuntimeVersion.ts +185 -0
- package/src/utils/index.tsx +1 -0
|
@@ -0,0 +1,239 @@
|
|
|
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 { describe, expect, it, vi } from 'vitest';
|
|
11
|
+
import type { NocoBaseDesktopRoute } from '../flow-compat';
|
|
12
|
+
import { RouteRepository } from '../RouteRepository';
|
|
13
|
+
|
|
14
|
+
function createRouteRepository() {
|
|
15
|
+
const request = vi.fn().mockResolvedValue({
|
|
16
|
+
data: {
|
|
17
|
+
data: [],
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
const create = vi.fn().mockResolvedValue({
|
|
21
|
+
data: {
|
|
22
|
+
data: {},
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
const resource = vi.fn(() => ({
|
|
26
|
+
create,
|
|
27
|
+
}));
|
|
28
|
+
const repository = new RouteRepository({
|
|
29
|
+
api: {
|
|
30
|
+
request,
|
|
31
|
+
resource,
|
|
32
|
+
},
|
|
33
|
+
} as never);
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
create,
|
|
37
|
+
repository,
|
|
38
|
+
request,
|
|
39
|
+
resource,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function route(schemaUid: string): NocoBaseDesktopRoute {
|
|
44
|
+
return { schemaUid } as NocoBaseDesktopRoute;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
describe('RouteRepository', () => {
|
|
48
|
+
it('should pass the default admin layout when loading accessible routes', async () => {
|
|
49
|
+
const { repository, request } = createRouteRepository();
|
|
50
|
+
|
|
51
|
+
await repository.refreshAccessible();
|
|
52
|
+
|
|
53
|
+
expect(request).toHaveBeenCalledWith({
|
|
54
|
+
url: '/desktopRoutes:listAccessible',
|
|
55
|
+
params: {
|
|
56
|
+
tree: true,
|
|
57
|
+
sort: 'sort',
|
|
58
|
+
layout: 'admin-layout-model',
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should pass the active client-v2 layout when loading accessible routes', async () => {
|
|
64
|
+
const { repository, request } = createRouteRepository();
|
|
65
|
+
const deactivateLayout = repository.activateLayout({
|
|
66
|
+
uid: 'custom-desktop-layout-model',
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
await repository.refreshAccessible();
|
|
70
|
+
deactivateLayout();
|
|
71
|
+
|
|
72
|
+
expect(request).toHaveBeenCalledWith({
|
|
73
|
+
url: '/desktopRoutes:listAccessible',
|
|
74
|
+
params: {
|
|
75
|
+
tree: true,
|
|
76
|
+
sort: 'sort',
|
|
77
|
+
layout: 'custom-desktop-layout-model',
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should reload accessible routes when the active client-v2 layout changes', async () => {
|
|
83
|
+
const { repository, request } = createRouteRepository();
|
|
84
|
+
const deactivateFirstLayout = repository.activateLayout({
|
|
85
|
+
uid: 'first-layout-model',
|
|
86
|
+
});
|
|
87
|
+
await repository.ensureAccessibleLoaded();
|
|
88
|
+
deactivateFirstLayout();
|
|
89
|
+
|
|
90
|
+
const deactivateSecondLayout = repository.activateLayout({
|
|
91
|
+
uid: 'second-layout-model',
|
|
92
|
+
});
|
|
93
|
+
await repository.ensureAccessibleLoaded();
|
|
94
|
+
deactivateSecondLayout();
|
|
95
|
+
|
|
96
|
+
expect(request).toHaveBeenNthCalledWith(1, {
|
|
97
|
+
url: '/desktopRoutes:listAccessible',
|
|
98
|
+
params: {
|
|
99
|
+
tree: true,
|
|
100
|
+
sort: 'sort',
|
|
101
|
+
layout: 'first-layout-model',
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
expect(request).toHaveBeenNthCalledWith(2, {
|
|
105
|
+
url: '/desktopRoutes:listAccessible',
|
|
106
|
+
params: {
|
|
107
|
+
tree: true,
|
|
108
|
+
sort: 'sort',
|
|
109
|
+
layout: 'second-layout-model',
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('should report accessible routes as unloaded when the active layout changes', () => {
|
|
115
|
+
const { repository } = createRouteRepository();
|
|
116
|
+
|
|
117
|
+
repository.setRoutes([], 'first-layout-model');
|
|
118
|
+
const deactivateLayout = repository.activateLayout({
|
|
119
|
+
uid: 'second-layout-model',
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
expect(repository.isAccessibleLoaded()).toBe(false);
|
|
123
|
+
deactivateLayout();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('should keep accessible route caches isolated by active layout', () => {
|
|
127
|
+
const { repository } = createRouteRepository();
|
|
128
|
+
|
|
129
|
+
repository.setRoutes([route('admin-page')], 'admin-layout-model');
|
|
130
|
+
const deactivateLayout = repository.activateLayout({
|
|
131
|
+
uid: 'custom-desktop-layout-model',
|
|
132
|
+
});
|
|
133
|
+
repository.setRoutes([route('custom-page')], 'custom-desktop-layout-model');
|
|
134
|
+
|
|
135
|
+
expect(repository.listAccessible().map((route) => route.schemaUid)).toEqual(['custom-page']);
|
|
136
|
+
expect(repository.getRouteBySchemaUid('admin-page')).toBeUndefined();
|
|
137
|
+
deactivateLayout();
|
|
138
|
+
|
|
139
|
+
expect(repository.listAccessible().map((route) => route.schemaUid)).toEqual(['admin-page']);
|
|
140
|
+
expect(repository.getRouteBySchemaUid('custom-page')).toBeUndefined();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('should find nested routes by id', () => {
|
|
144
|
+
const { repository } = createRouteRepository();
|
|
145
|
+
|
|
146
|
+
repository.setRoutes([
|
|
147
|
+
{
|
|
148
|
+
id: 1,
|
|
149
|
+
schemaUid: 'group-1',
|
|
150
|
+
children: [
|
|
151
|
+
{
|
|
152
|
+
id: 11,
|
|
153
|
+
schemaUid: 'page-1',
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
},
|
|
157
|
+
] as NocoBaseDesktopRoute[]);
|
|
158
|
+
|
|
159
|
+
expect(repository.getRouteById('11')).toMatchObject({
|
|
160
|
+
id: 11,
|
|
161
|
+
schemaUid: 'page-1',
|
|
162
|
+
});
|
|
163
|
+
expect(repository.getRouteById('missing')).toBeUndefined();
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('should notify only subscribers for the changed layout cache', () => {
|
|
167
|
+
const { repository } = createRouteRepository();
|
|
168
|
+
const adminEvents: string[][] = [];
|
|
169
|
+
const customEvents: string[][] = [];
|
|
170
|
+
|
|
171
|
+
const unsubscribeAdmin = repository.subscribe(() => {
|
|
172
|
+
adminEvents.push(repository.listAccessible().map((route) => route.schemaUid || ''));
|
|
173
|
+
});
|
|
174
|
+
const deactivateLayout = repository.activateLayout({
|
|
175
|
+
uid: 'custom-desktop-layout-model',
|
|
176
|
+
});
|
|
177
|
+
const unsubscribeCustom = repository.subscribe(() => {
|
|
178
|
+
customEvents.push(repository.listAccessible().map((route) => route.schemaUid || ''));
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
repository.setRoutes([route('custom-page')], 'custom-desktop-layout-model');
|
|
182
|
+
|
|
183
|
+
expect(adminEvents).toEqual([]);
|
|
184
|
+
expect(customEvents).toEqual([['custom-page']]);
|
|
185
|
+
|
|
186
|
+
deactivateLayout();
|
|
187
|
+
repository.setRoutes([route('admin-page')], 'admin-layout-model');
|
|
188
|
+
|
|
189
|
+
expect(adminEvents).toEqual([['admin-page']]);
|
|
190
|
+
expect(customEvents).toEqual([['custom-page']]);
|
|
191
|
+
|
|
192
|
+
unsubscribeAdmin();
|
|
193
|
+
unsubscribeCustom();
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it('should pass the default admin layout when creating a route', async () => {
|
|
197
|
+
const { repository, create } = createRouteRepository();
|
|
198
|
+
|
|
199
|
+
await repository.createRoute(
|
|
200
|
+
{
|
|
201
|
+
title: 'Admin page',
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
refreshAfterMutation: false,
|
|
205
|
+
},
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
expect(create).toHaveBeenCalledWith({
|
|
209
|
+
values: {
|
|
210
|
+
title: 'Admin page',
|
|
211
|
+
},
|
|
212
|
+
layout: 'admin-layout-model',
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('should pass the active client-v2 layout when creating a route', async () => {
|
|
217
|
+
const { repository, create } = createRouteRepository();
|
|
218
|
+
const deactivateLayout = repository.activateLayout({
|
|
219
|
+
uid: 'custom-desktop-layout-model',
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
await repository.createRoute(
|
|
223
|
+
{
|
|
224
|
+
title: 'Custom page',
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
refreshAfterMutation: false,
|
|
228
|
+
},
|
|
229
|
+
);
|
|
230
|
+
deactivateLayout();
|
|
231
|
+
|
|
232
|
+
expect(create).toHaveBeenCalledWith({
|
|
233
|
+
values: {
|
|
234
|
+
title: 'Custom page',
|
|
235
|
+
},
|
|
236
|
+
layout: 'custom-desktop-layout-model',
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
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 type { BaseApplication } from '../BaseApplication';
|
|
11
|
+
import { RouterManager, shouldOpenAdminRouteInNewWindow } from '../RouterManager';
|
|
12
|
+
|
|
13
|
+
describe('RouterManager', () => {
|
|
14
|
+
describe('shouldOpenAdminRouteInNewWindow', () => {
|
|
15
|
+
it('opens admin route in a new window from a non-admin portal', () => {
|
|
16
|
+
expect(
|
|
17
|
+
shouldOpenAdminRouteInNewWindow({
|
|
18
|
+
currentPathname: '/v/test',
|
|
19
|
+
targetPathname: '/admin/settings',
|
|
20
|
+
basePath: '/v',
|
|
21
|
+
adminRoutePath: '/admin',
|
|
22
|
+
}),
|
|
23
|
+
).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('supports target pathname with the v2 base path', () => {
|
|
27
|
+
expect(
|
|
28
|
+
shouldOpenAdminRouteInNewWindow({
|
|
29
|
+
currentPathname: '/nocobase/v/test',
|
|
30
|
+
targetPathname: '/nocobase/v/admin/settings',
|
|
31
|
+
basePath: '/nocobase/v',
|
|
32
|
+
adminRoutePath: '/admin',
|
|
33
|
+
}),
|
|
34
|
+
).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('supports custom portal routes in sub-apps', () => {
|
|
38
|
+
expect(
|
|
39
|
+
shouldOpenAdminRouteInNewWindow({
|
|
40
|
+
currentPathname: '/v/apps/a_9xlild35jir/crm-amd/ekeisumx1zu',
|
|
41
|
+
targetPathname: '/v/apps/a_9xlild35jir/admin/settings',
|
|
42
|
+
basePath: '/v',
|
|
43
|
+
adminRoutePath: '/admin',
|
|
44
|
+
}),
|
|
45
|
+
).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('keeps admin route navigation in the current window when already in sub-app admin', () => {
|
|
49
|
+
expect(
|
|
50
|
+
shouldOpenAdminRouteInNewWindow({
|
|
51
|
+
currentPathname: '/v/apps/a_9xlild35jir/admin',
|
|
52
|
+
targetPathname: '/v/apps/a_9xlild35jir/admin/settings',
|
|
53
|
+
basePath: '/v',
|
|
54
|
+
adminRoutePath: '/admin',
|
|
55
|
+
}),
|
|
56
|
+
).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('keeps admin route navigation in the current window when already in admin', () => {
|
|
60
|
+
expect(
|
|
61
|
+
shouldOpenAdminRouteInNewWindow({
|
|
62
|
+
currentPathname: '/v/admin',
|
|
63
|
+
targetPathname: '/admin/settings',
|
|
64
|
+
basePath: '/v',
|
|
65
|
+
adminRoutePath: '/admin',
|
|
66
|
+
}),
|
|
67
|
+
).toBe(false);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('keeps non-admin portal navigation in the current window', () => {
|
|
71
|
+
expect(
|
|
72
|
+
shouldOpenAdminRouteInNewWindow({
|
|
73
|
+
currentPathname: '/v/test',
|
|
74
|
+
targetPathname: '/test/page',
|
|
75
|
+
basePath: '/v',
|
|
76
|
+
adminRoutePath: '/admin',
|
|
77
|
+
}),
|
|
78
|
+
).toBe(false);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('does not intercept replace navigation or relative paths', () => {
|
|
82
|
+
expect(
|
|
83
|
+
shouldOpenAdminRouteInNewWindow({
|
|
84
|
+
currentPathname: '/v/test',
|
|
85
|
+
targetPathname: '/admin/settings',
|
|
86
|
+
basePath: '/v',
|
|
87
|
+
adminRoutePath: '/admin',
|
|
88
|
+
replace: true,
|
|
89
|
+
}),
|
|
90
|
+
).toBe(false);
|
|
91
|
+
expect(
|
|
92
|
+
shouldOpenAdminRouteInNewWindow({
|
|
93
|
+
currentPathname: '/v/test',
|
|
94
|
+
targetPathname: 'admin/settings',
|
|
95
|
+
basePath: '/v',
|
|
96
|
+
adminRoutePath: '/admin',
|
|
97
|
+
}),
|
|
98
|
+
).toBe(false);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('opens admin route in a new window through the underlying router navigate from a sub-app portal', async () => {
|
|
103
|
+
const app = {
|
|
104
|
+
name: 'a_9xlild35jir',
|
|
105
|
+
getPublicPath: () => '/v/',
|
|
106
|
+
getHref: (pathname: string) => `/v/apps/a_9xlild35jir/${pathname.replace(/^\/+/, '')}`,
|
|
107
|
+
layoutManager: {
|
|
108
|
+
getLayout: () => ({ routePath: '/admin' }),
|
|
109
|
+
},
|
|
110
|
+
renderComponent: () => null,
|
|
111
|
+
} as unknown as BaseApplication<unknown>;
|
|
112
|
+
const manager = new RouterManager({ type: 'browser' }, app);
|
|
113
|
+
const open = vi.spyOn(window, 'open').mockImplementation(() => null);
|
|
114
|
+
|
|
115
|
+
window.history.pushState({}, '', '/v/apps/a_9xlild35jir/crm-amd/ekeisumx1zu');
|
|
116
|
+
manager.getRouterComponent();
|
|
117
|
+
await manager.router.navigate('/admin/settings/version-control/list');
|
|
118
|
+
|
|
119
|
+
expect(open).toHaveBeenCalledWith(
|
|
120
|
+
'/v/apps/a_9xlild35jir/admin/settings/version-control/list',
|
|
121
|
+
'_blank',
|
|
122
|
+
'noopener,noreferrer',
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
@@ -52,6 +52,24 @@ describe('app', () => {
|
|
|
52
52
|
expect(app.getHref('/test')).toBe('/test');
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
+
it('should enable credentials for api clients by default', () => {
|
|
56
|
+
const sameOriginApp = new Application({
|
|
57
|
+
router,
|
|
58
|
+
apiClient: {
|
|
59
|
+
baseURL: '/api/',
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
const crossOriginApp = new Application({
|
|
63
|
+
router,
|
|
64
|
+
apiClient: {
|
|
65
|
+
baseURL: 'https://api.example.com/api/',
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
expect(sameOriginApp.apiClient.axios.defaults.withCredentials).toBe(true);
|
|
70
|
+
expect(crossOriginApp.apiClient.axios.defaults.withCredentials).toBe(true);
|
|
71
|
+
});
|
|
72
|
+
|
|
55
73
|
it('should initialize shared jsonLogic operators', () => {
|
|
56
74
|
const app = new Application({ router });
|
|
57
75
|
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import {
|
|
11
11
|
buildV2SigninHref,
|
|
12
12
|
getCurrentV2RedirectPath,
|
|
13
|
+
normalizeV2RedirectPath,
|
|
13
14
|
redirectToV2Signin,
|
|
14
15
|
resolveV2SigninRedirect,
|
|
15
16
|
} from '../authRedirect';
|
|
@@ -133,6 +134,22 @@ describe('auth redirect helpers', () => {
|
|
|
133
134
|
});
|
|
134
135
|
|
|
135
136
|
describe('v2 sub-app context (router basename contains /apps/<id>/)', () => {
|
|
137
|
+
it('should normalize signin redirect fallback under the current sub-app basename', () => {
|
|
138
|
+
const app = {
|
|
139
|
+
getPublicPath: () => '/v/',
|
|
140
|
+
router: {
|
|
141
|
+
getBasename: () => '/v/apps/test-app/',
|
|
142
|
+
},
|
|
143
|
+
} as any;
|
|
144
|
+
|
|
145
|
+
expect(normalizeV2RedirectPath(app, '')).toBe('/v/apps/test-app/admin/');
|
|
146
|
+
expect(normalizeV2RedirectPath(app, '/admin/?tab=overview#panel')).toBe(
|
|
147
|
+
'/v/apps/test-app/admin/?tab=overview#panel',
|
|
148
|
+
);
|
|
149
|
+
expect(normalizeV2RedirectPath(app, '/v/apps/test-app/admin/')).toBe('/v/apps/test-app/admin/');
|
|
150
|
+
expect(normalizeV2RedirectPath(app, '/v/admin/')).toBe('/v/apps/test-app/admin/');
|
|
151
|
+
});
|
|
152
|
+
|
|
136
153
|
it('should preserve sub-app segment when building current redirect path under simple public path', () => {
|
|
137
154
|
const app = {
|
|
138
155
|
getPublicPath: () => '/v2/',
|
|
@@ -15,6 +15,8 @@ import { fileURLToPath } from 'node:url';
|
|
|
15
15
|
type BrowserCheckerCase = {
|
|
16
16
|
pathname: string;
|
|
17
17
|
publicPath: string;
|
|
18
|
+
modernClientPrefix?: string;
|
|
19
|
+
appClientEntryMode?: string;
|
|
18
20
|
expectedRedirect?: string;
|
|
19
21
|
};
|
|
20
22
|
|
|
@@ -40,6 +42,8 @@ function executeBrowserChecker(scriptPath: string, input: BrowserCheckerCase) {
|
|
|
40
42
|
showLog: false,
|
|
41
43
|
window: {
|
|
42
44
|
__nocobase_public_path__: input.publicPath,
|
|
45
|
+
__nocobase_modern_client_prefix__: input.modernClientPrefix,
|
|
46
|
+
__nocobase_app_client_entry_mode__: input.appClientEntryMode,
|
|
43
47
|
location: {
|
|
44
48
|
origin: 'http://c.local.nocobase.com',
|
|
45
49
|
pathname: input.pathname,
|
|
@@ -109,4 +113,61 @@ describe.each(browserCheckerCases)('$label', ({ scriptPath }) => {
|
|
|
109
113
|
|
|
110
114
|
expect(replace).not.toHaveBeenCalled();
|
|
111
115
|
});
|
|
116
|
+
|
|
117
|
+
if (scriptPath.includes('/app/client/public/')) {
|
|
118
|
+
it('redirects app root to modern entry for modern-default', () => {
|
|
119
|
+
const replace = executeBrowserChecker(scriptPath, {
|
|
120
|
+
pathname: '/',
|
|
121
|
+
publicPath: '/',
|
|
122
|
+
modernClientPrefix: 'v',
|
|
123
|
+
appClientEntryMode: 'modern-default',
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
expect(replace).toHaveBeenCalledWith('http://c.local.nocobase.com/v/');
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('does not redirect legacy deep links for modern-default', () => {
|
|
130
|
+
const replace = executeBrowserChecker(scriptPath, {
|
|
131
|
+
pathname: '/admin',
|
|
132
|
+
publicPath: '/',
|
|
133
|
+
modernClientPrefix: 'v',
|
|
134
|
+
appClientEntryMode: 'modern-default',
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
expect(replace).not.toHaveBeenCalled();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('rewrites legacy document paths for modern-only', () => {
|
|
141
|
+
const replace = executeBrowserChecker(scriptPath, {
|
|
142
|
+
pathname: '/admin/settings/workflow',
|
|
143
|
+
publicPath: '/',
|
|
144
|
+
modernClientPrefix: 'v',
|
|
145
|
+
appClientEntryMode: 'modern-only',
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
expect(replace).toHaveBeenCalledWith('http://c.local.nocobase.com/v/admin/settings/workflow');
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('redirects sub-path site root directly to final modern target', () => {
|
|
152
|
+
const replace = executeBrowserChecker(scriptPath, {
|
|
153
|
+
pathname: '/nocobase/',
|
|
154
|
+
publicPath: '/nocobase/',
|
|
155
|
+
modernClientPrefix: 'v',
|
|
156
|
+
appClientEntryMode: 'modern-default',
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
expect(replace).toHaveBeenCalledWith('http://c.local.nocobase.com/nocobase/v/');
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('rewrites sub-app legacy deep links for modern-only without collapsing the sub-app segment', () => {
|
|
163
|
+
const replace = executeBrowserChecker(scriptPath, {
|
|
164
|
+
pathname: '/nocobase/apps/a_31itq60q4kg/admin/',
|
|
165
|
+
publicPath: '/nocobase/',
|
|
166
|
+
modernClientPrefix: 'v',
|
|
167
|
+
appClientEntryMode: 'modern-only',
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
expect(replace).toHaveBeenCalledWith('http://c.local.nocobase.com/nocobase/v/apps/a_31itq60q4kg/admin');
|
|
171
|
+
});
|
|
172
|
+
}
|
|
112
173
|
});
|
|
@@ -0,0 +1,16 @@
|
|
|
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 { IconPicker } from '..';
|
|
11
|
+
|
|
12
|
+
describe('@nocobase/client-v2 exports', () => {
|
|
13
|
+
it('should export IconPicker from the root entry', () => {
|
|
14
|
+
expect(IconPicker).toBeDefined();
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
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 { afterEach, describe, expect, it } from 'vitest';
|
|
11
|
+
import { getRouteRuntimeVersion } from '../utils/getRouteRuntimeVersion';
|
|
12
|
+
|
|
13
|
+
function replacePathname(pathname: string) {
|
|
14
|
+
Object.defineProperty(window, 'location', {
|
|
15
|
+
configurable: true,
|
|
16
|
+
value: {
|
|
17
|
+
...window.location,
|
|
18
|
+
pathname,
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe('getRouteRuntimeVersion', () => {
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
delete window.__nocobase_modern_client_prefix__;
|
|
26
|
+
delete window.__nocobase_public_path__;
|
|
27
|
+
replacePathname('/');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('returns modern when the current pathname is inside the modern client prefix', () => {
|
|
31
|
+
window.__nocobase_modern_client_prefix__ = 'v';
|
|
32
|
+
window.__nocobase_public_path__ = '/nocobase/v/';
|
|
33
|
+
replacePathname('/nocobase/v/admin/settings/workflow');
|
|
34
|
+
|
|
35
|
+
expect(getRouteRuntimeVersion()).toBe('modern');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('returns legacy when reused v2 components run under the v1 settings page', () => {
|
|
39
|
+
window.__nocobase_modern_client_prefix__ = 'v';
|
|
40
|
+
window.__nocobase_public_path__ = '/nocobase/';
|
|
41
|
+
replacePathname('/nocobase/admin/settings/workflow/workflows/123');
|
|
42
|
+
|
|
43
|
+
expect(getRouteRuntimeVersion()).toBe('legacy');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('returns legacy when root public path is "/"', () => {
|
|
47
|
+
window.__nocobase_modern_client_prefix__ = 'v';
|
|
48
|
+
window.__nocobase_public_path__ = '/';
|
|
49
|
+
replacePathname('/admin/settings/workflow/workflows/123');
|
|
50
|
+
|
|
51
|
+
expect(getRouteRuntimeVersion()).toBe('legacy');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('returns modern when root public path is "/v/"', () => {
|
|
55
|
+
window.__nocobase_modern_client_prefix__ = 'v';
|
|
56
|
+
window.__nocobase_public_path__ = '/v/';
|
|
57
|
+
replacePathname('/v/admin/workflow/workflows/123');
|
|
58
|
+
|
|
59
|
+
expect(getRouteRuntimeVersion()).toBe('modern');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('falls back to pathname matching when public path is unavailable', () => {
|
|
63
|
+
window.__nocobase_modern_client_prefix__ = 'v';
|
|
64
|
+
replacePathname('/v/admin/workflow/workflows/123');
|
|
65
|
+
|
|
66
|
+
expect(getRouteRuntimeVersion()).toBe('modern');
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -55,6 +55,7 @@ describe('nocobase buildin plugin auth redirect', () => {
|
|
|
55
55
|
const originalLocation = globalThis.window.location;
|
|
56
56
|
|
|
57
57
|
beforeEach(() => {
|
|
58
|
+
globalThis.window.localStorage.clear();
|
|
58
59
|
// These fixtures mount the modern client under the `v2` segment; tell the
|
|
59
60
|
// runtime-prefix helper so v2-runtime detection matches (server injects it
|
|
60
61
|
// in production).
|
|
@@ -75,6 +76,7 @@ describe('nocobase buildin plugin auth redirect', () => {
|
|
|
75
76
|
});
|
|
76
77
|
|
|
77
78
|
afterEach(() => {
|
|
79
|
+
globalThis.window.localStorage.clear();
|
|
78
80
|
delete (globalThis.window as any).__nocobase_modern_client_prefix__;
|
|
79
81
|
Object.defineProperty(globalThis.window, 'location', {
|
|
80
82
|
configurable: true,
|
|
@@ -116,6 +118,7 @@ describe('nocobase buildin plugin auth redirect', () => {
|
|
|
116
118
|
plugins: [NocoBaseBuildInPlugin as any],
|
|
117
119
|
router: { type: 'memory', initialEntries: ['/v2/admin'] },
|
|
118
120
|
});
|
|
121
|
+
app.apiClient.auth.setToken('test-token');
|
|
119
122
|
app.apiMock.onGet('app:getLang').reply(200, {
|
|
120
123
|
data: { lang: 'en-US', resources: { client: {} }, cron: {} },
|
|
121
124
|
});
|
|
@@ -130,6 +133,7 @@ describe('nocobase buildin plugin auth redirect', () => {
|
|
|
130
133
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
131
134
|
expect(app.router.router.state.location.pathname).toBe('/v2/admin');
|
|
132
135
|
expect(app.router.router.state.location.search).toBe('');
|
|
136
|
+
expect(app.apiMock.history.post.filter((request) => request.url === 'auth:syncCookies')).toHaveLength(0);
|
|
133
137
|
});
|
|
134
138
|
|
|
135
139
|
it('should redirect unauthenticated v2 root access to v2 signin via <Navigate />', async () => {
|
|
@@ -326,6 +330,29 @@ describe('nocobase buildin plugin auth redirect', () => {
|
|
|
326
330
|
data: { lang: 'en-US', resources: { client: {} }, cron: {} },
|
|
327
331
|
});
|
|
328
332
|
app.apiMock.onGet('/auth:check').reply(200, { data: { id: 1 } });
|
|
333
|
+
app.apiMock.onPost('auth:syncCookies').reply(200, { data: { synced: true } });
|
|
334
|
+
const ensureLoaded = vi.spyOn(app.dataSourceManager, 'ensureLoaded').mockResolvedValue(undefined);
|
|
335
|
+
|
|
336
|
+
const Root = app.getRootComponent();
|
|
337
|
+
render(<Root />);
|
|
338
|
+
|
|
339
|
+
expect(await screen.findByText('secure page')).toBeInTheDocument();
|
|
340
|
+
expect(ensureLoaded).toHaveBeenCalledTimes(1);
|
|
341
|
+
expect(app.apiMock.history.post.filter((request) => request.url === 'auth:syncCookies')).toHaveLength(1);
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it('should keep authenticated v2 startup working when cookie bootstrap fails', async () => {
|
|
345
|
+
const app = createMockClient({
|
|
346
|
+
publicPath: '/v2/',
|
|
347
|
+
plugins: [NocoBaseBuildInPlugin as any, AuthBootstrapRoutePlugin as any],
|
|
348
|
+
router: { type: 'memory', initialEntries: ['/v2/secure'] },
|
|
349
|
+
});
|
|
350
|
+
app.apiClient.auth.setToken('test-token');
|
|
351
|
+
app.apiMock.onGet('app:getLang').reply(200, {
|
|
352
|
+
data: { lang: 'en-US', resources: { client: {} }, cron: {} },
|
|
353
|
+
});
|
|
354
|
+
app.apiMock.onGet('/auth:check').reply(200, { data: { id: 1 } });
|
|
355
|
+
app.apiMock.onPost('auth:syncCookies').reply(500, { errors: [{ message: 'cookie sync failed' }] });
|
|
329
356
|
const ensureLoaded = vi.spyOn(app.dataSourceManager, 'ensureLoaded').mockResolvedValue(undefined);
|
|
330
357
|
|
|
331
358
|
const Root = app.getRootComponent();
|
|
@@ -333,6 +360,7 @@ describe('nocobase buildin plugin auth redirect', () => {
|
|
|
333
360
|
|
|
334
361
|
expect(await screen.findByText('secure page')).toBeInTheDocument();
|
|
335
362
|
expect(ensureLoaded).toHaveBeenCalledTimes(1);
|
|
363
|
+
expect(app.apiMock.history.post.filter((request) => request.url === 'auth:syncCookies')).toHaveLength(1);
|
|
336
364
|
});
|
|
337
365
|
|
|
338
366
|
it('should not auth-check or bootstrap authCheck false routes', async () => {
|