@transitrix/diagrams 1.8.6 → 1.8.8
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/fgca/index.js +10 -10
- package/dist/fgca/layout.js +1 -1
- package/dist/fgca/nodeTypes.js +4 -4
- package/dist/index.js +33 -33
- package/package.json +8 -2
- package/dist/__tests__/edge-path.test.d.ts +0 -1
- package/dist/__tests__/edge-path.test.js +0 -55
- package/dist/__tests__/node-size-presets.test.d.ts +0 -1
- package/dist/__tests__/node-size-presets.test.js +0 -30
- package/dist/__tests__/scope.test.d.ts +0 -1
- package/dist/__tests__/scope.test.js +0 -23
- package/dist/__tests__/yaml-normalize.test.d.ts +0 -1
- package/dist/__tests__/yaml-normalize.test.js +0 -148
- package/dist/activities/__tests__/cpm.test.d.ts +0 -1
- package/dist/activities/__tests__/cpm.test.js +0 -146
- package/dist/activities/__tests__/gantt.test.d.ts +0 -1
- package/dist/activities/__tests__/gantt.test.js +0 -263
- package/dist/activities/__tests__/layout.test.d.ts +0 -1
- package/dist/activities/__tests__/layout.test.js +0 -98
- package/dist/activities/__tests__/validate.test.d.ts +0 -1
- package/dist/activities/__tests__/validate.test.js +0 -397
- package/dist/activity-card/__tests__/example.test.d.ts +0 -1
- package/dist/activity-card/__tests__/example.test.js +0 -73
- package/dist/activity-card/__tests__/layout.test.d.ts +0 -1
- package/dist/activity-card/__tests__/layout.test.js +0 -141
- package/dist/activity-card/__tests__/resolver.test.d.ts +0 -1
- package/dist/activity-card/__tests__/resolver.test.js +0 -325
- package/dist/activity-card/__tests__/validate.test.d.ts +0 -1
- package/dist/activity-card/__tests__/validate.test.js +0 -149
- package/dist/actor/__tests__/validate.test.d.ts +0 -1
- package/dist/actor/__tests__/validate.test.js +0 -95
- package/dist/applications/__tests__/validate.test.d.ts +0 -1
- package/dist/applications/__tests__/validate.test.js +0 -223
- package/dist/assertion/__tests__/example.test.d.ts +0 -1
- package/dist/assertion/__tests__/example.test.js +0 -32
- package/dist/assertion/__tests__/validate.test.d.ts +0 -1
- package/dist/assertion/__tests__/validate.test.js +0 -130
- package/dist/blocks/__tests__/layout.test.d.ts +0 -1
- package/dist/blocks/__tests__/layout.test.js +0 -153
- package/dist/blocks/__tests__/validate.test.d.ts +0 -1
- package/dist/blocks/__tests__/validate.test.js +0 -235
- package/dist/business-service/__tests__/validate.test.d.ts +0 -1
- package/dist/business-service/__tests__/validate.test.js +0 -135
- package/dist/capability-map/__tests__/CapabilityMapView.test.d.ts +0 -1
- package/dist/capability-map/__tests__/CapabilityMapView.test.js +0 -217
- package/dist/capability-map/__tests__/address.test.d.ts +0 -1
- package/dist/capability-map/__tests__/address.test.js +0 -49
- package/dist/capability-map/__tests__/dsm-layout.test.d.ts +0 -1
- package/dist/capability-map/__tests__/dsm-layout.test.js +0 -46
- package/dist/capability-map/__tests__/dsm-mutations.test.d.ts +0 -1
- package/dist/capability-map/__tests__/dsm-mutations.test.js +0 -125
- package/dist/capability-map/__tests__/dsm-validate.test.d.ts +0 -1
- package/dist/capability-map/__tests__/dsm-validate.test.js +0 -56
- package/dist/capability-map/__tests__/validate.test.d.ts +0 -1
- package/dist/capability-map/__tests__/validate.test.js +0 -212
- package/dist/change/__tests__/validate.test.d.ts +0 -1
- package/dist/change/__tests__/validate.test.js +0 -79
- package/dist/codex/__tests__/example.test.d.ts +0 -1
- package/dist/codex/__tests__/example.test.js +0 -33
- package/dist/codex/__tests__/validate.test.d.ts +0 -1
- package/dist/codex/__tests__/validate.test.js +0 -68
- package/dist/compliance/__tests__/canon-catalog.test.d.ts +0 -1
- package/dist/compliance/__tests__/canon-catalog.test.js +0 -60
- package/dist/compliance/__tests__/classify.test.d.ts +0 -1
- package/dist/compliance/__tests__/classify.test.js +0 -58
- package/dist/compliance/__tests__/confidence.test.d.ts +0 -1
- package/dist/compliance/__tests__/confidence.test.js +0 -78
- package/dist/compliance/__tests__/coverage-metric.test.d.ts +0 -1
- package/dist/compliance/__tests__/coverage-metric.test.js +0 -264
- package/dist/compliance/__tests__/demo-scenario.test.d.ts +0 -1
- package/dist/compliance/__tests__/demo-scenario.test.js +0 -226
- package/dist/compliance/__tests__/example.test.d.ts +0 -1
- package/dist/compliance/__tests__/example.test.js +0 -51
- package/dist/compliance/__tests__/gap-report.test.d.ts +0 -1
- package/dist/compliance/__tests__/gap-report.test.js +0 -113
- package/dist/compliance/__tests__/html.test.d.ts +0 -1
- package/dist/compliance/__tests__/html.test.js +0 -122
- package/dist/compliance/__tests__/impact.test.d.ts +0 -1
- package/dist/compliance/__tests__/impact.test.js +0 -913
- package/dist/compliance/__tests__/markdown.test.d.ts +0 -1
- package/dist/compliance/__tests__/markdown.test.js +0 -85
- package/dist/compliance/__tests__/trace.test.d.ts +0 -1
- package/dist/compliance/__tests__/trace.test.js +0 -144
- package/dist/compliance/__tests__/view-resolution.test.d.ts +0 -1
- package/dist/compliance/__tests__/view-resolution.test.js +0 -59
- package/dist/compliance/__tests__/views.test.d.ts +0 -1
- package/dist/compliance/__tests__/views.test.js +0 -59
- package/dist/compliance-matrix/__tests__/build.test.d.ts +0 -1
- package/dist/compliance-matrix/__tests__/build.test.js +0 -183
- package/dist/compliance-matrix/__tests__/example.test.d.ts +0 -1
- package/dist/compliance-matrix/__tests__/example.test.js +0 -49
- package/dist/confidence/__tests__/score.test.d.ts +0 -1
- package/dist/confidence/__tests__/score.test.js +0 -188
- package/dist/constraint/__tests__/example.test.d.ts +0 -1
- package/dist/constraint/__tests__/example.test.js +0 -14
- package/dist/constraint/__tests__/validate.test.d.ts +0 -1
- package/dist/constraint/__tests__/validate.test.js +0 -58
- package/dist/factor/__tests__/validate.test.d.ts +0 -1
- package/dist/factor/__tests__/validate.test.js +0 -112
- package/dist/fgca/__tests__/chain-table.test.d.ts +0 -1
- package/dist/fgca/__tests__/chain-table.test.js +0 -158
- package/dist/fgca/__tests__/layout.test.d.ts +0 -1
- package/dist/fgca/__tests__/layout.test.js +0 -140
- package/dist/fgca/__tests__/parse-canonical.test.d.ts +0 -1
- package/dist/fgca/__tests__/parse-canonical.test.js +0 -268
- package/dist/fgca/__tests__/preview-layout.test.d.ts +0 -1
- package/dist/fgca/__tests__/preview-layout.test.js +0 -106
- package/dist/fgca/__tests__/resolver.test.d.ts +0 -1
- package/dist/fgca/__tests__/resolver.test.js +0 -185
- package/dist/fgca/__tests__/validate.test.d.ts +0 -1
- package/dist/fgca/__tests__/validate.test.js +0 -125
- package/dist/goals/__tests__/GoalTreeView.test.d.ts +0 -1
- package/dist/goals/__tests__/GoalTreeView.test.js +0 -337
- package/dist/goals/__tests__/layout.test.d.ts +0 -1
- package/dist/goals/__tests__/layout.test.js +0 -153
- package/dist/goals/__tests__/mutations.test.d.ts +0 -1
- package/dist/goals/__tests__/mutations.test.js +0 -134
- package/dist/goals/__tests__/parse-canonical.test.d.ts +0 -1
- package/dist/goals/__tests__/parse-canonical.test.js +0 -131
- package/dist/goals/__tests__/validate.test.d.ts +0 -1
- package/dist/goals/__tests__/validate.test.js +0 -183
- package/dist/integration/__tests__/validate.test.d.ts +0 -1
- package/dist/integration/__tests__/validate.test.js +0 -169
- package/dist/location/__tests__/validate.test.d.ts +0 -1
- package/dist/location/__tests__/validate.test.js +0 -107
- package/dist/node/__tests__/validate.test.d.ts +0 -1
- package/dist/node/__tests__/validate.test.js +0 -100
- package/dist/process-blueprint/__tests__/compliance-lane.test.d.ts +0 -1
- package/dist/process-blueprint/__tests__/compliance-lane.test.js +0 -272
- package/dist/process-blueprint/__tests__/layout.test.d.ts +0 -1
- package/dist/process-blueprint/__tests__/layout.test.js +0 -196
- package/dist/process-blueprint/__tests__/validate.test.d.ts +0 -1
- package/dist/process-blueprint/__tests__/validate.test.js +0 -280
- package/dist/process-map/__tests__/validate.test.d.ts +0 -1
- package/dist/process-map/__tests__/validate.test.js +0 -199
- package/dist/products/__tests__/validate.test.d.ts +0 -1
- package/dist/products/__tests__/validate.test.js +0 -210
- package/dist/repo-validate/__tests__/validate-repo.test.d.ts +0 -1
- package/dist/repo-validate/__tests__/validate-repo.test.js +0 -576
- package/dist/requirement/__tests__/example.test.d.ts +0 -1
- package/dist/requirement/__tests__/example.test.js +0 -21
- package/dist/requirement/__tests__/validate.test.d.ts +0 -1
- package/dist/requirement/__tests__/validate.test.js +0 -80
- package/dist/scenarios/__tests__/validate.test.d.ts +0 -1
- package/dist/scenarios/__tests__/validate.test.js +0 -183
- package/dist/stakeholder/__tests__/validate.test.d.ts +0 -1
- package/dist/stakeholder/__tests__/validate.test.js +0 -88
- package/dist/target-state/__tests__/validate.test.d.ts +0 -1
- package/dist/target-state/__tests__/validate.test.js +0 -78
- package/dist/technology-service/__tests__/validate.test.d.ts +0 -1
- package/dist/technology-service/__tests__/validate.test.js +0 -121
- package/dist/theme/__tests__/tokens.test.d.ts +0 -1
- package/dist/theme/__tests__/tokens.test.js +0 -159
- package/dist/webview/__tests__/entity-text-layout.test.d.ts +0 -1
- package/dist/webview/__tests__/entity-text-layout.test.js +0 -155
- package/dist/webview/__tests__/entry-notations.test.d.ts +0 -1
- package/dist/webview/__tests__/entry-notations.test.js +0 -62
- package/dist/webview/__tests__/entry.test.d.ts +0 -1
- package/dist/webview/__tests__/entry.test.js +0 -56
- package/dist/webview/__tests__/render-activities.test.d.ts +0 -1
- package/dist/webview/__tests__/render-activities.test.js +0 -91
- package/dist/webview/__tests__/render-blocks.test.d.ts +0 -1
- package/dist/webview/__tests__/render-blocks.test.js +0 -175
- package/dist/webview/__tests__/render-goals.test.d.ts +0 -1
- package/dist/webview/__tests__/render-goals.test.js +0 -120
- package/dist/webview/__tests__/render-process.test.d.ts +0 -1
- package/dist/webview/__tests__/render-process.test.js +0 -463
- package/dist/webview/__tests__/render-util.test.d.ts +0 -1
- package/dist/webview/__tests__/render-util.test.js +0 -54
- package/src/__tests__/edge-path.test.ts +0 -67
- package/src/__tests__/node-size-presets.test.ts +0 -50
- package/src/__tests__/scope.test.ts +0 -27
- package/src/__tests__/yaml-normalize.test.ts +0 -158
- package/src/activities/__tests__/cpm.test.ts +0 -164
- package/src/activities/__tests__/gantt.test.ts +0 -290
- package/src/activities/__tests__/layout.test.ts +0 -112
- package/src/activities/__tests__/validate.test.ts +0 -446
- package/src/activity-card/__tests__/example.test.ts +0 -83
- package/src/activity-card/__tests__/layout.test.ts +0 -162
- package/src/activity-card/__tests__/resolver.test.ts +0 -357
- package/src/activity-card/__tests__/validate.test.ts +0 -167
- package/src/actor/__tests__/validate.test.ts +0 -114
- package/src/applications/__tests__/validate.test.ts +0 -256
- package/src/assertion/__tests__/example.test.ts +0 -37
- package/src/assertion/__tests__/validate.test.ts +0 -142
- package/src/blocks/__tests__/layout.test.ts +0 -169
- package/src/blocks/__tests__/validate.test.ts +0 -260
- package/src/business-service/__tests__/validate.test.ts +0 -160
- package/src/capability-map/__tests__/CapabilityMapView.test.tsx +0 -232
- package/src/capability-map/__tests__/address.test.ts +0 -59
- package/src/capability-map/__tests__/dsm-layout.test.ts +0 -52
- package/src/capability-map/__tests__/dsm-mutations.test.ts +0 -141
- package/src/capability-map/__tests__/dsm-validate.test.ts +0 -65
- package/src/capability-map/__tests__/validate.test.ts +0 -238
- package/src/change/__tests__/validate.test.ts +0 -97
- package/src/codex/__tests__/example.test.ts +0 -40
- package/src/codex/__tests__/validate.test.ts +0 -84
- package/src/compliance/__tests__/canon-catalog.test.ts +0 -68
- package/src/compliance/__tests__/classify.test.ts +0 -64
- package/src/compliance/__tests__/confidence.test.ts +0 -98
- package/src/compliance/__tests__/coverage-metric.test.ts +0 -300
- package/src/compliance/__tests__/demo-scenario.test.ts +0 -273
- package/src/compliance/__tests__/example.test.ts +0 -57
- package/src/compliance/__tests__/gap-report.test.ts +0 -129
- package/src/compliance/__tests__/html.test.ts +0 -142
- package/src/compliance/__tests__/impact.test.ts +0 -1060
- package/src/compliance/__tests__/markdown.test.ts +0 -95
- package/src/compliance/__tests__/trace.test.ts +0 -157
- package/src/compliance/__tests__/view-resolution.test.ts +0 -80
- package/src/compliance/__tests__/views.test.ts +0 -64
- package/src/compliance-matrix/__tests__/build.test.ts +0 -200
- package/src/compliance-matrix/__tests__/example.test.ts +0 -57
- package/src/confidence/__tests__/score.test.ts +0 -254
- package/src/constraint/__tests__/example.test.ts +0 -19
- package/src/constraint/__tests__/validate.test.ts +0 -68
- package/src/factor/__tests__/validate.test.ts +0 -133
- package/src/fgca/__tests__/chain-table.test.ts +0 -172
- package/src/fgca/__tests__/layout.test.ts +0 -179
- package/src/fgca/__tests__/parse-canonical.test.ts +0 -296
- package/src/fgca/__tests__/preview-layout.test.ts +0 -124
- package/src/fgca/__tests__/resolver.test.ts +0 -209
- package/src/fgca/__tests__/validate.test.ts +0 -142
- package/src/goals/__tests__/GoalTreeView.test.tsx +0 -361
- package/src/goals/__tests__/layout.test.ts +0 -175
- package/src/goals/__tests__/mutations.test.ts +0 -153
- package/src/goals/__tests__/parse-canonical.test.ts +0 -147
- package/src/goals/__tests__/validate.test.ts +0 -202
- package/src/integration/__tests__/validate.test.ts +0 -203
- package/src/location/__tests__/validate.test.ts +0 -127
- package/src/node/__tests__/validate.test.ts +0 -118
- package/src/process-blueprint/__tests__/compliance-lane.test.ts +0 -320
- package/src/process-blueprint/__tests__/layout.test.ts +0 -240
- package/src/process-blueprint/__tests__/validate.test.ts +0 -310
- package/src/process-map/__tests__/validate.test.ts +0 -223
- package/src/products/__tests__/validate.test.ts +0 -239
- package/src/repo-validate/__tests__/validate-repo.test.ts +0 -699
- package/src/requirement/__tests__/example.test.ts +0 -24
- package/src/requirement/__tests__/validate.test.ts +0 -96
- package/src/scenarios/__tests__/validate.test.ts +0 -209
- package/src/stakeholder/__tests__/validate.test.ts +0 -105
- package/src/target-state/__tests__/validate.test.ts +0 -95
- package/src/technology-service/__tests__/validate.test.ts +0 -143
- package/src/theme/__tests__/tokens.test.ts +0 -185
- package/src/webview/__tests__/entity-text-layout.test.ts +0 -182
- package/src/webview/__tests__/entry-notations.test.ts +0 -77
- package/src/webview/__tests__/entry.test.ts +0 -64
- package/src/webview/__tests__/render-activities.test.ts +0 -100
- package/src/webview/__tests__/render-blocks.test.ts +0 -206
- package/src/webview/__tests__/render-goals.test.ts +0 -128
- package/src/webview/__tests__/render-process.test.ts +0 -538
- package/src/webview/__tests__/render-util.test.ts +0 -66
|
@@ -1,361 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { layoutGoalTree } from '../layout.js';
|
|
3
|
-
import type { GoalTree } from '../types.js';
|
|
4
|
-
|
|
5
|
-
const TREE: GoalTree = {
|
|
6
|
-
goal_types: [
|
|
7
|
-
{ name: 'Strategy', level: 0 },
|
|
8
|
-
{ name: 'Business Goal', level: 1 },
|
|
9
|
-
{ name: 'Project', level: 2 },
|
|
10
|
-
],
|
|
11
|
-
goals: [
|
|
12
|
-
{ id: 1, name: 'North Star', type: 'Strategy', level: 0, parent_id: 0 },
|
|
13
|
-
{ id: 2, name: 'EU Expansion', type: 'Business Goal', level: 1, parent_id: 1 },
|
|
14
|
-
{ id: 3, name: 'Berlin Office', type: 'Project', level: 2, parent_id: 2 },
|
|
15
|
-
{ id: 4, name: 'London Office', type: 'Project', level: 2, parent_id: 2 },
|
|
16
|
-
],
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
describe('layoutGoalTree', () => {
|
|
20
|
-
it('returns nodes for all goals', () => {
|
|
21
|
-
const layout = layoutGoalTree(TREE);
|
|
22
|
-
expect(layout.nodes).toHaveLength(4);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('returns edges for parent-child pairs', () => {
|
|
26
|
-
const layout = layoutGoalTree(TREE);
|
|
27
|
-
expect(layout.edges).toHaveLength(3); // 1→2, 2→3, 2→4
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('levels map to increasing x positions', () => {
|
|
31
|
-
const layout = layoutGoalTree(TREE);
|
|
32
|
-
const byId = new Map(layout.nodes.map(n => [n.id, n]));
|
|
33
|
-
expect(byId.get(1)!.x).toBeLessThan(byId.get(2)!.x);
|
|
34
|
-
expect(byId.get(2)!.x).toBeLessThan(byId.get(3)!.x);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('siblings at same level have different y positions', () => {
|
|
38
|
-
const layout = layoutGoalTree(TREE);
|
|
39
|
-
const byId = new Map(layout.nodes.map(n => [n.id, n]));
|
|
40
|
-
expect(byId.get(3)!.y).not.toBe(byId.get(4)!.y);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('returns non-zero bounds for non-empty tree', () => {
|
|
44
|
-
const layout = layoutGoalTree(TREE);
|
|
45
|
-
expect(layout.bounds.width).toBeGreaterThan(0);
|
|
46
|
-
expect(layout.bounds.height).toBeGreaterThan(0);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('returns empty layout for empty goals', () => {
|
|
50
|
-
const layout = layoutGoalTree({ goal_types: [], goals: [] });
|
|
51
|
-
expect(layout.nodes).toHaveLength(0);
|
|
52
|
-
expect(layout.edges).toHaveLength(0);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('nodes have default 250×80 size', () => {
|
|
56
|
-
const layout = layoutGoalTree(TREE);
|
|
57
|
-
expect(layout.nodes[0].width).toBe(250);
|
|
58
|
-
expect(layout.nodes[0].height).toBe(80);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('respects custom nodeWidth/nodeHeight', () => {
|
|
62
|
-
const layout = layoutGoalTree(TREE, { nodeWidth: 200, nodeHeight: 60 });
|
|
63
|
-
expect(layout.nodes[0].width).toBe(200);
|
|
64
|
-
expect(layout.nodes[0].height).toBe(60);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
// vkgeorgia/strategy#75 — configurable spacing. The preview maps
|
|
68
|
-
// horizontalGap → rankSep and verticalGap → nodeSep.
|
|
69
|
-
it('larger rankSep widens the column step', () => {
|
|
70
|
-
const tight = layoutGoalTree(TREE, { rankSep: 80 });
|
|
71
|
-
const wide = layoutGoalTree(TREE, { rankSep: 200 });
|
|
72
|
-
const stepOf = (l: ReturnType<typeof layoutGoalTree>) => {
|
|
73
|
-
const byId = new Map(l.nodes.map(n => [n.id, n]));
|
|
74
|
-
return byId.get(2)!.x - byId.get(1)!.x;
|
|
75
|
-
};
|
|
76
|
-
expect(stepOf(wide)).toBeGreaterThan(stepOf(tight));
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it('larger nodeSep increases the gap between stacked siblings', () => {
|
|
80
|
-
const gapOf = (sep: number) => {
|
|
81
|
-
const l = layoutGoalTree(TREE, { nodeSep: sep });
|
|
82
|
-
const byId = new Map(l.nodes.map(n => [n.id, n]));
|
|
83
|
-
return Math.abs(byId.get(4)!.y - byId.get(3)!.y);
|
|
84
|
-
};
|
|
85
|
-
expect(gapOf(120)).toBeGreaterThan(gapOf(24));
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('each node carries original goal data', () => {
|
|
89
|
-
const layout = layoutGoalTree(TREE);
|
|
90
|
-
const node1 = layout.nodes.find(n => n.id === 1)!;
|
|
91
|
-
expect(node1.data.name).toBe('North Star');
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it('viewDepth hides nodes beyond depth', () => {
|
|
95
|
-
const layout = layoutGoalTree(TREE, { viewDepth: 1 });
|
|
96
|
-
// Level 2 nodes (id 3, 4) should be hidden
|
|
97
|
-
expect(layout.nodes.every(n => n.data.level <= 1)).toBe(true);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('compresses non-contiguous levels into adjacent columns (no phantom empty columns)', () => {
|
|
101
|
-
// Legacy / non-canonical input: goal_types skip levels 1 and 3, so
|
|
102
|
-
// goals sit at levels 0, 2, 4. Column x must advance by exactly one
|
|
103
|
-
// step per used level, not per absolute level value — otherwise the
|
|
104
|
-
// skipped levels open empty columns and double the horizontal spacing.
|
|
105
|
-
const gapped: GoalTree = {
|
|
106
|
-
goal_types: [
|
|
107
|
-
{ name: 'Strategy', level: 0 },
|
|
108
|
-
{ name: 'Strategic Goal', level: 2 },
|
|
109
|
-
{ name: 'Project Goal', level: 4 },
|
|
110
|
-
],
|
|
111
|
-
goals: [
|
|
112
|
-
{ id: 1, name: 'Root', type: 'Strategy', level: 0, parent_id: 0 },
|
|
113
|
-
{ id: 2, name: 'Mid', type: 'Strategic Goal', level: 2, parent_id: 1 },
|
|
114
|
-
{ id: 3, name: 'Leaf', type: 'Project Goal', level: 4, parent_id: 2 },
|
|
115
|
-
],
|
|
116
|
-
};
|
|
117
|
-
const layout = layoutGoalTree(gapped);
|
|
118
|
-
const byId = new Map(layout.nodes.map(n => [n.id, n]));
|
|
119
|
-
const step = byId.get(2)!.x - byId.get(1)!.x;
|
|
120
|
-
// Root→Mid and Mid→Leaf must use the same single-column step despite
|
|
121
|
-
// the level numbers jumping by 2 each time.
|
|
122
|
-
expect(byId.get(3)!.x - byId.get(2)!.x).toBe(step);
|
|
123
|
-
// And that step is one node width + one rank separator (250 + 80).
|
|
124
|
-
expect(step).toBe(250 + 80);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
// Pre-release blocker regression (orchestrator review 2026-05-21).
|
|
128
|
-
it('[blocker] does not stack-overflow on a self-parent cycle', () => {
|
|
129
|
-
const cyclic: GoalTree = {
|
|
130
|
-
goal_types: [{ name: 'X', level: 0 }],
|
|
131
|
-
goals: [{ id: 1, name: 'self-parent', type: 'X', level: 0, parent_id: 1 }],
|
|
132
|
-
};
|
|
133
|
-
// Without a visited-set inside placeSubtree, this recurses forever.
|
|
134
|
-
expect(() => layoutGoalTree(cyclic)).not.toThrow();
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('[blocker] does not stack-overflow on a 2-node mutual cycle', () => {
|
|
138
|
-
const cyclic: GoalTree = {
|
|
139
|
-
goal_types: [{ name: 'X', level: 0 }, { name: 'Y', level: 1 }],
|
|
140
|
-
goals: [
|
|
141
|
-
{ id: 1, name: 'A', type: 'X', level: 0, parent_id: 2 },
|
|
142
|
-
{ id: 2, name: 'B', type: 'Y', level: 1, parent_id: 1 },
|
|
143
|
-
],
|
|
144
|
-
};
|
|
145
|
-
expect(() => layoutGoalTree(cyclic)).not.toThrow();
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// vkgeorgia/strategy#77 — scope filtering.
|
|
149
|
-
describe('scope', () => {
|
|
150
|
-
const ids = (l: ReturnType<typeof layoutGoalTree>) => l.nodes.map(n => n.id).sort((a, b) => a - b);
|
|
151
|
-
|
|
152
|
-
it("mode 'all' matches the baseline", () => {
|
|
153
|
-
expect(ids(layoutGoalTree(TREE, { scope: { mode: 'all' } }))).toEqual(ids(layoutGoalTree(TREE)));
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
it("mode 'level' trims goals strictly above the cap", () => {
|
|
157
|
-
// TREE: id1 level0, id2 level1, id3/id4 level2.
|
|
158
|
-
const layout = layoutGoalTree(TREE, { scope: { mode: 'level', maxLevel: 1 } });
|
|
159
|
-
expect(ids(layout)).toEqual([1, 2]);
|
|
160
|
-
expect(layout.nodes.every(n => n.data.level <= 1)).toBe(true);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
it("mode 'root' keeps the chosen goal and its descendants", () => {
|
|
164
|
-
// root id2 → itself + children id3, id4.
|
|
165
|
-
const layout = layoutGoalTree(TREE, { scope: { mode: 'root', rootGoalId: '2' } });
|
|
166
|
-
expect(ids(layout)).toEqual([2, 3, 4]);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it("mode 'root' returns an empty layout when the root is absent", () => {
|
|
170
|
-
const layout = layoutGoalTree(TREE, { scope: { mode: 'root', rootGoalId: '999' } });
|
|
171
|
-
expect(layout.nodes).toHaveLength(0);
|
|
172
|
-
expect(layout.edges).toHaveLength(0);
|
|
173
|
-
});
|
|
174
|
-
});
|
|
175
|
-
});
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { reparent, addChild, deleteWithDescendants, moveToBacklog, restoreFromBacklog } from '../mutations.js';
|
|
3
|
-
import type { GoalTree } from '../types.js';
|
|
4
|
-
|
|
5
|
-
const TREE: GoalTree = {
|
|
6
|
-
goal_types: [
|
|
7
|
-
{ name: 'Strategy', level: 0 },
|
|
8
|
-
{ name: 'Business Goal', level: 1 },
|
|
9
|
-
{ name: 'Project', level: 2 },
|
|
10
|
-
],
|
|
11
|
-
goals: [
|
|
12
|
-
{ id: 1, name: 'North Star', type: 'Strategy', level: 0, parent_id: 0 },
|
|
13
|
-
{ id: 2, name: 'EU Expansion', type: 'Business Goal', level: 1, parent_id: 1 },
|
|
14
|
-
{ id: 3, name: 'Berlin Office', type: 'Project', level: 2, parent_id: 2 },
|
|
15
|
-
],
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
describe('reparent', () => {
|
|
19
|
-
it('moves a goal to a new parent', () => {
|
|
20
|
-
const r = reparent(TREE, 3, 1);
|
|
21
|
-
expect(r.ok).toBe(true);
|
|
22
|
-
const moved = r.result!.goals.find(g => g.id === 3)!;
|
|
23
|
-
expect(moved.parent_id).toBe(1);
|
|
24
|
-
expect(moved.level).toBe(1);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('refuses to create a cycle', () => {
|
|
28
|
-
const r = reparent(TREE, 1, 3);
|
|
29
|
-
expect(r.ok).toBe(false);
|
|
30
|
-
expect(r.error?.code).toBe('MUTATION_REFUSED');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('refuses self-reparent', () => {
|
|
34
|
-
expect(reparent(TREE, 1, 1).ok).toBe(false);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('refuses reparent that would exceed max level', () => {
|
|
38
|
-
const r = reparent(TREE, 1, 3); // would make level 3 which exceeds max 2
|
|
39
|
-
expect(r.ok).toBe(false);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('preserves immutability — original tree unchanged', () => {
|
|
43
|
-
reparent(TREE, 3, 1);
|
|
44
|
-
expect(TREE.goals.find(g => g.id === 3)!.parent_id).toBe(2);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
describe('addChild', () => {
|
|
49
|
-
it('adds a child with auto-assigned id and level', () => {
|
|
50
|
-
const r = addChild(TREE, 2, { name: 'Warsaw Office', type: 'Project', level: 2, parent_id: 2 });
|
|
51
|
-
expect(r.ok).toBe(true);
|
|
52
|
-
const newGoal = r.result!.goals.find(g => g.name === 'Warsaw Office')!;
|
|
53
|
-
expect(newGoal.id).toBeGreaterThan(3);
|
|
54
|
-
expect(newGoal.parent_id).toBe(2);
|
|
55
|
-
expect(newGoal.level).toBe(2);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('adds root-level child when parentId is 0', () => {
|
|
59
|
-
const r = addChild(TREE, 0, { name: 'Second Strategy', type: 'Strategy', level: 0, parent_id: 0 });
|
|
60
|
-
expect(r.ok).toBe(true);
|
|
61
|
-
expect(r.result!.goals.find(g => g.name === 'Second Strategy')!.level).toBe(0);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('refuses when parent not found', () => {
|
|
65
|
-
const r = addChild(TREE, 99, { name: 'X', type: 'Project', level: 2, parent_id: 99 });
|
|
66
|
-
expect(r.ok).toBe(false);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it('preserves immutability', () => {
|
|
70
|
-
const before = TREE.goals.length;
|
|
71
|
-
addChild(TREE, 1, { name: 'New', type: 'Business Goal', level: 1, parent_id: 1 });
|
|
72
|
-
expect(TREE.goals.length).toBe(before);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
describe('deleteWithDescendants', () => {
|
|
77
|
-
it('deletes goal and all descendants', () => {
|
|
78
|
-
const r = deleteWithDescendants(TREE, 2);
|
|
79
|
-
expect(r.ok).toBe(true);
|
|
80
|
-
const ids = r.result!.goals.map(g => g.id);
|
|
81
|
-
expect(ids).not.toContain(2);
|
|
82
|
-
expect(ids).not.toContain(3);
|
|
83
|
-
expect(ids).toContain(1);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it('refuses when goal not found', () => {
|
|
87
|
-
expect(deleteWithDescendants(TREE, 99).ok).toBe(false);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('preserves immutability', () => {
|
|
91
|
-
deleteWithDescendants(TREE, 2);
|
|
92
|
-
expect(TREE.goals.length).toBe(3);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
describe('moveToBacklog', () => {
|
|
97
|
-
it('sets parent_id to 0', () => {
|
|
98
|
-
const r = moveToBacklog(TREE, 3);
|
|
99
|
-
expect(r.ok).toBe(true);
|
|
100
|
-
expect(r.result!.goals.find(g => g.id === 3)!.parent_id).toBe(0);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
describe('restoreFromBacklog', () => {
|
|
105
|
-
it('reparents the goal to the new parent', () => {
|
|
106
|
-
const backlogged = moveToBacklog(TREE, 3).result!;
|
|
107
|
-
const r = restoreFromBacklog(backlogged, 3, 1);
|
|
108
|
-
expect(r.ok).toBe(true);
|
|
109
|
-
expect(r.result!.goals.find(g => g.id === 3)!.parent_id).toBe(1);
|
|
110
|
-
});
|
|
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
|
-
});
|