-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathvalidate-nav-target-refs.test.ts
More file actions
139 lines (122 loc) · 5.61 KB
/
Copy pathvalidate-nav-target-refs.test.ts
File metadata and controls
139 lines (122 loc) · 5.61 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
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
/**
* Tests for the non-object nav-target rule (ADR-0072).
*
* Two of these are the load-bearing ones:
*
* 1. The **empty-collection** case. That is the whole reason this rule exists:
* `defineStack`'s own check is gated on `pageNames.size > 0`, so a stack with
* no `pages` has its page-nav validation switched off. If someone "optimises"
* this rule by skipping stacks with no pages, that test goes red.
* 2. The **deliberate NON-members** (`component`, `action`). Each was verified,
* not assumed — `component` renders a named "Component not registered"
* diagnostic rather than failing silently, and `action` is already owned by
* `validate-action-name-refs`. Flagging either would be a false prescription
* or a duplicate report, and these tests are where that attempt fails first.
*/
import { describe, expect, it } from 'vitest';
import { validateNavTargetRefs, NAV_TARGET_UNRESOLVED } from './validate-nav-target-refs.js';
const app = (items: unknown[]) => ({ apps: [{ name: 'ops', navigation: items }] });
describe('validateNavTargetRefs — the gap defineStack leaves', () => {
it('flags a page target when the stack declares NO pages (the size>0 hole)', () => {
const [f] = validateNavTargetRefs(app([{ id: 'n1', type: 'page', pageName: 'missing_page' }]));
expect(f.rule).toBe(NAV_TARGET_UNRESOLVED);
expect(f.severity).toBe('warning');
expect(f.path).toBe('apps[0].navigation[0].pageName');
expect(f.where).toBe('app "ops" · nav "n1"');
// The message must say WHY nothing else caught it, or the author has no
// way to know this rule is the only thing speaking.
expect(f.message).toContain('NO pages at all');
expect(f.message).toContain('size > 0');
});
it('flags a page target when pages exist but the name is wrong', () => {
const findings = validateNavTargetRefs({
...app([{ id: 'n1', type: 'page', pageName: 'typo' }]),
pages: [{ name: 'real_page' }],
});
expect(findings).toHaveLength(1);
expect(findings[0].message).not.toContain('NO pages at all');
});
it('is silent when the target resolves', () => {
expect(validateNavTargetRefs({
...app([{ id: 'n1', type: 'page', pageName: 'real_page' }]),
pages: [{ name: 'real_page' }],
})).toEqual([]);
});
it.each([
['report', 'reportName', 'reports'],
['dashboard', 'dashboardName', 'dashboards'],
])('covers %s targets too', (type, prop, collection) => {
expect(validateNavTargetRefs(app([{ id: 'x', type, [prop]: 'nope' }]))).toHaveLength(1);
expect(validateNavTargetRefs({
...app([{ id: 'x', type, [prop]: 'ok' }]),
[collection]: [{ name: 'ok' }],
})).toEqual([]);
});
it('walks nested children — an `object` item carries them too, not just a group', () => {
const findings = validateNavTargetRefs(app([
{ id: 'grp', type: 'object', objectName: 'task', children: [
{ id: 'deep', type: 'page', pageName: 'missing' },
] },
]));
expect(findings).toHaveLength(1);
expect(findings[0].path).toBe('apps[0].navigation[0].children[0].pageName');
});
it('walks the `areas[]` container, not just `navigation`', () => {
const findings = validateNavTargetRefs({
apps: [{ name: 'ops', areas: [{ name: 'a', items: [{ id: 'n', type: 'page', pageName: 'missing' }] }] }],
});
expect(findings).toHaveLength(1);
expect(findings[0].path).toBe('apps[0].areas[0].items[0].pageName');
});
it('skips interpolated targets — they resolve at render time (ADR-0072 D1)', () => {
expect(validateNavTargetRefs(app([
{ id: 'n', type: 'page', pageName: '${ctx.page}' },
{ id: 'm', type: 'page', pageName: '{dynamic}' },
]))).toEqual([]);
});
});
describe('the deliberate NON-members — each verified, not assumed', () => {
it('does NOT flag `component` — an unregistered ref is reported loudly at runtime', () => {
// ComponentNavView renders "Component not registered … Ensure the plugin
// that provides this surface is installed and has called
// registerAppComponent()". The registry exists so plugin surfaces MAY be
// absent; flagging this would break valid plugin nav and duplicate a
// better runtime message.
expect(validateNavTargetRefs(app([
{ id: 'n', type: 'component', componentRef: 'nobody:nothing' },
]))).toEqual([]);
});
it('does NOT flag `action` — validate-action-name-refs already walks app nav', () => {
expect(validateNavTargetRefs(app([
{ id: 'n', type: 'action', actionDef: { actionName: 'ghost_action' } },
]))).toEqual([]);
});
it('does NOT flag `url` — external by definition', () => {
expect(validateNavTargetRefs(app([
{ id: 'n', type: 'url', url: 'https://example.com' },
]))).toEqual([]);
});
});
describe('robustness', () => {
it('never throws on junk or partial stacks', () => {
for (const junk of [
undefined, null, 42, 'x', [], {},
{ apps: 'nope' }, { apps: [null, 7] },
{ apps: [{ name: 'a', navigation: 'nope' }] },
{ apps: [{ navigation: [null, 3, { type: 'page' }] }] },
{ apps: [{ name: 'a', areas: 'nope' }] },
app([{ type: 'page' }]), // no pageName at all
]) {
expect(() => validateNavTargetRefs(junk)).not.toThrow();
}
});
it('emits nothing for a stack with no apps', () => {
expect(validateNavTargetRefs({ pages: [{ name: 'p' }] })).toEqual([]);
});
it('every finding carries a usable hint', () => {
for (const f of validateNavTargetRefs(app([{ id: 'n', type: 'page', pageName: 'x' }]))) {
expect(f.hint.length).toBeGreaterThan(20);
}
});
});