Repository navigation
Expand file tree
/
Copy pathsys-approval-request-page.test.ts
More file actions
321 lines (290 loc) · 16.8 KB
/
Copy pathsys-approval-request-page.test.ts
File metadata and controls
321 lines (290 loc) · 16.8 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
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
/**
* `sys_approval_request`'s record-detail page — the full page this plugin
* serves through its manifest `pages` (maintainer ruling 乙 on objectui#12045,
* `6079807016`: the page is metadata in plugin-approvals; objectui registers
* renderers and mounts `RecordDetailView`).
*
* Four questions, each answered against the shipped artifacts and never a
* copy of them:
*
* 1. the plugin's manifest carries the page, so the registry — and the
* metadata API reading it — has it;
* 2. the page body is the one the ruling's build list names (a slotted page
* until the `tabs` slot retired, objectstack#27053; rebuilt as the same
* nodes in a `kind: 'full'` page): a header, one
* `record:approval_decision` node, `record:details`, `sys_approval_action`
* as the related list, no discussion thread, and a highlights strip that
* leaves `record_id` to the details grid (the seat's choice on the ui
* seat's design input `6081889955`) and names nothing by a machine name;
* 3. the page passes what `os validate` judges a page by — the parse, the
* component-type vocabulary, the props rows and the build rules — with a
* control for each half that can go red;
* 4. its label is translated in every shipped locale, `en` byte-equal to
* the page literal, and served as the translation (not the fallback).
*/
import { describe, it, expect } from 'vitest';
import { ObjectStackDefinitionSchema, normalizeStackInput } from '@objectstack/spec';
import { PageSchema } from '@objectstack/spec/ui';
import {
COMPONENT_PROPS_UNKNOWN_KEY,
COMPONENT_TYPE_UNKNOWN,
runAuthoringRules,
splitBySeverity,
validateComponentProps,
validateComponentTypes,
} from '@objectstack/lint';
import { ApprovalsServicePlugin } from './approvals-plugin.js';
import { SysApprovalRequestDetailPage } from './sys-approval-request.page.js';
import { SysApprovalRequest } from './sys-approval-request.object.js';
import { SysApprovalAction } from './sys-approval-action.object.js';
import { ApprovalsTranslations } from './translations/index.js';
import { approvalsPageTranslations } from './translations/pages.js';
type AnyRec = Record<string, any>;
const PAGE = SysApprovalRequestDetailPage as AnyRec;
const COMPONENTS = (PAGE.regions?.[0]?.components ?? []) as AnyRec[];
const nodeOf = (type: string): AnyRec | undefined => COMPONENTS.find((c) => c.type === type);
const HIGHLIGHTS = (nodeOf('record:highlights') ?? {}) as AnyRec;
const TAB_ITEMS = (nodeOf('page:tabs')?.properties?.items ?? []) as AnyRec[];
/** Where the decision panel sits in the region: after the header, before the highlights. */
const DECISION_AT = COMPONENTS.findIndex((c) => c.type === 'record:approval_decision');
/** The plugin's one manifest, as `init` registers it. */
async function registeredManifest(): Promise<AnyRec> {
const registered: AnyRec[] = [];
const ctx: any = {
getService: (name: string) =>
name === 'manifest' ? { register: (m: AnyRec) => registered.push(m) } : undefined,
logger: { info: () => {}, warn: () => {} },
};
await new ApprovalsServicePlugin({ disableService: true }).init(ctx);
expect(registered).toHaveLength(1);
return registered[0];
}
/** Every component node under the page, tab children included. */
function nodesOf(value: unknown, out: AnyRec[] = []): AnyRec[] {
if (Array.isArray(value)) {
for (const v of value) nodesOf(v, out);
} else if (value && typeof value === 'object') {
const rec = value as AnyRec;
if (typeof rec.type === 'string') out.push(rec);
for (const v of Object.values(rec)) nodesOf(v, out);
}
return out;
}
const MANIFEST = {
id: 'com.objectstack.test.approval-request-page',
name: 'approval_request_page',
version: '1.0.0',
type: 'app',
} as const;
/** The page in a stack beside the two objects it binds, parsed as `os validate` parses it. */
function judgedStack(page: AnyRec) {
const normalized = normalizeStackInput({
manifest: MANIFEST,
objects: [SysApprovalRequest, SysApprovalAction],
pages: [page],
}) as AnyRec;
const result = ObjectStackDefinitionSchema.safeParse(normalized);
if (!result.success) {
throw new Error(
'stack is not spec-valid: '
+ result.error.issues.map((i) => `${i.path.join('.') || '(root)'}: ${i.message}`).join('; '),
);
}
return { normalized, parsed: result.data as AnyRec };
}
/** The build rules' findings located on the page (the objects' own are not this file's question). */
function pageBuildFindings(page: AnyRec) {
const { normalized, parsed } = judgedStack(page);
return runAuthoringRules('build', { normalized, parsed }).filter((f) => f.path.startsWith('pages'));
}
/** The page with its decision node replaced. */
const withDecisionNode = (node: AnyRec): AnyRec => ({
...PAGE,
regions: [{ ...PAGE.regions[0], components: COMPONENTS.map((c, i) => (i === DECISION_AT ? node : c)) }],
});
describe('sys_approval_request detail page — served through the manifest', () => {
it('the plugin manifest carries the page in `pages`', async () => {
const manifest = await registeredManifest();
expect(manifest.pages).toEqual([SysApprovalRequestDetailPage]);
});
it('is the default full record page of sys_approval_request', () => {
expect(PAGE).toMatchObject({
name: 'sys_approval_request_detail',
type: 'record',
object: 'sys_approval_request',
kind: 'full',
isDefault: true,
});
const parsed = PageSchema.safeParse(PAGE);
expect(parsed.success, JSON.stringify(parsed.error?.issues ?? [])).toBe(true);
});
});
describe('sys_approval_request detail page — the page body', () => {
it('authors exactly the header, the decision panel, the highlights and the tabs, in the slotted order', () => {
// The nodes the slotted page rendered, in the synthesizer's order: the
// header it fell through to, its `actions` slot, its `highlights` slot and
// its tab strip, whose first tab is the details body. Its `discussion`
// slot was empty, so there is no discussion node. The header reads the
// object's placed header actions live, as the synthesized one did: a bare
// `page:header` drew none, so an action another package places on the
// object at `record_header` was dropped (#29951).
expect(COMPONENTS.map((c) => c.type)).toEqual(['page:header', 'record:approval_decision', 'record:highlights', 'page:tabs']);
expect(nodeOf('page:header')).toEqual({ type: 'page:header', properties: { placedActions: true } });
});
it('holds ONE record:approval_decision node, with no properties (its props row is empty and strict)', () => {
const decision = nodesOf(COMPONENTS).filter((n) => n.type === 'record:approval_decision');
expect(decision).toHaveLength(1);
expect(COMPONENTS[DECISION_AT]).toEqual({ type: 'record:approval_decision' });
});
it('highlights the object\'s highlightFields minus record_id, which the object itself keeps', () => {
// The seat's choice on the ui seat's design input: the page's strip drops
// `record_id` so the details grid keeps it (that grid is where the console
// draws the target-record card of the `record_id` / `object_name` pointer
// pair), and the object's `highlightFields` keeps it.
const declared = SysApprovalRequest.highlightFields ?? [];
expect(declared).toContain('record_id');
expect(HIGHLIGHTS.type).toBe('record:highlights');
expect(HIGHLIGHTS.properties.fields).toEqual(declared.filter((f: string) => f !== 'record_id'));
expect((SysApprovalRequest.fields as AnyRec).record_id?.referenceVia).toBe('object_name');
});
it('names the flow by its label, process_label, in the strip and in the object\'s list alike', () => {
// `process_name` is the machine source (`flow:NAME`); `process_label` is the
// flow's label, served under that name by the approvals get. The object's
// list moves with the strip: the Details tab's bare `record:details` node
// draws the object's `highlightFields` minus the strip, so a strip-only
// change would put `process_name` in that tab.
const strip = HIGHLIGHTS.properties.fields as string[];
const declared = SysApprovalRequest.highlightFields ?? [];
expect(strip[0]).toBe('process_label');
expect(declared[0]).toBe('process_label');
expect({ strip: strip.includes('process_name'), declared: declared.includes('process_name') })
.toEqual({ strip: false, declared: false });
expect(declared.filter((f: string) => !strip.includes(f))).toEqual(['record_id']);
});
it('names the step by its label, current_step_label, in the strip and in the object\'s list alike', () => {
// `current_step` is the Approval node's machine id (`approve_step`);
// `current_step_label` is the step's label, a declared field the approvals
// get serves under that name (`approval-service.test.ts` pins the get). The
// object's list moves with the strip for the reason the flow chip's does.
const strip = HIGHLIGHTS.properties.fields as string[];
const declared = SysApprovalRequest.highlightFields ?? [];
const fields = SysApprovalRequest.fields as AnyRec;
expect({ strip: strip.includes('current_step_label'), declared: declared.includes('current_step_label') })
.toEqual({ strip: true, declared: true });
expect({ strip: strip.includes('current_step'), declared: declared.includes('current_step') })
.toEqual({ strip: false, declared: false });
expect(fields.current_step_label).toMatchObject({ type: 'text', label: 'Approval Step' });
// Control: the machine id stays a declared field. It is dropped from the
// two lists, not from the object.
expect(fields.current_step).toMatchObject({ type: 'text' });
});
it('draws no Object chip: object_name, the target\'s API name, is in neither list, and the Details tab is the pointer pair\'s card', () => {
// `object_name` holds the target object's API name (`showcase_announcement`)
// and the object declares no field holding that object's label. The page
// names the target object on the card the console draws for the
// `record_id` / `object_name` pair in the Details tab, which heads the
// record with its object's label. The object's list moves with the strip
// for the reason the flow chip's does: dropped from the strip alone,
// `object_name` would be drawn as a row in that tab.
const strip = HIGHLIGHTS.properties.fields as string[];
const declared = SysApprovalRequest.highlightFields ?? [];
const fields = SysApprovalRequest.fields as AnyRec;
expect({ strip: strip.includes('object_name'), declared: declared.includes('object_name') })
.toEqual({ strip: false, declared: false });
// The Details tab's bare `record:details` node draws the object's list
// minus the strip: the id half of the pair, whose type half names the
// target object.
expect(TAB_ITEMS[0].children).toEqual([{ type: 'record:details' }]);
expect(declared.filter((f: string) => !strip.includes(f))).toEqual(['record_id']);
expect(fields.record_id?.referenceVia).toBe('object_name');
// Control: the type half stays a declared, required field. It is dropped
// from the two lists, not from the object.
expect(fields.object_name).toMatchObject({ type: 'text', required: true });
});
it('tabs: Details is record:details, Timeline is sys_approval_action as a related list on request_id', () => {
expect(TAB_ITEMS.map((t) => t.label?.en)).toEqual(['Details', 'Timeline']);
expect(TAB_ITEMS[0].children).toEqual([{ type: 'record:details' }]);
const [timeline] = TAB_ITEMS[1].children as AnyRec[];
expect(timeline.type).toBe('record:related_list');
expect(timeline.properties).toMatchObject({ objectName: 'sys_approval_action', relationshipField: 'request_id' });
// The relationship really points back at this object.
expect((SysApprovalAction.fields as AnyRec).request_id).toMatchObject({ type: 'lookup', reference: 'sys_approval_request' });
});
it('names each Timeline step by its label, step_label, never by the node\'s machine id, step_name', () => {
// Both are stored on every `sys_approval_action` row: `step_name` is the
// Approval node's id (`dual_signoff`), `step_label` the step's label the
// service copies from the request (`actionRow`). The existence check below
// cannot tell them apart, since both are declared fields, so the choice is
// pinned here, the way the strip's `current_step_label` is.
const [timeline] = TAB_ITEMS[1].children as AnyRec[];
const columns = timeline.properties.columns as string[];
const fields = SysApprovalAction.fields as AnyRec;
expect({ label: columns.includes('step_label'), machine: columns.includes('step_name') })
.toEqual({ label: true, machine: false });
expect(fields.step_label).toMatchObject({ type: 'text', label: 'Approval Step' });
// Control: the machine id stays a declared field. It is dropped from the
// Timeline, not from the object.
expect(fields.step_name).toMatchObject({ type: 'text' });
});
it('every field the page names exists on its object', () => {
const requestFields = Object.keys(SysApprovalRequest.fields);
const actionFields = Object.keys(SysApprovalAction.fields);
const [timeline] = TAB_ITEMS[1].children as AnyRec[];
const missing = [
...(HIGHLIGHTS.properties.fields as string[]).filter((f) => !requestFields.includes(f)).map((f) => `request.${f}`),
...(timeline.properties.columns as string[]).filter((f) => !actionFields.includes(f)).map((f) => `action.${f}`),
...(timeline.properties.sort as AnyRec[]).map((s) => s.field).filter((f) => !actionFields.includes(f)).map((f) => `action.${f}`),
];
expect(missing).toEqual([]);
});
it('has no discussion thread anywhere — the reply is the declared approval_comment action', () => {
expect(nodesOf(PAGE).map((n) => n.type).filter((t) => t === 'record:discussion' || t === 'record:chatter')).toEqual([]);
const actions = (SysApprovalRequest.actions ?? []) as AnyRec[];
expect(actions.find((a) => a.name === 'approval_comment')?.locations).toEqual(['record_section']);
});
});
describe('sys_approval_request detail page — what `os validate` judges a page by', () => {
it('the component-type vocabulary knows every node, record:approval_decision included', () => {
expect(validateComponentTypes({ pages: [PAGE] })).toEqual([]);
});
it('control: a misspelled decision-panel type is refused by the same call', () => {
const findings = validateComponentTypes({ pages: [withDecisionNode({ type: 'record:approval_decison' })] });
expect(findings.map((f) => [f.rule, f.path])).toEqual([[COMPONENT_TYPE_UNKNOWN, `pages[0].regions[0].components[${DECISION_AT}].type`]]);
});
it('every node\'s props are inside its declared props row', () => {
expect(validateComponentProps({ pages: [PAGE] })).toEqual([]);
});
it('control: a property on the decision node is refused by the same call', () => {
const findings = validateComponentProps({ pages: [withDecisionNode({ type: 'record:approval_decision', properties: { showProgress: true } })] });
expect(findings.map((f) => f.rule)).toEqual([COMPONENT_PROPS_UNKNOWN_KEY]);
});
it('the build rules raise no error on the page, in a stack beside the two objects it binds', () => {
const { errors } = splitBySeverity(pageBuildFindings(PAGE));
expect(errors, JSON.stringify(errors, null, 2)).toEqual([]);
});
it('control: the build rules see the page — the misspelled type is an error there too', () => {
const { errors } = splitBySeverity(pageBuildFindings(withDecisionNode({ type: 'record:approval_decison' })));
expect(errors.map((f) => f.rule)).toContain(COMPONENT_TYPE_UNKNOWN);
});
});
describe('sys_approval_request detail page — its label in the translation bundles', () => {
const NAME = 'sys_approval_request_detail';
it('the `en` entry is byte-equal to the page literal', () => {
// `translatePage` applies the bundle in `en` too, so a drifted `en` entry
// would override the page's own label rather than fall back to it.
expect(approvalsPageTranslations.en[NAME]?.label).toBe(PAGE.label);
});
it('every served locale carries the label, and a translated locale serves its translation', () => {
const locales = Object.keys(ApprovalsTranslations).sort();
expect(locales).toEqual(['ar', 'en', 'es-ES', 'fr', 'ja-JP', 'pt-BR', 'zh-CN', 'zh-Hant']);
for (const locale of locales) {
const served = (ApprovalsTranslations as AnyRec)[locale]?.pages?.[NAME]?.label;
const authored = (approvalsPageTranslations as AnyRec)[locale]?.[NAME]?.label;
expect({ locale, served }).toEqual({ locale, served: authored });
// Served AS the translation: the recorded source digest is current, so
// the staleness fallback did not put the English source in its place.
if (locale !== 'en') expect({ locale, english: served === PAGE.label }).toEqual({ locale, english: false });
}
});
});