@transitrix/diagrams 1.5.0 → 1.7.6
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/dist/capability-map/CapabilityCardNode.d.ts +19 -0
- package/dist/capability-map/CapabilityCardNode.js +66 -0
- package/dist/capability-map/CapabilityMapView.d.ts +59 -0
- package/dist/capability-map/CapabilityMapView.js +204 -0
- package/dist/capability-map/CapabilityRootNode.d.ts +12 -0
- package/dist/capability-map/CapabilityRootNode.js +23 -0
- package/dist/capability-map/__tests__/CapabilityMapView.test.d.ts +1 -0
- package/dist/capability-map/__tests__/CapabilityMapView.test.js +217 -0
- package/dist/capability-map/__tests__/address.test.d.ts +1 -0
- package/dist/capability-map/__tests__/address.test.js +49 -0
- package/dist/capability-map/__tests__/dsm-layout.test.d.ts +1 -0
- package/dist/capability-map/__tests__/dsm-layout.test.js +46 -0
- package/dist/capability-map/__tests__/dsm-mutations.test.d.ts +1 -0
- package/dist/capability-map/__tests__/dsm-mutations.test.js +125 -0
- package/dist/capability-map/__tests__/dsm-validate.test.d.ts +1 -0
- package/dist/capability-map/__tests__/dsm-validate.test.js +56 -0
- package/dist/capability-map/address.d.ts +12 -0
- package/dist/capability-map/address.js +48 -0
- package/dist/capability-map/dsm-layout.d.ts +9 -0
- package/dist/capability-map/dsm-layout.js +125 -0
- package/dist/capability-map/dsm-mutations.d.ts +28 -0
- package/dist/capability-map/dsm-mutations.js +196 -0
- package/dist/capability-map/dsm-schema.d.ts +71 -0
- package/dist/capability-map/dsm-schema.js +14 -0
- package/dist/capability-map/dsm-theme.d.ts +20 -0
- package/dist/capability-map/dsm-theme.js +36 -0
- package/dist/capability-map/dsm-validate.d.ts +2 -0
- package/dist/capability-map/dsm-validate.js +93 -0
- package/dist/capability-map/index.d.ts +9 -0
- package/dist/capability-map/index.js +6 -0
- package/dist/codex/__tests__/example.test.d.ts +1 -0
- package/dist/codex/__tests__/example.test.js +33 -0
- package/dist/codex/__tests__/validate.test.d.ts +1 -0
- package/dist/codex/__tests__/validate.test.js +68 -0
- package/dist/codex/index.d.ts +4 -0
- package/dist/codex/index.js +2 -0
- package/dist/codex/types.d.ts +7 -0
- package/dist/codex/types.js +8 -0
- package/dist/codex/validate.d.ts +11 -0
- package/dist/codex/validate.js +103 -0
- package/dist/compliance/__tests__/canon-catalog.test.d.ts +1 -0
- package/dist/compliance/__tests__/canon-catalog.test.js +60 -0
- package/dist/compliance/__tests__/trace.test.d.ts +1 -0
- package/dist/compliance/__tests__/trace.test.js +144 -0
- package/dist/compliance/__tests__/view-resolution.test.d.ts +1 -0
- package/dist/compliance/__tests__/view-resolution.test.js +59 -0
- package/dist/compliance/canon-catalog.d.ts +19 -0
- package/dist/compliance/canon-catalog.js +59 -0
- package/dist/compliance/classify.js +7 -1
- package/dist/compliance/coverage-metric.d.ts +12 -0
- package/dist/compliance/coverage-metric.js +35 -0
- package/dist/compliance/impact.d.ts +7 -1
- package/dist/compliance/impact.js +53 -0
- package/dist/compliance/index.d.ts +8 -5
- package/dist/compliance/index.js +4 -2
- package/dist/compliance/reverse-index.js +4 -1
- package/dist/compliance/trace.d.ts +26 -0
- package/dist/compliance/trace.js +89 -0
- package/dist/compliance/types.d.ts +94 -1
- package/dist/constraint/__tests__/example.test.d.ts +1 -0
- package/dist/constraint/__tests__/example.test.js +14 -0
- package/dist/constraint/__tests__/validate.test.d.ts +1 -0
- package/dist/constraint/__tests__/validate.test.js +58 -0
- package/dist/constraint/index.d.ts +4 -0
- package/dist/constraint/index.js +2 -0
- package/dist/constraint/types.d.ts +4 -0
- package/dist/constraint/types.js +2 -0
- package/dist/constraint/validate.d.ts +7 -0
- package/dist/constraint/validate.js +115 -0
- package/dist/fgca/__tests__/parse-canonical.test.js +31 -0
- package/dist/fgca/parse-canonical.d.ts +1 -1
- package/dist/fgca/parse-canonical.js +18 -4
- package/dist/goals/GoalNode.d.ts +19 -0
- package/dist/goals/GoalNode.js +96 -0
- package/dist/goals/GoalTreeView.d.ts +59 -0
- package/dist/goals/GoalTreeView.js +245 -0
- package/dist/goals/__tests__/GoalTreeView.test.d.ts +1 -0
- package/dist/goals/__tests__/GoalTreeView.test.js +337 -0
- package/dist/goals/__tests__/mutations.test.js +39 -0
- package/dist/goals/__tests__/parse-canonical.test.js +2 -0
- package/dist/goals/index.d.ts +3 -0
- package/dist/goals/index.js +1 -0
- package/dist/goals/layout.js +2 -1
- package/dist/goals/mutations.js +6 -6
- package/dist/goals/parse-canonical.d.ts +5 -0
- package/dist/goals/parse-canonical.js +5 -0
- package/dist/goals/theme.d.ts +22 -0
- package/dist/goals/theme.js +32 -0
- package/dist/goals/types.d.ts +2 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/repo-validate/types.js +2 -3
- package/dist/webview/__tests__/render-goals.test.js +17 -3
- package/dist/webview/render-goals.js +2 -1
- package/package.json +4 -1
- package/src/capability-map/CapabilityCardNode.tsx +146 -0
- package/src/capability-map/CapabilityMapView.tsx +331 -0
- package/src/capability-map/CapabilityRootNode.tsx +38 -0
- package/src/capability-map/__tests__/CapabilityMapView.test.tsx +232 -0
- package/src/capability-map/__tests__/address.test.ts +59 -0
- package/src/capability-map/__tests__/dsm-layout.test.ts +52 -0
- package/src/capability-map/__tests__/dsm-mutations.test.ts +141 -0
- package/src/capability-map/__tests__/dsm-validate.test.ts +65 -0
- package/src/capability-map/address.ts +48 -0
- package/src/capability-map/dsm-layout.ts +142 -0
- package/src/capability-map/dsm-mutations.ts +208 -0
- package/src/capability-map/dsm-schema.ts +80 -0
- package/src/capability-map/dsm-theme.ts +53 -0
- package/src/capability-map/dsm-validate.ts +103 -0
- package/src/capability-map/index.ts +35 -0
- package/src/codex/__tests__/example.test.ts +40 -0
- package/src/codex/__tests__/validate.test.ts +84 -0
- package/src/codex/index.ts +4 -0
- package/src/codex/types.ts +13 -0
- package/src/codex/validate.ts +125 -0
- package/src/compliance/__tests__/canon-catalog.test.ts +68 -0
- package/src/compliance/__tests__/trace.test.ts +157 -0
- package/src/compliance/__tests__/view-resolution.test.ts +80 -0
- package/src/compliance/canon-catalog.ts +76 -0
- package/src/compliance/classify.ts +7 -1
- package/src/compliance/coverage-metric.ts +50 -0
- package/src/compliance/impact.ts +67 -1
- package/src/compliance/index.ts +16 -1
- package/src/compliance/reverse-index.ts +3 -1
- package/src/compliance/trace.ts +118 -0
- package/src/compliance/types.ts +101 -1
- package/src/constraint/__tests__/example.test.ts +19 -0
- package/src/constraint/__tests__/validate.test.ts +68 -0
- package/src/constraint/index.ts +4 -0
- package/src/constraint/types.ts +5 -0
- package/src/constraint/validate.ts +131 -0
- package/src/fgca/__tests__/parse-canonical.test.ts +34 -0
- package/src/fgca/parse-canonical.ts +17 -4
- package/src/goals/GoalNode.tsx +219 -0
- package/src/goals/GoalTreeView.tsx +384 -0
- package/src/goals/__tests__/GoalTreeView.test.tsx +361 -0
- package/src/goals/__tests__/mutations.test.ts +42 -0
- package/src/goals/__tests__/parse-canonical.test.ts +2 -0
- package/src/goals/index.ts +4 -0
- package/src/goals/layout.ts +2 -1
- package/src/goals/mutations.ts +6 -6
- package/src/goals/parse-canonical.ts +6 -0
- package/src/goals/theme.ts +54 -0
- package/src/goals/types.ts +2 -0
- package/src/index.ts +29 -1
- package/src/repo-validate/types.ts +2 -3
- package/src/webview/__tests__/render-goals.test.ts +17 -3
- package/src/webview/render-goals.ts +2 -1
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { render, screen, cleanup, waitFor } from '@testing-library/react';
|
|
5
|
+
import { GoalTreeView, computeDragOutcome } from '../GoalTreeView.js';
|
|
6
|
+
import type { GoalTree } from '../types.js';
|
|
7
|
+
import type { GoalTreeChange } from '../GoalTreeView.js';
|
|
8
|
+
|
|
9
|
+
// jsdom has no ResizeObserver / layout engine. reactflow keeps a node's DOM
|
|
10
|
+
// wrapper `visibility: hidden` and excludes it from drag/intersection logic
|
|
11
|
+
// until it has been "measured" via ResizeObserver — so the mock must
|
|
12
|
+
// actually invoke its callback (with the mocked getBoundingClientRect below)
|
|
13
|
+
// for nodes to become interactive, not just satisfy the constructor call.
|
|
14
|
+
class MockResizeObserver {
|
|
15
|
+
#callback: ResizeObserverCallback;
|
|
16
|
+
constructor(callback: ResizeObserverCallback) {
|
|
17
|
+
this.#callback = callback;
|
|
18
|
+
}
|
|
19
|
+
observe(target: Element) {
|
|
20
|
+
queueMicrotask(() => {
|
|
21
|
+
const rect = target.getBoundingClientRect();
|
|
22
|
+
this.#callback(
|
|
23
|
+
[{ target, contentRect: rect } as ResizeObserverEntry],
|
|
24
|
+
this as unknown as ResizeObserver,
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
unobserve() {}
|
|
29
|
+
disconnect() {}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// jsdom also has no DOMMatrixReadOnly, which reactflow's dimension-tracking
|
|
33
|
+
// uses to read the translateX/Y out of a node's computed transform. Only
|
|
34
|
+
// translate() (no scale/rotate) ever appears in this component's own CSS, so
|
|
35
|
+
// a minimal shim covering that one case is enough.
|
|
36
|
+
class MockDOMMatrixReadOnly {
|
|
37
|
+
m41 = 0;
|
|
38
|
+
m42 = 0;
|
|
39
|
+
constructor(transform?: string) {
|
|
40
|
+
if (!transform || transform === 'none') return;
|
|
41
|
+
const t = /translate\((-?[\d.]+)px,\s*(-?[\d.]+)px\)/.exec(transform);
|
|
42
|
+
if (t) {
|
|
43
|
+
this.m41 = Number(t[1]);
|
|
44
|
+
this.m42 = Number(t[2]);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const m = /matrix\(([^)]+)\)/.exec(transform);
|
|
48
|
+
if (m) {
|
|
49
|
+
const parts = m[1].split(',').map((p) => Number(p.trim()));
|
|
50
|
+
this.m41 = parts[4] ?? 0;
|
|
51
|
+
this.m42 = parts[5] ?? 0;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function makeTree(): GoalTree {
|
|
57
|
+
return {
|
|
58
|
+
goal_types: [
|
|
59
|
+
{ name: 'Strategy', level: 0 },
|
|
60
|
+
{ name: 'Business Goal', level: 1 },
|
|
61
|
+
],
|
|
62
|
+
goals: [
|
|
63
|
+
{ id: 1, name: 'Triple revenue', type: 'Strategy', level: 0, parent_id: 0 },
|
|
64
|
+
{ id: 2, name: 'Launch in EU', type: 'Business Goal', level: 1, parent_id: 1 },
|
|
65
|
+
{
|
|
66
|
+
id: 3,
|
|
67
|
+
name: 'Cut churn',
|
|
68
|
+
type: 'Business Goal',
|
|
69
|
+
level: 1,
|
|
70
|
+
parent_id: 1,
|
|
71
|
+
factors: [
|
|
72
|
+
{ id: 10, name: 'Support backlog', impact_type: 'risk' },
|
|
73
|
+
{ id: 11, name: 'New pricing', impact_type: 'opportunity' },
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
beforeEach(() => {
|
|
81
|
+
(global as unknown as { ResizeObserver: unknown }).ResizeObserver = MockResizeObserver;
|
|
82
|
+
(window as unknown as { DOMMatrixReadOnly: unknown }).DOMMatrixReadOnly = MockDOMMatrixReadOnly;
|
|
83
|
+
vi.spyOn(Element.prototype, 'getBoundingClientRect').mockImplementation(function (this: Element) {
|
|
84
|
+
// Individual goal cards report their real 250x80 footprint (matters for
|
|
85
|
+
// reactflow's own drag/measurement bookkeeping); the flow container and
|
|
86
|
+
// everything else gets a generously large rect so viewport fitting has
|
|
87
|
+
// room to work with.
|
|
88
|
+
const isNode = this.classList?.contains('react-flow__node');
|
|
89
|
+
const width = isNode ? 250 : 1000;
|
|
90
|
+
const height = isNode ? 80 : 800;
|
|
91
|
+
return {
|
|
92
|
+
width, height, top: 0, left: 0, right: width, bottom: height, x: 0, y: 0,
|
|
93
|
+
toJSON() { return this; },
|
|
94
|
+
} as DOMRect;
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
afterEach(() => {
|
|
99
|
+
cleanup();
|
|
100
|
+
vi.restoreAllMocks();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
describe('GoalTreeView', () => {
|
|
104
|
+
it('renders without crashing and shows every canvas goal', async () => {
|
|
105
|
+
render(<GoalTreeView tree={makeTree()} />);
|
|
106
|
+
await waitFor(() => {
|
|
107
|
+
expect(screen.getByText('Triple revenue')).toBeTruthy();
|
|
108
|
+
expect(screen.getByText('Launch in EU')).toBeTruthy();
|
|
109
|
+
expect(screen.getByText('Cut churn')).toBeTruthy();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('renders factor indicators from goal.factors', async () => {
|
|
114
|
+
render(<GoalTreeView tree={makeTree()} />);
|
|
115
|
+
await waitFor(() => {
|
|
116
|
+
expect(screen.getByText('Triple revenue')).toBeTruthy();
|
|
117
|
+
});
|
|
118
|
+
// One up-caret (opportunity) and one down-caret (risk) on "Cut churn".
|
|
119
|
+
expect(screen.getByLabelText('1 positive factor')).toBeTruthy();
|
|
120
|
+
expect(screen.getByLabelText('1 negative factor')).toBeTruthy();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('puts a goal with a broken parent_id in the backlog, not on canvas', async () => {
|
|
124
|
+
const tree: GoalTree = {
|
|
125
|
+
goal_types: [
|
|
126
|
+
{ name: 'Strategy', level: 0 },
|
|
127
|
+
{ name: 'Business Goal', level: 1 },
|
|
128
|
+
],
|
|
129
|
+
goals: [
|
|
130
|
+
{ id: 1, name: 'Root goal', type: 'Strategy', level: 0, parent_id: 0 },
|
|
131
|
+
// level 1 + a parent_id that resolves to nothing — not a root by
|
|
132
|
+
// either "Roots: level === 0 || parent_id === 0" clause, and
|
|
133
|
+
// unreachable from goal 1 — must land in the backlog.
|
|
134
|
+
{ id: 2, name: 'Orphaned goal', type: 'Business Goal', level: 1, parent_id: 999 },
|
|
135
|
+
],
|
|
136
|
+
};
|
|
137
|
+
render(<GoalTreeView tree={tree} showBacklog />);
|
|
138
|
+
await waitFor(() => {
|
|
139
|
+
expect(screen.getByText('Root goal')).toBeTruthy();
|
|
140
|
+
});
|
|
141
|
+
expect(screen.getByText('Orphaned goal')).toBeTruthy();
|
|
142
|
+
expect(screen.queryByText('Backlog')).toBeTruthy();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('does not render add/delete affordances when readOnly', async () => {
|
|
146
|
+
render(<GoalTreeView tree={makeTree()} readOnly />);
|
|
147
|
+
await waitFor(() => {
|
|
148
|
+
expect(screen.getByText('Triple revenue')).toBeTruthy();
|
|
149
|
+
});
|
|
150
|
+
expect(screen.queryByLabelText('Add child goal')).toBeNull();
|
|
151
|
+
expect(screen.queryByLabelText('Delete goal')).toBeNull();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('fires onChange with kind "addChild" when the add-child button is clicked', async () => {
|
|
155
|
+
const onChange = vi.fn<(e: GoalTreeChange) => void>();
|
|
156
|
+
render(<GoalTreeView tree={makeTree()} onChange={onChange} />);
|
|
157
|
+
await waitFor(() => {
|
|
158
|
+
expect(screen.getByText('Triple revenue')).toBeTruthy();
|
|
159
|
+
});
|
|
160
|
+
// Target the root (id 1, level 0) specifically — makeTree()'s goal_types
|
|
161
|
+
// only go up to level 1, so clicking "add child" on an existing level-1
|
|
162
|
+
// goal would be correctly refused (would exceed max level) and never
|
|
163
|
+
// fire onChange at all.
|
|
164
|
+
const rootNode = document.querySelector('.react-flow__node[data-id="1"]');
|
|
165
|
+
const addButton = rootNode!.querySelector('[aria-label="Add child goal"]')!;
|
|
166
|
+
addButton.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
|
167
|
+
|
|
168
|
+
await waitFor(() => expect(onChange).toHaveBeenCalledTimes(1));
|
|
169
|
+
const event = onChange.mock.calls[0][0];
|
|
170
|
+
expect(event.kind).toBe('addChild');
|
|
171
|
+
if (event.kind === 'addChild') {
|
|
172
|
+
expect(event.result.goals.length).toBe(4);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('fires onChange with kind "delete" when the delete button is clicked', async () => {
|
|
177
|
+
const onChange = vi.fn<(e: GoalTreeChange) => void>();
|
|
178
|
+
render(<GoalTreeView tree={makeTree()} onChange={onChange} />);
|
|
179
|
+
await waitFor(() => {
|
|
180
|
+
expect(screen.getByText('Cut churn')).toBeTruthy();
|
|
181
|
+
});
|
|
182
|
+
const deleteButtons = screen.getAllByLabelText('Delete goal');
|
|
183
|
+
deleteButtons[deleteButtons.length - 1].dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
|
184
|
+
|
|
185
|
+
await waitFor(() => expect(onChange).toHaveBeenCalledTimes(1));
|
|
186
|
+
const event = onChange.mock.calls[0][0];
|
|
187
|
+
expect(event.kind).toBe('delete');
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('fires onChange with kind "restoreFromBacklog" when a backlog card is dropped onto a canvas card', async () => {
|
|
191
|
+
const tree: GoalTree = {
|
|
192
|
+
goal_types: [
|
|
193
|
+
{ name: 'Strategy', level: 0 },
|
|
194
|
+
{ name: 'Business Goal', level: 1 },
|
|
195
|
+
],
|
|
196
|
+
goals: [
|
|
197
|
+
{ id: 1, name: 'Root goal', type: 'Strategy', level: 0, parent_id: 0 },
|
|
198
|
+
{ id: 2, name: 'Orphaned goal', type: 'Business Goal', level: 1, parent_id: 999 },
|
|
199
|
+
],
|
|
200
|
+
};
|
|
201
|
+
const onChange = vi.fn<(e: GoalTreeChange) => void>();
|
|
202
|
+
render(<GoalTreeView tree={tree} onChange={onChange} showBacklog />);
|
|
203
|
+
await waitFor(() => {
|
|
204
|
+
expect(screen.getByText('Orphaned goal')).toBeTruthy();
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// jsdom has no native DataTransfer; stub the minimal setData/getData
|
|
208
|
+
// surface this component's native (non-reactflow) HTML5 drag path uses
|
|
209
|
+
// and attach it directly to the dispatched events.
|
|
210
|
+
const store = new Map<string, string>();
|
|
211
|
+
const dataTransfer = {
|
|
212
|
+
setData: (k: string, v: string) => store.set(k, v),
|
|
213
|
+
getData: (k: string) => store.get(k) ?? '',
|
|
214
|
+
effectAllowed: 'move',
|
|
215
|
+
};
|
|
216
|
+
function fireDnd(el: Element, type: string, coords: { clientX: number; clientY: number }) {
|
|
217
|
+
const event = new Event(type, { bubbles: true, cancelable: true });
|
|
218
|
+
Object.defineProperty(event, 'dataTransfer', { value: dataTransfer });
|
|
219
|
+
Object.assign(event, coords);
|
|
220
|
+
el.dispatchEvent(event);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const backlogItem = screen.getByText('Orphaned goal').closest('div[draggable]')!;
|
|
224
|
+
const rootNode = document.querySelector('.react-flow__node[data-id="1"]')!;
|
|
225
|
+
// jsdom doesn't implement elementFromPoint at all (not just "returns null").
|
|
226
|
+
document.elementFromPoint = vi.fn().mockReturnValue(rootNode);
|
|
227
|
+
|
|
228
|
+
fireDnd(backlogItem, 'dragstart', { clientX: 0, clientY: 0 });
|
|
229
|
+
fireDnd(rootNode, 'drop', { clientX: 10, clientY: 10 });
|
|
230
|
+
|
|
231
|
+
await waitFor(() => expect(onChange).toHaveBeenCalledTimes(1));
|
|
232
|
+
const event = onChange.mock.calls[0][0];
|
|
233
|
+
expect(event.kind).toBe('restoreFromBacklog');
|
|
234
|
+
if (event.kind === 'restoreFromBacklog') {
|
|
235
|
+
expect(event.id).toBe(2);
|
|
236
|
+
expect(event.newParentId).toBe(1);
|
|
237
|
+
expect(event.result.goals.find((g) => g.id === 2)?.parent_id).toBe(1);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// Dragging a card is choreographed by reactflow's own pointer/DOM-measurement
|
|
242
|
+
// machinery (ResizeObserver-gated node "readiness", d3-drag pointer capture,
|
|
243
|
+
// viewport transform math) — faithfully simulating that in jsdom means
|
|
244
|
+
// re-implementing reactflow's internals rather than testing this component.
|
|
245
|
+
// computeDragOutcome() is the pure decision GoalTreeView's onNodeDragStop
|
|
246
|
+
// calls once reactflow reports a drag: given where a card was dropped, which
|
|
247
|
+
// mutation fires and what onChange payload it produces. Testing it directly
|
|
248
|
+
// covers the actual reparent/moveToBacklog logic without that DOM coupling.
|
|
249
|
+
describe('computeDragOutcome (reparent / moveToBacklog decision logic)', () => {
|
|
250
|
+
const tree: GoalTree = {
|
|
251
|
+
goal_types: [
|
|
252
|
+
{ name: 'Strategy', level: 0 },
|
|
253
|
+
{ name: 'Business Goal', level: 1 },
|
|
254
|
+
],
|
|
255
|
+
goals: [
|
|
256
|
+
{ id: 1, name: 'Goal A', type: 'Strategy', level: 0, parent_id: 0 },
|
|
257
|
+
{ id: 2, name: 'Goal C', type: 'Strategy', level: 0, parent_id: 0 },
|
|
258
|
+
{ id: 3, name: 'Goal B', type: 'Business Goal', level: 1, parent_id: 1 },
|
|
259
|
+
],
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
it('fires a "reparent" change when dropped onto another card', () => {
|
|
263
|
+
const change = computeDragOutcome(tree, 3, { kind: 'node', id: 2 });
|
|
264
|
+
expect(change?.kind).toBe('reparent');
|
|
265
|
+
if (change?.kind === 'reparent') {
|
|
266
|
+
expect(change.sourceId).toBe(3);
|
|
267
|
+
expect(change.targetId).toBe(2);
|
|
268
|
+
expect(change.result.goals.find((g) => g.id === 3)?.parent_id).toBe(2);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it('fires a "moveToBacklog" change when dropped on the backlog zone', () => {
|
|
273
|
+
const change = computeDragOutcome(tree, 3, { kind: 'backlog' });
|
|
274
|
+
expect(change?.kind).toBe('moveToBacklog');
|
|
275
|
+
if (change?.kind === 'moveToBacklog') {
|
|
276
|
+
expect(change.id).toBe(3);
|
|
277
|
+
expect(change.result.goals.find((g) => g.id === 3)?.parent_id).toBe(0);
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
it('is a no-op when dropped nowhere in particular', () => {
|
|
282
|
+
expect(computeDragOutcome(tree, 3, null)).toBeNull();
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('is a no-op when dropped on itself', () => {
|
|
286
|
+
expect(computeDragOutcome(tree, 3, { kind: 'node', id: 3 })).toBeNull();
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it('is a no-op when the reparent would exceed the schema max level', () => {
|
|
290
|
+
// Goal 3 is already level 1 (max); reparenting it under itself-sibling
|
|
291
|
+
// level-1 goal would push it to level 2.
|
|
292
|
+
const deeper: GoalTree = {
|
|
293
|
+
...tree,
|
|
294
|
+
goals: [...tree.goals, { id: 4, name: 'Goal D', type: 'Business Goal', level: 1, parent_id: 1 }],
|
|
295
|
+
};
|
|
296
|
+
expect(computeDragOutcome(deeper, 3, { kind: 'node', id: 4 })).toBeNull();
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it('fires onFactorClick with the clicked factor when a popover item is clicked', async () => {
|
|
301
|
+
const onFactorClick = vi.fn();
|
|
302
|
+
render(<GoalTreeView tree={makeTree()} onFactorClick={onFactorClick} />);
|
|
303
|
+
await waitFor(() => {
|
|
304
|
+
expect(screen.getByText('Cut churn')).toBeTruthy();
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
// Open the negative-factor panel on "Cut churn" (id=3, has risk factor "Support backlog")
|
|
308
|
+
const negativeBadge = screen.getByLabelText('1 negative factor');
|
|
309
|
+
negativeBadge.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
|
310
|
+
|
|
311
|
+
// The popover item for the risk factor should now be in the DOM
|
|
312
|
+
const factorItem = await waitFor(() => screen.getByText('Support backlog'));
|
|
313
|
+
factorItem.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
|
314
|
+
|
|
315
|
+
await waitFor(() => expect(onFactorClick).toHaveBeenCalledTimes(1));
|
|
316
|
+
expect(onFactorClick.mock.calls[0][0]).toMatchObject({ id: 10, name: 'Support backlog', impact_type: 'risk' });
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
it('backlog panel is collapsible — toggle hides and restores content', async () => {
|
|
320
|
+
const tree: GoalTree = {
|
|
321
|
+
goal_types: [
|
|
322
|
+
{ name: 'Strategy', level: 0 },
|
|
323
|
+
{ name: 'Business Goal', level: 1 },
|
|
324
|
+
],
|
|
325
|
+
goals: [
|
|
326
|
+
{ id: 1, name: 'Root goal', type: 'Strategy', level: 0, parent_id: 0 },
|
|
327
|
+
{ id: 2, name: 'Orphaned goal', type: 'Business Goal', level: 1, parent_id: 999 },
|
|
328
|
+
],
|
|
329
|
+
};
|
|
330
|
+
render(<GoalTreeView tree={tree} showBacklog />);
|
|
331
|
+
await waitFor(() => {
|
|
332
|
+
expect(screen.getByText('Backlog')).toBeTruthy();
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
// Collapse
|
|
336
|
+
screen.getByLabelText('Collapse backlog').dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
|
337
|
+
await waitFor(() => {
|
|
338
|
+
expect(screen.queryByText('Backlog')).toBeNull();
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
// Expand again
|
|
342
|
+
screen.getByLabelText('Expand backlog').dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
|
343
|
+
await waitFor(() => {
|
|
344
|
+
expect(screen.getByText('Backlog')).toBeTruthy();
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it('fires onEditRequest on double-click', async () => {
|
|
349
|
+
const onEditRequest = vi.fn();
|
|
350
|
+
render(<GoalTreeView tree={makeTree()} onEditRequest={onEditRequest} />);
|
|
351
|
+
await waitFor(() => {
|
|
352
|
+
expect(screen.getByText('Triple revenue')).toBeTruthy();
|
|
353
|
+
});
|
|
354
|
+
const nodeEl = document.querySelector('.react-flow__node[data-id="1"]');
|
|
355
|
+
expect(nodeEl).toBeTruthy();
|
|
356
|
+
nodeEl!.dispatchEvent(new MouseEvent('dblclick', { bubbles: true }));
|
|
357
|
+
|
|
358
|
+
await waitFor(() => expect(onEditRequest).toHaveBeenCalledTimes(1));
|
|
359
|
+
expect(onEditRequest.mock.calls[0][0]).toMatchObject({ id: 1, name: 'Triple revenue' });
|
|
360
|
+
});
|
|
361
|
+
});
|
|
@@ -109,3 +109,45 @@ describe('restoreFromBacklog', () => {
|
|
|
109
109
|
expect(r.result!.goals.find(g => g.id === 3)!.parent_id).toBe(1);
|
|
110
110
|
});
|
|
111
111
|
});
|
|
112
|
+
|
|
113
|
+
describe('reparent — descendant type relabeling and level cap', () => {
|
|
114
|
+
const DEEP: GoalTree = {
|
|
115
|
+
goal_types: [
|
|
116
|
+
{ name: 'Strategy', level: 0 },
|
|
117
|
+
{ name: 'Business Goal', level: 1 },
|
|
118
|
+
{ name: 'Project', level: 2 },
|
|
119
|
+
{ name: 'Task', level: 3 },
|
|
120
|
+
],
|
|
121
|
+
goals: [
|
|
122
|
+
{ id: 1, name: 'Root', type: 'Strategy', level: 0, parent_id: 0 },
|
|
123
|
+
{ id: 2, name: 'BG1', type: 'Business Goal', level: 1, parent_id: 1 },
|
|
124
|
+
{ id: 3, name: 'Proj1', type: 'Project', level: 2, parent_id: 2 },
|
|
125
|
+
{ id: 4, name: 'Task1', type: 'Task', level: 3, parent_id: 3 },
|
|
126
|
+
],
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
it('relabels descendant types via getTypeForLevel when reparenting shifts levels', () => {
|
|
130
|
+
// Move Proj1 (id=3, level=2) directly under Root (id=1, level=0); delta = -1
|
|
131
|
+
// Task1 (child of Proj1, level=3): new level = 2, type should be 'Project'
|
|
132
|
+
const r = reparent(DEEP, 3, 1);
|
|
133
|
+
expect(r.ok).toBe(true);
|
|
134
|
+
const proj = r.result!.goals.find(g => g.id === 3)!;
|
|
135
|
+
const task = r.result!.goals.find(g => g.id === 4)!;
|
|
136
|
+
expect(proj.level).toBe(1);
|
|
137
|
+
expect(proj.type).toBe('Business Goal');
|
|
138
|
+
expect(task.level).toBe(2);
|
|
139
|
+
expect(task.type).toBe('Project');
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('caps descendant level at maxLevel and refuses when that violates GOALS-012', () => {
|
|
143
|
+
// Move Root (id=1, level=0) under Root2 (id=5, level=0); delta = +1
|
|
144
|
+
// BG1: 1→2, Proj1: 2→3 (maxLevel), Task1: 3→4, capped at 3
|
|
145
|
+
// Task1 (capped level=3) under Proj1 (level=3) violates GOALS-012 → refused
|
|
146
|
+
const tree: GoalTree = {
|
|
147
|
+
...DEEP,
|
|
148
|
+
goals: [...DEEP.goals, { id: 5, name: 'Root2', type: 'Strategy', level: 0, parent_id: 0 }],
|
|
149
|
+
};
|
|
150
|
+
const r = reparent(tree, 1, 5);
|
|
151
|
+
expect(r.ok).toBe(false);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
@@ -122,8 +122,10 @@ describe('parseCanonicalGoals', () => {
|
|
|
122
122
|
it('maps canonical IDs to internal numeric ids; parent_id is the parent\'s mapped id', () => {
|
|
123
123
|
const r = parseCanonicalGoals(VALID);
|
|
124
124
|
expect(r.parsed?.goals[0].id).toBe(1);
|
|
125
|
+
expect(r.parsed?.goals[0].canonical_id).toBe('GOAL-1');
|
|
125
126
|
expect(r.parsed?.goals[0].parent_id).toBe(0);
|
|
126
127
|
expect(r.parsed?.goals[1].id).toBe(2);
|
|
128
|
+
expect(r.parsed?.goals[1].canonical_id).toBe('GOAL-2');
|
|
127
129
|
expect(r.parsed?.goals[1].parent_id).toBe(1);
|
|
128
130
|
});
|
|
129
131
|
});
|
package/src/goals/index.ts
CHANGED
|
@@ -18,3 +18,7 @@ export { parseCanonicalGoals } from './parse-canonical.js';
|
|
|
18
18
|
export type { CanonicalGoalsResult } from './parse-canonical.js';
|
|
19
19
|
export { layoutGoalTree, selectScopedGoals } from './layout.js';
|
|
20
20
|
export { reparent, addChild, deleteWithDescendants, moveToBacklog, restoreFromBacklog } from './mutations.js';
|
|
21
|
+
|
|
22
|
+
export { GoalTreeView } from './GoalTreeView.js';
|
|
23
|
+
export type { GoalTreeViewProps, GoalTreeChange } from './GoalTreeView.js';
|
|
24
|
+
export type { ThemeTokens } from './theme.js';
|
package/src/goals/layout.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Goal, GoalTree, LayoutOptions, GoalTreeLayout, LaidOutNode, LaidOutEdge } from './types.js';
|
|
2
2
|
import type { Scope } from '../scope.js';
|
|
3
|
+
import { displayGoalId } from './parse-canonical.js';
|
|
3
4
|
|
|
4
5
|
const DEFAULT_NODE_WIDTH = 250;
|
|
5
6
|
const DEFAULT_NODE_HEIGHT = 80;
|
|
@@ -23,7 +24,7 @@ export function selectScopedGoals(goals: Goal[], scope: Scope): Goal[] {
|
|
|
23
24
|
if (!children.has(g.parent_id)) children.set(g.parent_id, []);
|
|
24
25
|
children.get(g.parent_id)!.push(g.id);
|
|
25
26
|
}
|
|
26
|
-
const root = goals.find(g =>
|
|
27
|
+
const root = goals.find(g => displayGoalId(g) === scope.rootGoalId);
|
|
27
28
|
if (!root) return [];
|
|
28
29
|
const keep = new Set<number>();
|
|
29
30
|
const stack = [root.id];
|
package/src/goals/mutations.ts
CHANGED
|
@@ -22,12 +22,12 @@ function getTypeForLevel(tree: GoalTree, level: number): string {
|
|
|
22
22
|
return gt?.name ?? '';
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
function updateDescendantLevels(
|
|
26
|
-
for (const g of goals) {
|
|
25
|
+
function updateDescendantLevels(clone: GoalTree, id: number, levelDelta: number, maxLevel: number): void {
|
|
26
|
+
for (const g of clone.goals) {
|
|
27
27
|
if (g.parent_id === id) {
|
|
28
|
-
g.level
|
|
29
|
-
g.type =
|
|
30
|
-
updateDescendantLevels(
|
|
28
|
+
g.level = Math.min(g.level + levelDelta, maxLevel);
|
|
29
|
+
g.type = getTypeForLevel(clone, g.level);
|
|
30
|
+
updateDescendantLevels(clone, g.id, levelDelta, maxLevel);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -70,7 +70,7 @@ export function reparent(tree: GoalTree, sourceId: number, targetId: number): Mu
|
|
|
70
70
|
source.parent_id = targetId;
|
|
71
71
|
source.level = newLevel;
|
|
72
72
|
source.type = getTypeForLevel(clone, newLevel);
|
|
73
|
-
if (levelDelta !== 0) updateDescendantLevels(clone
|
|
73
|
+
if (levelDelta !== 0) updateDescendantLevels(clone, sourceId, levelDelta, maxLevel);
|
|
74
74
|
|
|
75
75
|
const v = validateGoalTree(clone);
|
|
76
76
|
if (!v.valid) return refusalError(v.errors[0]?.message ?? 'Validation failed after reparent');
|
|
@@ -36,6 +36,11 @@ export interface CanonicalGoalsResult extends ValidationResult {
|
|
|
36
36
|
const GOAL_ID_RE = /^GOAL(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
|
|
37
37
|
const GOALS_DOC_ID_RE = /^GOALS(-[A-Z0-9][A-Z0-9_]*)*-\d+$/;
|
|
38
38
|
|
|
39
|
+
/** Display id for previews — canonical `GOAL-…` when present, else internal numeric id. */
|
|
40
|
+
export function displayGoalId(goal: { id: number; canonical_id?: string }): string {
|
|
41
|
+
return goal.canonical_id ?? String(goal.id);
|
|
42
|
+
}
|
|
43
|
+
|
|
39
44
|
function isNonEmptyString(v: unknown): v is string {
|
|
40
45
|
return typeof v === 'string' && v.trim().length > 0;
|
|
41
46
|
}
|
|
@@ -267,6 +272,7 @@ export function parseCanonicalGoals(input: unknown): CanonicalGoalsResult {
|
|
|
267
272
|
isNonEmptyString(parent) && idToInternal.has(parent) ? idToInternal.get(parent)! : 0;
|
|
268
273
|
return {
|
|
269
274
|
id: idToInternal.get(o['id'] as string)!,
|
|
275
|
+
canonical_id: o['id'] as string,
|
|
270
276
|
name: o['name'] as string,
|
|
271
277
|
type: o['type'] as string,
|
|
272
278
|
level: o['level'] as number,
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme tokens for GoalTreeView — replaces DSM's Redux selectors
|
|
3
|
+
* (selectDiagramParams, selectGoalLevelColors) with a plain prop. Hosts
|
|
4
|
+
* that already carry Transitrix's --ts-* CSS custom properties (Studio)
|
|
5
|
+
* can pass those through; hosts with their own theme store (DSM) map
|
|
6
|
+
* their own values onto this shape.
|
|
7
|
+
*/
|
|
8
|
+
export interface ThemeTokens {
|
|
9
|
+
/** Card fill colour per goal level (0..7). Falls back to DEFAULT_GOAL_LEVEL_COLORS for missing levels. */
|
|
10
|
+
goalLevelColors?: Record<number, string>;
|
|
11
|
+
cardBorderColor?: string;
|
|
12
|
+
cardBorderWidth?: number;
|
|
13
|
+
cardTextColor?: string;
|
|
14
|
+
cardMetaColor?: string;
|
|
15
|
+
edgeColor?: string;
|
|
16
|
+
edgeWidth?: number;
|
|
17
|
+
/** Border colour a card takes on while it's a highlighted drop target during drag. */
|
|
18
|
+
dropTargetBorderColor?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const DEFAULT_GOAL_LEVEL_COLORS: Record<number, string> = {
|
|
22
|
+
0: '#e0e7ff',
|
|
23
|
+
1: '#c7d2fe',
|
|
24
|
+
2: '#a5b4fc',
|
|
25
|
+
3: '#93c5fd',
|
|
26
|
+
4: '#bae6fd',
|
|
27
|
+
5: '#bbf7d0',
|
|
28
|
+
6: '#fef08a',
|
|
29
|
+
7: '#fed7aa',
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const DEFAULT_THEME: Required<ThemeTokens> = {
|
|
33
|
+
goalLevelColors: DEFAULT_GOAL_LEVEL_COLORS,
|
|
34
|
+
cardBorderColor: '#94a3b8',
|
|
35
|
+
cardBorderWidth: 1,
|
|
36
|
+
cardTextColor: '#0f172a',
|
|
37
|
+
cardMetaColor: '#64748b',
|
|
38
|
+
edgeColor: '#94a3b8',
|
|
39
|
+
edgeWidth: 1.5,
|
|
40
|
+
dropTargetBorderColor: '#2563eb',
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export function resolveTheme(theme?: ThemeTokens): Required<ThemeTokens> {
|
|
44
|
+
return {
|
|
45
|
+
goalLevelColors: theme?.goalLevelColors ?? DEFAULT_THEME.goalLevelColors,
|
|
46
|
+
cardBorderColor: theme?.cardBorderColor ?? DEFAULT_THEME.cardBorderColor,
|
|
47
|
+
cardBorderWidth: theme?.cardBorderWidth ?? DEFAULT_THEME.cardBorderWidth,
|
|
48
|
+
cardTextColor: theme?.cardTextColor ?? DEFAULT_THEME.cardTextColor,
|
|
49
|
+
cardMetaColor: theme?.cardMetaColor ?? DEFAULT_THEME.cardMetaColor,
|
|
50
|
+
edgeColor: theme?.edgeColor ?? DEFAULT_THEME.edgeColor,
|
|
51
|
+
edgeWidth: theme?.edgeWidth ?? DEFAULT_THEME.edgeWidth,
|
|
52
|
+
dropTargetBorderColor: theme?.dropTargetBorderColor ?? DEFAULT_THEME.dropTargetBorderColor,
|
|
53
|
+
};
|
|
54
|
+
}
|
package/src/goals/types.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -6,7 +6,35 @@ export * from "./geometry";
|
|
|
6
6
|
export * from "./applications/index";
|
|
7
7
|
export * from "./assertion/index";
|
|
8
8
|
export * from "./blocks/index";
|
|
9
|
-
|
|
9
|
+
// capability-map/index.js also exports a set of DSM-migration symbols
|
|
10
|
+
// (Capability, reparent, addChild, LayoutOptions, ThemeTokens, ...) that
|
|
11
|
+
// reuse the goals module's exact generic Layer-A/B naming convention by
|
|
12
|
+
// design (both follow the same extraction-spec template) — the wildcard
|
|
13
|
+
// re-export below would collide with goals' identically-named symbols.
|
|
14
|
+
// Neither spec's acceptance criteria asks for root-barrel access (only
|
|
15
|
+
// `@transitrix/diagrams/goals` / `@transitrix/diagrams/capability-map`
|
|
16
|
+
// subpath imports), so the colliding names are simply left off the root
|
|
17
|
+
// barrel; they're still importable via the capability-map subpath.
|
|
18
|
+
export type {
|
|
19
|
+
CapabilityType,
|
|
20
|
+
CapabilityNode,
|
|
21
|
+
CapabilityMapHeader,
|
|
22
|
+
CapabilityMapFile,
|
|
23
|
+
CapabilityTreeNode,
|
|
24
|
+
CapabilityTreeEdge,
|
|
25
|
+
CapabilityTreeLevelCounts,
|
|
26
|
+
CapabilityTreeLayout,
|
|
27
|
+
RenderCapabilityTreeOptions,
|
|
28
|
+
} from "./capability-map/index";
|
|
29
|
+
export {
|
|
30
|
+
validateCapabilityMap,
|
|
31
|
+
layoutCapabilityTree,
|
|
32
|
+
TREE_NODE_WIDTH,
|
|
33
|
+
TREE_NODE_HEIGHT,
|
|
34
|
+
TREE_RANK_SEP,
|
|
35
|
+
TREE_NODE_SEP,
|
|
36
|
+
renderCapabilityTreeSvg,
|
|
37
|
+
} from "./capability-map/index";
|
|
10
38
|
export * from "./change/index";
|
|
11
39
|
export * from "./compliance/index";
|
|
12
40
|
export * from "./compliance-matrix/index";
|
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
// referential integrity, atomicity, ID uniqueness, policy — the checks that the
|
|
5
5
|
// methodology's Python `.validators/lint.py` owns today. This converges those
|
|
6
6
|
// checks onto the shared TypeScript model so there is a single validation
|
|
7
|
-
// runtime (methodology ADR
|
|
8
|
-
//
|
|
9
|
-
// `docs/decisions/2026-06-11-validation-runtime-convergence.md`).
|
|
7
|
+
// runtime (methodology ADR "Validation Two-Axis Model"; Studio decision
|
|
8
|
+
// "Validation Runtime Convergence").
|
|
10
9
|
//
|
|
11
10
|
// The finding shape is deliberately minimal — `{ scope, id, message }`. The
|
|
12
11
|
// richer `target` / `category` reporting taxonomy is explicitly DEFERRED per the
|
|
@@ -65,8 +65,22 @@ describe('renderGoalsSvg', () => {
|
|
|
65
65
|
expect(svg).toContain('height="0"');
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
it('
|
|
69
|
-
const
|
|
70
|
-
|
|
68
|
+
it('shows canonical goal ids in node labels when present', () => {
|
|
69
|
+
const tree: GoalTree = {
|
|
70
|
+
goal_types: [{ name: 'Strategy', level: 0 }],
|
|
71
|
+
goals: [
|
|
72
|
+
{
|
|
73
|
+
id: 1,
|
|
74
|
+
canonical_id: 'GOAL-REVENUE-1',
|
|
75
|
+
name: 'Triple revenue',
|
|
76
|
+
type: 'Strategy',
|
|
77
|
+
level: 0,
|
|
78
|
+
parent_id: 0,
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
const svg = renderGoalsSvg(tree);
|
|
83
|
+
expect(svg).toContain('GOAL-REVENUE-1');
|
|
84
|
+
expect(svg).not.toMatch(/>\s*1\s*</);
|
|
71
85
|
});
|
|
72
86
|
});
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { layoutGoalTree } from '../goals/layout.js';
|
|
14
14
|
import type { GoalTree, GoalTreeLayout, LaidOutEdge } from '../goals/types.js';
|
|
15
|
+
import { displayGoalId } from '../goals/parse-canonical.js';
|
|
15
16
|
import { horizontalCubicEdgePath, DEFAULT_EDGE_CURVATURE } from '../edge-path.js';
|
|
16
17
|
import { generateSvgEmbedCss, type ThemeId } from '../theme/index.js';
|
|
17
18
|
import { escXml } from './render-util.js';
|
|
@@ -129,7 +130,7 @@ export function renderGoalsLayoutSvg(layout: GoalTreeLayout, options: RenderGoal
|
|
|
129
130
|
const typeY = twoLines ? y + 43 : y + 35;
|
|
130
131
|
const idY = twoLines ? y + 59 : y + 55;
|
|
131
132
|
const typeLabel = n.data.type ?? '';
|
|
132
|
-
const idText =
|
|
133
|
+
const idText = displayGoalId(n.data);
|
|
133
134
|
return `<g>
|
|
134
135
|
<rect class="diagram-node level-${level}" x="${x}" y="${y}" width="${n.width}" height="${n.height}" rx="${ENTITY_NODE_RX}"/>
|
|
135
136
|
<text class="text-primary" x="${x + n.width / 2}" y="${nameY1}" text-anchor="middle" dominant-baseline="central">${escXml(line1)}</text>${twoLines ? `
|