Repository navigation
Expand file tree
/
Copy pathappRoute.test.ts
More file actions
401 lines (354 loc) · 18.9 KB
/
Copy pathappRoute.test.ts
File metadata and controls
401 lines (354 loc) · 18.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
import { describe, it, expect } from 'vitest';
import { appRouteSegment, matchAppBySegment, appAddressSegment, canonicalAppPathname, filterActiveApps, resolveHostAppSegment, resolveApprovalsHostSegment, isApprovalsInboxLink, appStudioDesignPath, appStudioSurfacePath, appStudioObjectPath, appStudioRoutePath } from '../appRoute';
/**
* ADR-0048 (option A) — package-id route segment.
*/
describe('appRouteSegment', () => {
it('returns the package id when present', () => {
expect(appRouteSegment({ name: 'crm', _packageId: 'com.acme.crm' })).toBe('com.acme.crm');
});
it('falls back to the app name when no package id', () => {
expect(appRouteSegment({ name: 'crm' })).toBe('crm');
});
it('returns undefined for nullish input', () => {
expect(appRouteSegment(undefined)).toBeUndefined();
expect(appRouteSegment(null)).toBeUndefined();
});
});
describe('matchAppBySegment', () => {
const crm = { name: 'crm', _packageId: 'com.acme.crm' };
const hr = { name: 'crm', _packageId: 'com.beta.crm' }; // same display name, different vendor
const apps = [crm, hr];
it('matches by package id (disambiguates same-named apps)', () => {
expect(matchAppBySegment(apps, 'com.acme.crm')).toBe(crm);
expect(matchAppBySegment(apps, 'com.beta.crm')).toBe(hr);
});
it('falls back to matching by name (legacy/alias URL)', () => {
expect(matchAppBySegment([{ name: 'sales' }], 'sales')).toEqual({ name: 'sales' });
});
it('prefers a package-id match over a name match', () => {
const byName = { name: 'com.acme.crm' }; // pathological: an app literally named like a pkg id
expect(matchAppBySegment([byName, crm], 'com.acme.crm')).toBe(crm);
});
it('returns undefined for missing inputs', () => {
expect(matchAppBySegment(apps, undefined)).toBeUndefined();
expect(matchAppBySegment(null, 'com.acme.crm')).toBeUndefined();
});
});
/**
* objectstack#7231 / objectui#4074 — which app hosts an app-INDEPENDENT page
* (the Approvals Inbox, `sys_inbox_message`, `sys_activity`). The producers that
* consume this are pinned end-to-end in `HomePage.inboxLinksTarget.test.tsx` and
* `InboxPopover.viewAllTarget.test.tsx`; these cases pin the resolution itself.
*/
/**
* objectstack-ai/objectstack#26183 — one app, one address. A route that reached
* its app through the name alias is rewritten onto the package id, so the
* page's own links and the sidebar's agree.
*/
describe('appAddressSegment', () => {
const CLM = { name: 'clm', _packageId: 'app.objectstack.hotclm' };
it('answers the package id when it resolves back to the same app', () => {
expect(appAddressSegment([CLM], CLM)).toBe('app.objectstack.hotclm');
});
it('answers the name for a package-less (runtime/DB) app', () => {
const app = { name: 'scratch' };
expect(appAddressSegment([app], app)).toBe('scratch');
});
it('answers the name when the package id opens a DIFFERENT app of the same package', () => {
const crm = { name: 'crm', _packageId: 'com.acme.suite' };
const ops = { name: 'ops', _packageId: 'com.acme.suite' };
expect(appAddressSegment([crm, ops], crm)).toBe('com.acme.suite');
expect(appAddressSegment([crm, ops], ops)).toBe('ops');
});
it('answers undefined for no app', () => {
expect(appAddressSegment([CLM], undefined)).toBeUndefined();
});
});
describe('canonicalAppPathname', () => {
const CLM = { name: 'clm', _packageId: 'app.objectstack.hotclm' };
it('moves a name-alias route onto the package id, the rest of the path kept', () => {
expect(canonicalAppPathname([CLM], 'clm', '/apps/clm/clm_contract/view/my_contracts')).toBe(
'/apps/app.objectstack.hotclm/clm_contract/view/my_contracts',
);
expect(canonicalAppPathname([CLM], 'clm', '/apps/clm')).toBe('/apps/app.objectstack.hotclm');
expect(canonicalAppPathname([CLM], 'clm', '/apps/clm/')).toBe('/apps/app.objectstack.hotclm/');
});
it('leaves the package-id route alone — the rewrite can never loop', () => {
const once = canonicalAppPathname([CLM], 'clm', '/apps/clm/clm_contract');
expect(once).toBe('/apps/app.objectstack.hotclm/clm_contract');
expect(canonicalAppPathname([CLM], 'app.objectstack.hotclm', once!)).toBeNull();
});
it('leaves an app whose name IS its package id alone', () => {
const app = { name: 'crm', _packageId: 'crm' };
expect(canonicalAppPathname([app], 'crm', '/apps/crm/account')).toBeNull();
});
it('leaves a package-less app on its name, and the later app of a shared package on its name', () => {
expect(canonicalAppPathname([{ name: 'scratch' }], 'scratch', '/apps/scratch/x')).toBeNull();
const crm = { name: 'crm', _packageId: 'com.acme.suite' };
const ops = { name: 'ops', _packageId: 'com.acme.suite' };
expect(canonicalAppPathname([crm, ops], 'ops', '/apps/ops/ticket')).toBeNull();
expect(canonicalAppPathname([crm, ops], 'crm', '/apps/crm/account')).toBe('/apps/com.acme.suite/account');
});
it('answers null for a segment no app answers to, or a pathname outside /apps', () => {
expect(canonicalAppPathname([CLM], 'nope', '/apps/nope/x')).toBeNull();
expect(canonicalAppPathname([CLM], undefined, '/apps')).toBeNull();
expect(canonicalAppPathname([CLM], 'clm', '/home')).toBeNull();
expect(canonicalAppPathname(undefined, 'clm', '/apps/clm')).toBeNull();
});
});
describe('filterActiveApps', () => {
it('keeps apps that declare neither flag (the common case)', () => {
expect(filterActiveApps([{ name: 'crm' }])).toEqual([{ name: 'crm' }]);
});
it('drops deactivated and hidden apps', () => {
const apps = [
{ name: 'crm' },
{ name: 'old', active: false },
{ name: 'account', hidden: true },
];
expect(filterActiveApps(apps).map((a) => a.name)).toEqual(['crm']);
});
it('⛔ keeps an UNPUBLISHED app — `_unpublished` is a server-side gate, not a launcher filter', () => {
// objectstack#6955 (#4829 A1). `_unpublished` is the ADR-0045 publish gate
// and the REST metadata gate already withholds those apps from non-builders,
// so one that reaches this predicate belongs to a builder entitled to open
// it. Adding an `_unpublished !== true` clause would hide a builder's own
// in-progress app from the builder and break every link the module builds
// into it. `hidden` is the opposite: no other enforcement point exists, so
// the clause above is its whole implementation.
const apps = [
{ name: 'crm' },
{ name: 'draft_app', _unpublished: true },
{ name: 'account', hidden: true, _unpublished: true },
];
expect(filterActiveApps(apps).map((a) => a.name)).toEqual(['crm', 'draft_app']);
});
it('is idempotent, so a caller that already filtered can pass its list through', () => {
const apps = [{ name: 'crm' }, { name: 'old', active: false }];
expect(filterActiveApps(filterActiveApps(apps))).toEqual(filterActiveApps(apps));
});
it('returns an empty list for nullish input', () => {
expect(filterActiveApps(null)).toEqual([]);
expect(filterActiveApps(undefined)).toEqual([]);
});
});
describe('resolveHostAppSegment', () => {
const setup = { name: 'setup' };
const crm = { name: 'crm', _packageId: 'com.acme.crm' };
const hr = { name: 'hr' };
it('1. prefers the app the user is in / last had open', () => {
expect(resolveHostAppSegment([setup, crm], 'com.acme.crm')).toBe('com.acme.crm');
});
it('1. addresses that app by its package segment, whichever spelling was remembered', () => {
// `matchAppBySegment` accepts the name as a legacy alias; the segment we
// emit is always the canonical one, so the link cannot disagree with the
// app tiles about how the same app is spelled.
expect(resolveHostAppSegment([crm], 'crm')).toBe('com.acme.crm');
});
it('1. re-checks the preferred name against the LIVE list and does not resurrect a dead app', () => {
// `currentAppName` is plain React state — it outlives the app it names.
expect(resolveHostAppSegment([hr], 'crm')).toBe('hr');
expect(resolveHostAppSegment([hr, { name: 'crm', active: false }], 'crm')).toBe('hr');
expect(resolveHostAppSegment([hr, { name: 'crm', hidden: true }], 'crm')).toBe('hr');
});
it('2. falls back to the first ACTIVE app when nothing names the current one', () => {
expect(resolveHostAppSegment([{ name: 'old', active: false }, hr], undefined)).toBe('hr');
});
it('3. keeps an unchecked preferred segment when the list names no app at all', () => {
// An empty list is "not loaded yet" as often as "no apps" — a caller
// rendering inside `/apps/crm/…` must not be demoted to `setup`.
expect(resolveHostAppSegment([], 'crm')).toBe('crm');
expect(resolveHostAppSegment(undefined, 'crm')).toBe('crm');
});
it('4. falls back to setup only when nothing addressable is left', () => {
expect(resolveHostAppSegment([], undefined)).toBe('setup');
expect(resolveHostAppSegment(null, null)).toBe('setup');
// A degenerate app carrying neither `_packageId` nor `name`: present, so
// step 3 does not apply, but nothing to build a URL from either.
expect(resolveHostAppSegment([{ label: 'nameless' }], 'crm')).toBe('setup');
});
it('CONTROL: a user whose current app IS setup resolves to setup', () => {
// The fallback order's tail is not "never setup" — it is "an app this user
// can actually open", and for an admin sitting in Setup that is `setup`.
expect(resolveHostAppSegment([setup, crm], 'setup')).toBe('setup');
});
});
/**
* objectstack#35505 (ruling option A, item 1) — the app an approval opened
* with no source app stays in, after the object's own app (which the request
* page asks): the current app, then the last used app, then the first app.
*/
describe('resolveApprovalsHostSegment (objectstack#35505)', () => {
const setup = { name: 'setup', _packageId: 'com.objectstack.setup' };
const crm = { name: 'crm', _packageId: 'com.acme.crm' };
const hr = { name: 'hr' };
const ops = { name: 'ops' };
it('tier 2 — the current app wins over the last used app', () => {
expect(resolveApprovalsHostSegment([setup, hr, crm], 'crm', 'hr')).toBe('com.acme.crm');
});
it('tier 3 — with no current app, the last used app', () => {
expect(resolveApprovalsHostSegment([setup, hr, crm], undefined, 'crm')).toBe('com.acme.crm');
});
it('tier 3 — a current app the user can no longer open falls through to the last used app', () => {
expect(resolveApprovalsHostSegment([setup, hr, { ...crm, active: false }, ops], 'crm', 'ops')).toBe('ops');
});
it('tier 4 — neither current nor last answers: the first app, not Setup ahead of it', () => {
expect(resolveApprovalsHostSegment([hr, setup, crm], undefined, undefined)).toBe('hr');
expect(resolveApprovalsHostSegment([hr, setup], 'gone', 'also_gone')).toBe('hr');
expect(resolveApprovalsHostSegment([hr, { ...crm, hidden: true }], undefined, 'crm')).toBe('hr');
});
it('Setup stays the answer when it is the current or the last used app (ruling item 3)', () => {
expect(resolveApprovalsHostSegment([hr, setup], 'setup', 'hr')).toBe('com.objectstack.setup');
expect(resolveApprovalsHostSegment([hr, setup], undefined, 'setup')).toBe('com.objectstack.setup');
});
it('an unloaded list keeps the hint, current first', () => {
expect(resolveApprovalsHostSegment([], 'crm', 'hr')).toBe('crm');
expect(resolveApprovalsHostSegment(undefined, undefined, 'hr')).toBe('hr');
});
});
describe('isApprovalsInboxLink (objectstack#35505)', () => {
it('names the inbox and its request deep link, as the approvals service writes them', () => {
expect(isApprovalsInboxLink('/system/approvals')).toBe(true);
expect(isApprovalsInboxLink('/system/approvals?request=req_1')).toBe(true);
expect(isApprovalsInboxLink('system/approvals?request=req_1')).toBe(true);
});
it('CONTROL: other links, and a segment that only starts the same way, are not it', () => {
expect(isApprovalsInboxLink('/invoice/inv_1')).toBe(false);
expect(isApprovalsInboxLink('/system/approvals_archive')).toBe(false);
expect(isApprovalsInboxLink('/apps/crm/system/approvals')).toBe(false);
expect(isApprovalsInboxLink(undefined)).toBe(false);
});
});
/**
* ADR-0080 — app → Studio reverse bridge.
*/
describe('appStudioDesignPath', () => {
const crm = { name: 'crm', _packageId: 'com.acme.crm' };
it("resolves an admin viewing a packaged app to its package's 概览 Overview (objectstack#38392)", () => {
expect(appStudioDesignPath(crm, true)).toBe('/studio/com.acme.crm/overview');
});
it('URL-encodes the package id', () => {
expect(appStudioDesignPath({ _packageId: 'com.acme/crm' }, true)).toBe(
'/studio/com.acme%2Fcrm/overview',
);
});
it('returns null for non-admins', () => {
expect(appStudioDesignPath(crm, false)).toBeNull();
});
it('returns null for apps with no owning package (runtime/DB apps)', () => {
expect(appStudioDesignPath({ name: 'crm' }, true)).toBeNull();
expect(appStudioDesignPath(undefined, true)).toBeNull();
expect(appStudioDesignPath(null, true)).toBeNull();
});
it('returns null for the DB-authored sys_metadata pseudo-package', () => {
expect(appStudioDesignPath({ name: 'crm', _packageId: 'sys_metadata' }, true)).toBeNull();
});
});
/**
* App → Studio interface deep-link: the item's page in the All-metadata area
* (objectstack#36502 retired the Interfaces pillar it opened before).
*/
describe('appStudioSurfacePath', () => {
const crm = { name: 'crm', _packageId: 'com.acme.crm' };
it('deep-links to the interface\'s item page in the All-metadata area (objectstack#36502)', () => {
expect(appStudioSurfacePath(crm, true, { type: 'dashboard', name: 'executive_dashboard' })).toBe(
'/studio/com.acme.crm/metadata/dashboard/executive_dashboard',
);
});
it('URL-encodes the package id and the surface name', () => {
expect(
appStudioSurfacePath({ _packageId: 'com.acme/crm' }, true, { type: 'dashboard', name: 'sales dash' }),
).toBe('/studio/com.acme%2Fcrm/metadata/dashboard/sales%20dash');
});
it('returns null for non-admins', () => {
expect(appStudioSurfacePath(crm, false, { type: 'dashboard', name: 'd' })).toBeNull();
});
it('returns null when the surface identity is incomplete', () => {
expect(appStudioSurfacePath(crm, true, { type: 'dashboard', name: '' })).toBeNull();
expect(appStudioSurfacePath(crm, true, { type: '', name: 'd' })).toBeNull();
expect(appStudioSurfacePath(crm, true, null)).toBeNull();
});
it('returns null for apps with no owning package or the sys_metadata pseudo-package', () => {
expect(appStudioSurfacePath({ name: 'crm' }, true, { type: 'dashboard', name: 'd' })).toBeNull();
expect(appStudioSurfacePath({ _packageId: 'sys_metadata' }, true, { type: 'dashboard', name: 'd' })).toBeNull();
});
});
/**
* App → Studio object deep-link (Data pillar).
*/
describe('appStudioObjectPath', () => {
const crm = { name: 'crm', _packageId: 'com.acme.crm' };
// objectstack#36904 — the object designer on its metadata address.
it("deep-links to the object's designer", () => {
expect(appStudioObjectPath(crm, true, 'showcase_task')).toBe('/studio/com.acme.crm/metadata/object/showcase_task');
});
it('URL-encodes the package id and the object name', () => {
expect(appStudioObjectPath({ _packageId: 'com.acme/crm' }, true, 'my object')).toBe(
'/studio/com.acme%2Fcrm/metadata/object/my%20object',
);
});
it('returns null for non-admins', () => {
expect(appStudioObjectPath(crm, false, 'account')).toBeNull();
});
it('returns null when the object name is missing', () => {
expect(appStudioObjectPath(crm, true, undefined)).toBeNull();
expect(appStudioObjectPath(crm, true, '')).toBeNull();
});
it('returns null for apps with no owning package or the sys_metadata pseudo-package', () => {
expect(appStudioObjectPath({ name: 'crm' }, true, 'account')).toBeNull();
expect(appStudioObjectPath({ _packageId: 'sys_metadata' }, true, 'account')).toBeNull();
});
});
/**
* App → Studio route bridge — maps a running-app route to its Studio target:
* an interface surface (dashboard / page / report) deep-links to its
* All-metadata item page (objectstack#36502); an object record page deep-links that object in the Data
* pillar; everything else opens the package's Data tab.
*/
describe('appStudioRoutePath', () => {
const crm = { name: 'crm', _packageId: 'com.acme.crm' };
it('deep-links a dashboard route to its All-metadata item page', () => {
expect(appStudioRoutePath(crm, true, { type: 'dashboard', name: 'executive_dashboard' })).toBe(
'/studio/com.acme.crm/metadata/dashboard/executive_dashboard',
);
});
it('deep-links a page route to its All-metadata item page (the fix — was the Data tab)', () => {
expect(appStudioRoutePath(crm, true, { type: 'page', name: 'showcase_crm_workbench' })).toBe(
'/studio/com.acme.crm/metadata/page/showcase_crm_workbench',
);
});
it('deep-links a report route to its All-metadata item page', () => {
expect(appStudioRoutePath(crm, true, { type: 'report', name: 'pipeline_report' })).toBe(
'/studio/com.acme.crm/metadata/report/pipeline_report',
);
});
it('deep-links an object route (routeType is the object name) to its Data-pillar surface', () => {
// The fix: an object records page now opens THAT object, not the generic Data tab.
expect(appStudioRoutePath(crm, true, { type: 'showcase_task', name: undefined })).toBe(
'/studio/com.acme.crm/metadata/object/showcase_task',
);
// A record-detail route (name='record') still keys off the object route type.
expect(appStudioRoutePath(crm, true, { type: 'account', name: 'record' })).toBe(
'/studio/com.acme.crm/metadata/object/account',
);
});
it("falls back to the package's 概览 Overview for the app root and the system area (objectstack#38392)", () => {
// No route type at all (bare /apps/:pkg) → 概览.
expect(appStudioRoutePath(crm, true, { type: undefined, name: undefined })).toBe('/studio/com.acme.crm/overview');
// The system settings area is not an object.
expect(appStudioRoutePath(crm, true, { type: 'system', name: 'members' })).toBe('/studio/com.acme.crm/overview');
});
it("falls back to the package's 概览 Overview for an interface list route (no surface name)", () => {
// e.g. /apps/:pkg/page with no specific page selected.
expect(appStudioRoutePath(crm, true, { type: 'page', name: undefined })).toBe('/studio/com.acme.crm/overview');
});
it('returns null for non-admins (bridge hidden), for both surface and Data targets', () => {
expect(appStudioRoutePath(crm, false, { type: 'page', name: 'showcase_crm_workbench' })).toBeNull();
expect(appStudioRoutePath(crm, false, { type: 'account', name: undefined })).toBeNull();
});
it('returns null when the app has no owning package (runtime/DB apps)', () => {
expect(appStudioRoutePath({ name: 'crm' }, true, { type: 'page', name: 'p' })).toBeNull();
expect(appStudioRoutePath({ _packageId: 'sys_metadata' }, true, { type: 'page', name: 'p' })).toBeNull();
});
});