@transitrix/diagrams 1.8.6 → 1.8.7

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.
Files changed (247) hide show
  1. package/package.json +7 -2
  2. package/dist/__tests__/edge-path.test.d.ts +0 -1
  3. package/dist/__tests__/edge-path.test.js +0 -55
  4. package/dist/__tests__/node-size-presets.test.d.ts +0 -1
  5. package/dist/__tests__/node-size-presets.test.js +0 -30
  6. package/dist/__tests__/scope.test.d.ts +0 -1
  7. package/dist/__tests__/scope.test.js +0 -23
  8. package/dist/__tests__/yaml-normalize.test.d.ts +0 -1
  9. package/dist/__tests__/yaml-normalize.test.js +0 -148
  10. package/dist/activities/__tests__/cpm.test.d.ts +0 -1
  11. package/dist/activities/__tests__/cpm.test.js +0 -146
  12. package/dist/activities/__tests__/gantt.test.d.ts +0 -1
  13. package/dist/activities/__tests__/gantt.test.js +0 -263
  14. package/dist/activities/__tests__/layout.test.d.ts +0 -1
  15. package/dist/activities/__tests__/layout.test.js +0 -98
  16. package/dist/activities/__tests__/validate.test.d.ts +0 -1
  17. package/dist/activities/__tests__/validate.test.js +0 -397
  18. package/dist/activity-card/__tests__/example.test.d.ts +0 -1
  19. package/dist/activity-card/__tests__/example.test.js +0 -73
  20. package/dist/activity-card/__tests__/layout.test.d.ts +0 -1
  21. package/dist/activity-card/__tests__/layout.test.js +0 -141
  22. package/dist/activity-card/__tests__/resolver.test.d.ts +0 -1
  23. package/dist/activity-card/__tests__/resolver.test.js +0 -325
  24. package/dist/activity-card/__tests__/validate.test.d.ts +0 -1
  25. package/dist/activity-card/__tests__/validate.test.js +0 -149
  26. package/dist/actor/__tests__/validate.test.d.ts +0 -1
  27. package/dist/actor/__tests__/validate.test.js +0 -95
  28. package/dist/applications/__tests__/validate.test.d.ts +0 -1
  29. package/dist/applications/__tests__/validate.test.js +0 -223
  30. package/dist/assertion/__tests__/example.test.d.ts +0 -1
  31. package/dist/assertion/__tests__/example.test.js +0 -32
  32. package/dist/assertion/__tests__/validate.test.d.ts +0 -1
  33. package/dist/assertion/__tests__/validate.test.js +0 -130
  34. package/dist/blocks/__tests__/layout.test.d.ts +0 -1
  35. package/dist/blocks/__tests__/layout.test.js +0 -153
  36. package/dist/blocks/__tests__/validate.test.d.ts +0 -1
  37. package/dist/blocks/__tests__/validate.test.js +0 -235
  38. package/dist/business-service/__tests__/validate.test.d.ts +0 -1
  39. package/dist/business-service/__tests__/validate.test.js +0 -135
  40. package/dist/capability-map/__tests__/CapabilityMapView.test.d.ts +0 -1
  41. package/dist/capability-map/__tests__/CapabilityMapView.test.js +0 -217
  42. package/dist/capability-map/__tests__/address.test.d.ts +0 -1
  43. package/dist/capability-map/__tests__/address.test.js +0 -49
  44. package/dist/capability-map/__tests__/dsm-layout.test.d.ts +0 -1
  45. package/dist/capability-map/__tests__/dsm-layout.test.js +0 -46
  46. package/dist/capability-map/__tests__/dsm-mutations.test.d.ts +0 -1
  47. package/dist/capability-map/__tests__/dsm-mutations.test.js +0 -125
  48. package/dist/capability-map/__tests__/dsm-validate.test.d.ts +0 -1
  49. package/dist/capability-map/__tests__/dsm-validate.test.js +0 -56
  50. package/dist/capability-map/__tests__/validate.test.d.ts +0 -1
  51. package/dist/capability-map/__tests__/validate.test.js +0 -212
  52. package/dist/change/__tests__/validate.test.d.ts +0 -1
  53. package/dist/change/__tests__/validate.test.js +0 -79
  54. package/dist/codex/__tests__/example.test.d.ts +0 -1
  55. package/dist/codex/__tests__/example.test.js +0 -33
  56. package/dist/codex/__tests__/validate.test.d.ts +0 -1
  57. package/dist/codex/__tests__/validate.test.js +0 -68
  58. package/dist/compliance/__tests__/canon-catalog.test.d.ts +0 -1
  59. package/dist/compliance/__tests__/canon-catalog.test.js +0 -60
  60. package/dist/compliance/__tests__/classify.test.d.ts +0 -1
  61. package/dist/compliance/__tests__/classify.test.js +0 -58
  62. package/dist/compliance/__tests__/confidence.test.d.ts +0 -1
  63. package/dist/compliance/__tests__/confidence.test.js +0 -78
  64. package/dist/compliance/__tests__/coverage-metric.test.d.ts +0 -1
  65. package/dist/compliance/__tests__/coverage-metric.test.js +0 -264
  66. package/dist/compliance/__tests__/demo-scenario.test.d.ts +0 -1
  67. package/dist/compliance/__tests__/demo-scenario.test.js +0 -226
  68. package/dist/compliance/__tests__/example.test.d.ts +0 -1
  69. package/dist/compliance/__tests__/example.test.js +0 -51
  70. package/dist/compliance/__tests__/gap-report.test.d.ts +0 -1
  71. package/dist/compliance/__tests__/gap-report.test.js +0 -113
  72. package/dist/compliance/__tests__/html.test.d.ts +0 -1
  73. package/dist/compliance/__tests__/html.test.js +0 -122
  74. package/dist/compliance/__tests__/impact.test.d.ts +0 -1
  75. package/dist/compliance/__tests__/impact.test.js +0 -913
  76. package/dist/compliance/__tests__/markdown.test.d.ts +0 -1
  77. package/dist/compliance/__tests__/markdown.test.js +0 -85
  78. package/dist/compliance/__tests__/trace.test.d.ts +0 -1
  79. package/dist/compliance/__tests__/trace.test.js +0 -144
  80. package/dist/compliance/__tests__/view-resolution.test.d.ts +0 -1
  81. package/dist/compliance/__tests__/view-resolution.test.js +0 -59
  82. package/dist/compliance/__tests__/views.test.d.ts +0 -1
  83. package/dist/compliance/__tests__/views.test.js +0 -59
  84. package/dist/compliance-matrix/__tests__/build.test.d.ts +0 -1
  85. package/dist/compliance-matrix/__tests__/build.test.js +0 -183
  86. package/dist/compliance-matrix/__tests__/example.test.d.ts +0 -1
  87. package/dist/compliance-matrix/__tests__/example.test.js +0 -49
  88. package/dist/confidence/__tests__/score.test.d.ts +0 -1
  89. package/dist/confidence/__tests__/score.test.js +0 -188
  90. package/dist/constraint/__tests__/example.test.d.ts +0 -1
  91. package/dist/constraint/__tests__/example.test.js +0 -14
  92. package/dist/constraint/__tests__/validate.test.d.ts +0 -1
  93. package/dist/constraint/__tests__/validate.test.js +0 -58
  94. package/dist/factor/__tests__/validate.test.d.ts +0 -1
  95. package/dist/factor/__tests__/validate.test.js +0 -112
  96. package/dist/fgca/__tests__/chain-table.test.d.ts +0 -1
  97. package/dist/fgca/__tests__/chain-table.test.js +0 -158
  98. package/dist/fgca/__tests__/layout.test.d.ts +0 -1
  99. package/dist/fgca/__tests__/layout.test.js +0 -140
  100. package/dist/fgca/__tests__/parse-canonical.test.d.ts +0 -1
  101. package/dist/fgca/__tests__/parse-canonical.test.js +0 -268
  102. package/dist/fgca/__tests__/preview-layout.test.d.ts +0 -1
  103. package/dist/fgca/__tests__/preview-layout.test.js +0 -106
  104. package/dist/fgca/__tests__/resolver.test.d.ts +0 -1
  105. package/dist/fgca/__tests__/resolver.test.js +0 -185
  106. package/dist/fgca/__tests__/validate.test.d.ts +0 -1
  107. package/dist/fgca/__tests__/validate.test.js +0 -125
  108. package/dist/goals/__tests__/GoalTreeView.test.d.ts +0 -1
  109. package/dist/goals/__tests__/GoalTreeView.test.js +0 -337
  110. package/dist/goals/__tests__/layout.test.d.ts +0 -1
  111. package/dist/goals/__tests__/layout.test.js +0 -153
  112. package/dist/goals/__tests__/mutations.test.d.ts +0 -1
  113. package/dist/goals/__tests__/mutations.test.js +0 -134
  114. package/dist/goals/__tests__/parse-canonical.test.d.ts +0 -1
  115. package/dist/goals/__tests__/parse-canonical.test.js +0 -131
  116. package/dist/goals/__tests__/validate.test.d.ts +0 -1
  117. package/dist/goals/__tests__/validate.test.js +0 -183
  118. package/dist/integration/__tests__/validate.test.d.ts +0 -1
  119. package/dist/integration/__tests__/validate.test.js +0 -169
  120. package/dist/location/__tests__/validate.test.d.ts +0 -1
  121. package/dist/location/__tests__/validate.test.js +0 -107
  122. package/dist/node/__tests__/validate.test.d.ts +0 -1
  123. package/dist/node/__tests__/validate.test.js +0 -100
  124. package/dist/process-blueprint/__tests__/compliance-lane.test.d.ts +0 -1
  125. package/dist/process-blueprint/__tests__/compliance-lane.test.js +0 -272
  126. package/dist/process-blueprint/__tests__/layout.test.d.ts +0 -1
  127. package/dist/process-blueprint/__tests__/layout.test.js +0 -196
  128. package/dist/process-blueprint/__tests__/validate.test.d.ts +0 -1
  129. package/dist/process-blueprint/__tests__/validate.test.js +0 -280
  130. package/dist/process-map/__tests__/validate.test.d.ts +0 -1
  131. package/dist/process-map/__tests__/validate.test.js +0 -199
  132. package/dist/products/__tests__/validate.test.d.ts +0 -1
  133. package/dist/products/__tests__/validate.test.js +0 -210
  134. package/dist/repo-validate/__tests__/validate-repo.test.d.ts +0 -1
  135. package/dist/repo-validate/__tests__/validate-repo.test.js +0 -576
  136. package/dist/requirement/__tests__/example.test.d.ts +0 -1
  137. package/dist/requirement/__tests__/example.test.js +0 -21
  138. package/dist/requirement/__tests__/validate.test.d.ts +0 -1
  139. package/dist/requirement/__tests__/validate.test.js +0 -80
  140. package/dist/scenarios/__tests__/validate.test.d.ts +0 -1
  141. package/dist/scenarios/__tests__/validate.test.js +0 -183
  142. package/dist/stakeholder/__tests__/validate.test.d.ts +0 -1
  143. package/dist/stakeholder/__tests__/validate.test.js +0 -88
  144. package/dist/target-state/__tests__/validate.test.d.ts +0 -1
  145. package/dist/target-state/__tests__/validate.test.js +0 -78
  146. package/dist/technology-service/__tests__/validate.test.d.ts +0 -1
  147. package/dist/technology-service/__tests__/validate.test.js +0 -121
  148. package/dist/theme/__tests__/tokens.test.d.ts +0 -1
  149. package/dist/theme/__tests__/tokens.test.js +0 -159
  150. package/dist/webview/__tests__/entity-text-layout.test.d.ts +0 -1
  151. package/dist/webview/__tests__/entity-text-layout.test.js +0 -155
  152. package/dist/webview/__tests__/entry-notations.test.d.ts +0 -1
  153. package/dist/webview/__tests__/entry-notations.test.js +0 -62
  154. package/dist/webview/__tests__/entry.test.d.ts +0 -1
  155. package/dist/webview/__tests__/entry.test.js +0 -56
  156. package/dist/webview/__tests__/render-activities.test.d.ts +0 -1
  157. package/dist/webview/__tests__/render-activities.test.js +0 -91
  158. package/dist/webview/__tests__/render-blocks.test.d.ts +0 -1
  159. package/dist/webview/__tests__/render-blocks.test.js +0 -175
  160. package/dist/webview/__tests__/render-goals.test.d.ts +0 -1
  161. package/dist/webview/__tests__/render-goals.test.js +0 -120
  162. package/dist/webview/__tests__/render-process.test.d.ts +0 -1
  163. package/dist/webview/__tests__/render-process.test.js +0 -463
  164. package/dist/webview/__tests__/render-util.test.d.ts +0 -1
  165. package/dist/webview/__tests__/render-util.test.js +0 -54
  166. package/src/__tests__/edge-path.test.ts +0 -67
  167. package/src/__tests__/node-size-presets.test.ts +0 -50
  168. package/src/__tests__/scope.test.ts +0 -27
  169. package/src/__tests__/yaml-normalize.test.ts +0 -158
  170. package/src/activities/__tests__/cpm.test.ts +0 -164
  171. package/src/activities/__tests__/gantt.test.ts +0 -290
  172. package/src/activities/__tests__/layout.test.ts +0 -112
  173. package/src/activities/__tests__/validate.test.ts +0 -446
  174. package/src/activity-card/__tests__/example.test.ts +0 -83
  175. package/src/activity-card/__tests__/layout.test.ts +0 -162
  176. package/src/activity-card/__tests__/resolver.test.ts +0 -357
  177. package/src/activity-card/__tests__/validate.test.ts +0 -167
  178. package/src/actor/__tests__/validate.test.ts +0 -114
  179. package/src/applications/__tests__/validate.test.ts +0 -256
  180. package/src/assertion/__tests__/example.test.ts +0 -37
  181. package/src/assertion/__tests__/validate.test.ts +0 -142
  182. package/src/blocks/__tests__/layout.test.ts +0 -169
  183. package/src/blocks/__tests__/validate.test.ts +0 -260
  184. package/src/business-service/__tests__/validate.test.ts +0 -160
  185. package/src/capability-map/__tests__/CapabilityMapView.test.tsx +0 -232
  186. package/src/capability-map/__tests__/address.test.ts +0 -59
  187. package/src/capability-map/__tests__/dsm-layout.test.ts +0 -52
  188. package/src/capability-map/__tests__/dsm-mutations.test.ts +0 -141
  189. package/src/capability-map/__tests__/dsm-validate.test.ts +0 -65
  190. package/src/capability-map/__tests__/validate.test.ts +0 -238
  191. package/src/change/__tests__/validate.test.ts +0 -97
  192. package/src/codex/__tests__/example.test.ts +0 -40
  193. package/src/codex/__tests__/validate.test.ts +0 -84
  194. package/src/compliance/__tests__/canon-catalog.test.ts +0 -68
  195. package/src/compliance/__tests__/classify.test.ts +0 -64
  196. package/src/compliance/__tests__/confidence.test.ts +0 -98
  197. package/src/compliance/__tests__/coverage-metric.test.ts +0 -300
  198. package/src/compliance/__tests__/demo-scenario.test.ts +0 -273
  199. package/src/compliance/__tests__/example.test.ts +0 -57
  200. package/src/compliance/__tests__/gap-report.test.ts +0 -129
  201. package/src/compliance/__tests__/html.test.ts +0 -142
  202. package/src/compliance/__tests__/impact.test.ts +0 -1060
  203. package/src/compliance/__tests__/markdown.test.ts +0 -95
  204. package/src/compliance/__tests__/trace.test.ts +0 -157
  205. package/src/compliance/__tests__/view-resolution.test.ts +0 -80
  206. package/src/compliance/__tests__/views.test.ts +0 -64
  207. package/src/compliance-matrix/__tests__/build.test.ts +0 -200
  208. package/src/compliance-matrix/__tests__/example.test.ts +0 -57
  209. package/src/confidence/__tests__/score.test.ts +0 -254
  210. package/src/constraint/__tests__/example.test.ts +0 -19
  211. package/src/constraint/__tests__/validate.test.ts +0 -68
  212. package/src/factor/__tests__/validate.test.ts +0 -133
  213. package/src/fgca/__tests__/chain-table.test.ts +0 -172
  214. package/src/fgca/__tests__/layout.test.ts +0 -179
  215. package/src/fgca/__tests__/parse-canonical.test.ts +0 -296
  216. package/src/fgca/__tests__/preview-layout.test.ts +0 -124
  217. package/src/fgca/__tests__/resolver.test.ts +0 -209
  218. package/src/fgca/__tests__/validate.test.ts +0 -142
  219. package/src/goals/__tests__/GoalTreeView.test.tsx +0 -361
  220. package/src/goals/__tests__/layout.test.ts +0 -175
  221. package/src/goals/__tests__/mutations.test.ts +0 -153
  222. package/src/goals/__tests__/parse-canonical.test.ts +0 -147
  223. package/src/goals/__tests__/validate.test.ts +0 -202
  224. package/src/integration/__tests__/validate.test.ts +0 -203
  225. package/src/location/__tests__/validate.test.ts +0 -127
  226. package/src/node/__tests__/validate.test.ts +0 -118
  227. package/src/process-blueprint/__tests__/compliance-lane.test.ts +0 -320
  228. package/src/process-blueprint/__tests__/layout.test.ts +0 -240
  229. package/src/process-blueprint/__tests__/validate.test.ts +0 -310
  230. package/src/process-map/__tests__/validate.test.ts +0 -223
  231. package/src/products/__tests__/validate.test.ts +0 -239
  232. package/src/repo-validate/__tests__/validate-repo.test.ts +0 -699
  233. package/src/requirement/__tests__/example.test.ts +0 -24
  234. package/src/requirement/__tests__/validate.test.ts +0 -96
  235. package/src/scenarios/__tests__/validate.test.ts +0 -209
  236. package/src/stakeholder/__tests__/validate.test.ts +0 -105
  237. package/src/target-state/__tests__/validate.test.ts +0 -95
  238. package/src/technology-service/__tests__/validate.test.ts +0 -143
  239. package/src/theme/__tests__/tokens.test.ts +0 -185
  240. package/src/webview/__tests__/entity-text-layout.test.ts +0 -182
  241. package/src/webview/__tests__/entry-notations.test.ts +0 -77
  242. package/src/webview/__tests__/entry.test.ts +0 -64
  243. package/src/webview/__tests__/render-activities.test.ts +0 -100
  244. package/src/webview/__tests__/render-blocks.test.ts +0 -206
  245. package/src/webview/__tests__/render-goals.test.ts +0 -128
  246. package/src/webview/__tests__/render-process.test.ts +0 -538
  247. package/src/webview/__tests__/render-util.test.ts +0 -66
@@ -1,232 +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 { CapabilityMapView, computeDragOutcome } from '../CapabilityMapView.js';
6
- import type { CapabilityMap } from '../dsm-schema.js';
7
- import type { CapabilityMapChange } from '../CapabilityMapView.js';
8
-
9
- // See goals/__tests__/GoalTreeView.test.tsx for why these three shims are
10
- // needed — reactflow keeps a node `visibility: hidden` (and inert to
11
- // drag/measurement logic) until ResizeObserver reports its size, and reads
12
- // the computed transform back out via DOMMatrixReadOnly; jsdom has neither.
13
- class MockResizeObserver {
14
- #callback: ResizeObserverCallback;
15
- constructor(callback: ResizeObserverCallback) {
16
- this.#callback = callback;
17
- }
18
- observe(target: Element) {
19
- queueMicrotask(() => {
20
- this.#callback([{ target, contentRect: target.getBoundingClientRect() } as ResizeObserverEntry], this as unknown as ResizeObserver);
21
- });
22
- }
23
- unobserve() {}
24
- disconnect() {}
25
- }
26
-
27
- class MockDOMMatrixReadOnly {
28
- m41 = 0;
29
- m42 = 0;
30
- constructor(transform?: string) {
31
- if (!transform || transform === 'none') return;
32
- const t = /translate\((-?[\d.]+)px,\s*(-?[\d.]+)px\)/.exec(transform);
33
- if (t) {
34
- this.m41 = Number(t[1]);
35
- this.m42 = Number(t[2]);
36
- }
37
- }
38
- }
39
-
40
- function makeMap(): CapabilityMap {
41
- return {
42
- organisation: 'Acme Corp',
43
- set_id: 'v1.0',
44
- capabilities: [
45
- { id: 1, name: 'Customer Acquisition', address: '1.0.0', maturity: [{ date: '2026-04-01', level: 3 }] },
46
- { id: 2, name: 'Lead Qualification', address: '1.1.0' },
47
- { id: 3, name: 'Inbound Lead Scoring', address: '1.1.1' },
48
- ],
49
- };
50
- }
51
-
52
- beforeEach(() => {
53
- (global as unknown as { ResizeObserver: unknown }).ResizeObserver = MockResizeObserver;
54
- (window as unknown as { DOMMatrixReadOnly: unknown }).DOMMatrixReadOnly = MockDOMMatrixReadOnly;
55
- vi.spyOn(Element.prototype, 'getBoundingClientRect').mockImplementation(function (this: Element) {
56
- const isNode = this.classList?.contains('react-flow__node');
57
- const width = isNode ? 250 : 1000;
58
- const height = isNode ? 64 : 800;
59
- return { width, height, top: 0, left: 0, right: width, bottom: height, x: 0, y: 0, toJSON() { return this; } } as DOMRect;
60
- });
61
- });
62
-
63
- afterEach(() => {
64
- cleanup();
65
- vi.restoreAllMocks();
66
- });
67
-
68
- describe('CapabilityMapView', () => {
69
- it('renders the virtual root and every on-diagram capability', async () => {
70
- render(<CapabilityMapView map={makeMap()} />);
71
- await waitFor(() => {
72
- expect(screen.getByText('Acme Corp')).toBeTruthy();
73
- expect(screen.getByText('Customer Acquisition')).toBeTruthy();
74
- expect(screen.getByText('Lead Qualification')).toBeTruthy();
75
- expect(screen.getByText('Inbound Lead Scoring')).toBeTruthy();
76
- });
77
- });
78
-
79
- it('renders a maturity dot only for capabilities with a maturity snapshot', async () => {
80
- render(<CapabilityMapView map={makeMap()} />);
81
- await waitFor(() => expect(screen.getByText('Customer Acquisition')).toBeTruthy());
82
- expect(screen.getByLabelText('Maturity 3')).toBeTruthy();
83
- expect(screen.queryByLabelText(/Maturity/, { selector: '[aria-label="Maturity undefined"]' })).toBeNull();
84
- });
85
-
86
- it('shows backlog capabilities in the sidebar, not on canvas', async () => {
87
- const map: CapabilityMap = {
88
- organisation: 'Acme Corp',
89
- set_id: 'v1.0',
90
- capabilities: [
91
- { id: 1, name: 'Customer Acquisition', address: '1.0.0' },
92
- { id: 2, name: 'Parked idea', address: '0.0.0', backlog: true },
93
- ],
94
- };
95
- render(<CapabilityMapView map={map} showBacklog />);
96
- await waitFor(() => expect(screen.getByText('Customer Acquisition')).toBeTruthy());
97
- expect(screen.getByText('Backlog')).toBeTruthy();
98
- expect(screen.getByText('Parked idea')).toBeTruthy();
99
- });
100
-
101
- it('does not render add/delete affordances when readOnly', async () => {
102
- render(<CapabilityMapView map={makeMap()} readOnly />);
103
- await waitFor(() => expect(screen.getByText('Customer Acquisition')).toBeTruthy());
104
- expect(screen.queryByLabelText('Add child capability')).toBeNull();
105
- expect(screen.queryByLabelText('Delete capability')).toBeNull();
106
- });
107
-
108
- it('fires onChange with kind "addChild" when the add-child button is clicked', async () => {
109
- const onChange = vi.fn<(e: CapabilityMapChange) => void>();
110
- render(<CapabilityMapView map={makeMap()} onChange={onChange} />);
111
- await waitFor(() => expect(screen.getByText('Customer Acquisition')).toBeTruthy());
112
- const rootCard = document.querySelector('.react-flow__node[data-id="1"]')!;
113
- rootCard.querySelector<HTMLElement>('[aria-label="Add child capability"]')!
114
- .dispatchEvent(new MouseEvent('click', { bubbles: true }));
115
-
116
- await waitFor(() => expect(onChange).toHaveBeenCalledTimes(1));
117
- const event = onChange.mock.calls[0][0];
118
- expect(event.kind).toBe('addChild');
119
- if (event.kind === 'addChild') {
120
- expect(event.newCap.address).toBe('1.2.0');
121
- }
122
- });
123
-
124
- it('fires onChange with kind "delete" when the delete button is clicked', async () => {
125
- const onChange = vi.fn<(e: CapabilityMapChange) => void>();
126
- render(<CapabilityMapView map={makeMap()} onChange={onChange} />);
127
- await waitFor(() => expect(screen.getByText('Inbound Lead Scoring')).toBeTruthy());
128
- const leafCard = document.querySelector('.react-flow__node[data-id="3"]')!;
129
- leafCard.querySelector<HTMLElement>('[aria-label="Delete capability"]')!
130
- .dispatchEvent(new MouseEvent('click', { bubbles: true }));
131
-
132
- await waitFor(() => expect(onChange).toHaveBeenCalledTimes(1));
133
- expect(onChange.mock.calls[0][0].kind).toBe('delete');
134
- });
135
-
136
- it('fires onEditRequest on double-click', async () => {
137
- const onEditRequest = vi.fn();
138
- render(<CapabilityMapView map={makeMap()} onEditRequest={onEditRequest} />);
139
- await waitFor(() => expect(screen.getByText('Customer Acquisition')).toBeTruthy());
140
- document.querySelector('.react-flow__node[data-id="1"]')!
141
- .dispatchEvent(new MouseEvent('dblclick', { bubbles: true }));
142
-
143
- await waitFor(() => expect(onEditRequest).toHaveBeenCalledTimes(1));
144
- expect(onEditRequest.mock.calls[0][0]).toMatchObject({ id: 1, name: 'Customer Acquisition' });
145
- });
146
-
147
- it('fires onChange with kind "normaliseAddresses" from the toolbar button', async () => {
148
- const onChange = vi.fn<(e: CapabilityMapChange) => void>();
149
- render(<CapabilityMapView map={makeMap()} onChange={onChange} />);
150
- await waitFor(() => expect(screen.getByText('Customer Acquisition')).toBeTruthy());
151
- screen.getByText('Normalise addresses').dispatchEvent(new MouseEvent('click', { bubbles: true }));
152
- await waitFor(() => expect(onChange).toHaveBeenCalledTimes(1));
153
- expect(onChange.mock.calls[0][0].kind).toBe('normaliseAddresses');
154
- });
155
-
156
- it('fires onChange with kind "restoreFromBacklog" when a backlog card is dropped onto a canvas card', async () => {
157
- const map: CapabilityMap = {
158
- organisation: 'Acme Corp',
159
- set_id: 'v1.0',
160
- capabilities: [
161
- { id: 1, name: 'Customer Acquisition', address: '1.0.0' },
162
- { id: 2, name: 'Parked idea', address: '0.0.0', backlog: true },
163
- ],
164
- };
165
- const onChange = vi.fn<(e: CapabilityMapChange) => void>();
166
- render(<CapabilityMapView map={map} onChange={onChange} showBacklog />);
167
- await waitFor(() => expect(screen.getByText('Parked idea')).toBeTruthy());
168
-
169
- const store = new Map<string, string>();
170
- const dataTransfer = { setData: (k: string, v: string) => store.set(k, v), getData: (k: string) => store.get(k) ?? '', effectAllowed: 'move' };
171
- function fireDnd(el: Element, type: string, coords: { clientX: number; clientY: number }) {
172
- const event = new Event(type, { bubbles: true, cancelable: true });
173
- Object.defineProperty(event, 'dataTransfer', { value: dataTransfer });
174
- Object.assign(event, coords);
175
- el.dispatchEvent(event);
176
- }
177
-
178
- const backlogItem = screen.getByText('Parked idea').closest('div[draggable]')!;
179
- const rootCard = document.querySelector('.react-flow__node[data-id="1"]')!;
180
- document.elementFromPoint = vi.fn().mockReturnValue(rootCard);
181
-
182
- fireDnd(backlogItem, 'dragstart', { clientX: 0, clientY: 0 });
183
- fireDnd(rootCard, 'drop', { clientX: 10, clientY: 10 });
184
-
185
- await waitFor(() => expect(onChange).toHaveBeenCalledTimes(1));
186
- const event = onChange.mock.calls[0][0];
187
- expect(event.kind).toBe('restoreFromBacklog');
188
- if (event.kind === 'restoreFromBacklog') {
189
- expect(event.id).toBe(2);
190
- expect(event.parentId).toBe(1);
191
- }
192
- });
193
- });
194
-
195
- // Dragging a card is choreographed by reactflow's own pointer/DOM-measurement
196
- // machinery — see the equivalent note in goals/__tests__/GoalTreeView.test.tsx.
197
- // computeDragOutcome() is the pure decision this component's onNodeDragStop
198
- // calls once reactflow reports a drag, tested directly here.
199
- describe('computeDragOutcome (reparent / moveBranchToBacklog decision logic)', () => {
200
- const map = makeMap();
201
-
202
- it('fires a "reparent" change when dropped onto another card', () => {
203
- const change = computeDragOutcome(map, 3, { kind: 'node', id: 1 });
204
- expect(change?.kind).toBe('reparent');
205
- if (change?.kind === 'reparent') {
206
- expect(change.sourceId).toBe(3);
207
- expect(change.targetId).toBe(1);
208
- }
209
- });
210
-
211
- it('fires a "reparent" change (promotion to L1) when dropped on the root', () => {
212
- const change = computeDragOutcome(map, 2, { kind: 'root' });
213
- expect(change?.kind).toBe('reparent');
214
- if (change?.kind === 'reparent') {
215
- expect(change.targetId).toBe(0);
216
- expect(change.result.capabilities.find((c) => c.id === 2)?.address).toBe('2.0.0');
217
- }
218
- });
219
-
220
- it('fires a "moveBranchToBacklog" change when dropped on the backlog zone', () => {
221
- const change = computeDragOutcome(map, 2, { kind: 'backlog' });
222
- expect(change?.kind).toBe('moveBranchToBacklog');
223
- });
224
-
225
- it('is a no-op when dropped nowhere in particular', () => {
226
- expect(computeDragOutcome(map, 2, null)).toBeNull();
227
- });
228
-
229
- it('is a no-op when dropped on itself', () => {
230
- expect(computeDragOutcome(map, 2, { kind: 'node', id: 2 })).toBeNull();
231
- });
232
- });
@@ -1,59 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { parseAddress, formatAddress, getLevel, getParentAddress, getFirstFreeAddress, isAddressTaken } from '../address.js';
3
- import type { Capability } from '../dsm-schema.js';
4
-
5
- function cap(id: number, address: string, backlog = false): Capability {
6
- return { id, name: `Cap ${id}`, address, backlog };
7
- }
8
-
9
- describe('parseAddress / formatAddress', () => {
10
- it('round-trips X.Y.Z', () => {
11
- for (const addr of ['1.0.0', '1.2.0', '1.2.3', '0.0.0', '42.7.19']) {
12
- expect(formatAddress(parseAddress(addr))).toBe(addr);
13
- }
14
- });
15
-
16
- it('throws on malformed input', () => {
17
- expect(() => parseAddress('1.2')).toThrow();
18
- expect(() => parseAddress('1.2.3.4')).toThrow();
19
- expect(() => parseAddress('a.b.c')).toThrow();
20
- });
21
- });
22
-
23
- describe('getLevel', () => {
24
- it('classifies each address shape', () => {
25
- expect(getLevel('1.0.0')).toBe(1);
26
- expect(getLevel('1.2.0')).toBe(2);
27
- expect(getLevel('1.2.3')).toBe(3);
28
- expect(getLevel('0.0.0')).toBe('backlog');
29
- });
30
- });
31
-
32
- describe('getParentAddress', () => {
33
- it('walks up one level at a time', () => {
34
- expect(getParentAddress('1.2.3')).toBe('1.2.0');
35
- expect(getParentAddress('1.2.0')).toBe('1.0.0');
36
- expect(getParentAddress('1.0.0')).toBeNull();
37
- });
38
- });
39
-
40
- describe('getFirstFreeAddress / isAddressTaken', () => {
41
- it('finds the first unused L2 slot under an L1 parent', () => {
42
- const caps = [cap(1, '1.0.0'), cap(2, '1.1.0'), cap(3, '1.2.0')];
43
- expect(getFirstFreeAddress('1.0.0', caps)).toBe('1.3.0');
44
- });
45
-
46
- it('finds the first unused L3 slot under an L2 parent', () => {
47
- const caps = [cap(1, '1.0.0'), cap(2, '1.1.0'), cap(3, '1.1.1')];
48
- expect(getFirstFreeAddress('1.1.0', caps)).toBe('1.1.2');
49
- });
50
-
51
- it('ignores backlog entries when checking occupancy', () => {
52
- const caps = [cap(1, '1.0.0'), cap(2, '0.0.0', true)];
53
- expect(isAddressTaken('1.1.0', caps)).toBe(false);
54
- });
55
-
56
- it('rejects an L3 address as a parent', () => {
57
- expect(() => getFirstFreeAddress('1.1.1', [])).toThrow();
58
- });
59
- });
@@ -1,52 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { layoutCapabilityMap } from '../dsm-layout.js';
3
- import type { CapabilityMap } from '../dsm-schema.js';
4
-
5
- function map(): CapabilityMap {
6
- return {
7
- organisation: 'Acme Corp',
8
- set_id: 'v1.0',
9
- capabilities: [
10
- { id: 1, name: 'Customer Acquisition', address: '1.0.0' },
11
- { id: 2, name: 'Lead Qualification', address: '1.1.0' },
12
- { id: 3, name: 'Inbound Lead Scoring', address: '1.1.1' },
13
- { id: 4, name: 'Order Management', address: '2.0.0' },
14
- { id: 5, name: 'Parked idea', address: '0.0.0', backlog: true },
15
- ],
16
- };
17
- }
18
-
19
- describe('layoutCapabilityMap', () => {
20
- it('lays out a virtual root plus every on-diagram capability, one column per level', () => {
21
- const layout = layoutCapabilityMap(map());
22
- expect(layout.rootNode.data).toBeNull();
23
- expect(layout.nodes).toHaveLength(4); // backlog entry excluded
24
- const byId = new Map(layout.nodes.map((n) => [n.id, n]));
25
- expect(byId.get(1)!.x).toBe(byId.get(4)!.x); // both L1s share a column
26
- expect(byId.get(2)!.x).toBeGreaterThan(byId.get(1)!.x); // L2 one column further right
27
- expect(byId.get(3)!.x).toBeGreaterThan(byId.get(2)!.x); // L3 further still
28
- expect(byId.get(1)!.x).toBeGreaterThan(layout.rootNode.x); // root sits left of the L1s
29
- });
30
-
31
- it('connects the root to every L1 and each parent to its children', () => {
32
- const layout = layoutCapabilityMap(map());
33
- const edgeSet = new Set(layout.edges.map((e) => `${e.source}->${e.target}`));
34
- expect(edgeSet.has('root->1')).toBe(true);
35
- expect(edgeSet.has('root->4')).toBe(true);
36
- expect(edgeSet.has('1->2')).toBe(true);
37
- expect(edgeSet.has('2->3')).toBe(true);
38
- });
39
-
40
- it('marks a node as having hidden children when its subtree is collapsed', () => {
41
- const layout = layoutCapabilityMap(map(), { hideCollapsed: [2] });
42
- const cap2 = layout.nodes.find((n) => n.id === 2)!;
43
- expect(cap2.hasHiddenChildren).toBe(true);
44
- expect(layout.nodes.some((n) => n.id === 3)).toBe(false); // hidden subtree omitted
45
- });
46
-
47
- it('returns just the root when there are no on-diagram capabilities', () => {
48
- const layout = layoutCapabilityMap({ organisation: 'Empty Co', set_id: 'v1', capabilities: [] });
49
- expect(layout.nodes).toHaveLength(0);
50
- expect(layout.rootNode.data).toBeNull();
51
- });
52
- });
@@ -1,141 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { reparent, addChild, deleteWithDescendants, moveBranchToBacklog, restoreFromBacklog, normaliseAddresses } from '../dsm-mutations.js';
3
- import type { CapabilityMap } from '../dsm-schema.js';
4
-
5
- function baseMap(): CapabilityMap {
6
- return {
7
- organisation: 'Acme Corp',
8
- set_id: 'v1.0',
9
- capabilities: [
10
- { id: 1, name: 'Customer Acquisition', address: '1.0.0' },
11
- { id: 2, name: 'Lead Qualification', address: '1.1.0' },
12
- { id: 3, name: 'Inbound Lead Scoring', address: '1.1.1' },
13
- { id: 4, name: 'Order Management', address: '2.0.0' },
14
- ],
15
- };
16
- }
17
-
18
- describe('reparent', () => {
19
- it('moves an L3 under a different L2 (no cascade)', () => {
20
- const map = baseMap();
21
- const r = reparent(map, 3, 4); // Inbound Lead Scoring (L3) -> Order Management (L1)... newLevel would be 2
22
- expect(r.ok).toBe(true);
23
- const moved = r.result!.capabilities.find((c) => c.id === 3)!;
24
- expect(moved.address).toBe('2.1.0'); // now an L2 under capability 4
25
- });
26
-
27
- it('promotes an L2 to L1 and cascades its L3 children to L2 (spec §9)', () => {
28
- const map = baseMap();
29
- const r = reparent(map, 2, 0); // Lead Qualification (L2, id 2) -> virtual root
30
- expect(r.ok).toBe(true);
31
- const promoted = r.result!.capabilities.find((c) => c.id === 2)!;
32
- const child = r.result!.capabilities.find((c) => c.id === 3)!;
33
- expect(promoted.address).toBe('3.0.0'); // first free L1 slot (1 and 2 taken)
34
- expect(child.address).toBe('3.1.0'); // cascaded from L3 to L2 under the new L1
35
- });
36
-
37
- it('refuses a demotion that would push a grandchild past L3', () => {
38
- const map = baseMap();
39
- // Capability 1 (L1) has descendant 2 (L2) and 3 (L3, a grandchild).
40
- // Demoting 1 under 4 (making 1 an L2) would need 3 to become L4.
41
- const r = reparent(map, 1, 4);
42
- expect(r.ok).toBe(false);
43
- });
44
-
45
- it('refuses reparenting onto its own descendant (cycle)', () => {
46
- const map = baseMap();
47
- const r = reparent(map, 2, 3); // Lead Qualification onto its own child
48
- expect(r.ok).toBe(false);
49
- });
50
-
51
- it('refuses reparenting onto itself', () => {
52
- const map = baseMap();
53
- expect(reparent(map, 1, 1).ok).toBe(false);
54
- });
55
-
56
- it('leaves the original map untouched', () => {
57
- const map = baseMap();
58
- reparent(map, 3, 4);
59
- expect(map.capabilities.find((c) => c.id === 3)!.address).toBe('1.1.1');
60
- });
61
- });
62
-
63
- describe('addChild', () => {
64
- it('assigns the first free address under the parent', () => {
65
- const map = baseMap();
66
- const r = addChild(map, 1, { name: 'New L2' });
67
- expect(r.ok).toBe(true);
68
- const added = r.result!.capabilities.find((c) => c.name === 'New L2')!;
69
- expect(added.address).toBe('1.2.0');
70
- expect(added.backlog).toBe(false);
71
- });
72
-
73
- it('assigns a new L1 address when parentId is 0 (root)', () => {
74
- const map = baseMap();
75
- const r = addChild(map, 0, { name: 'New L1' });
76
- expect(r.ok).toBe(true);
77
- expect(r.result!.capabilities.find((c) => c.name === 'New L1')!.address).toBe('3.0.0');
78
- });
79
-
80
- it('refuses adding a child under an L3 (would exceed max depth)', () => {
81
- const map = baseMap();
82
- const r = addChild(map, 3, { name: 'Too deep' });
83
- expect(r.ok).toBe(false);
84
- });
85
- });
86
-
87
- describe('deleteWithDescendants', () => {
88
- it('removes the capability and every descendant', () => {
89
- const map = baseMap();
90
- const r = deleteWithDescendants(map, 2); // Lead Qualification + its L3 child
91
- expect(r.ok).toBe(true);
92
- const ids = r.result!.capabilities.map((c) => c.id);
93
- expect(ids).not.toContain(2);
94
- expect(ids).not.toContain(3);
95
- expect(ids).toContain(1);
96
- expect(ids).toContain(4);
97
- });
98
- });
99
-
100
- describe('moveBranchToBacklog / restoreFromBacklog', () => {
101
- it('moves a branch to the backlog and back', () => {
102
- const map = baseMap();
103
- const toBacklog = moveBranchToBacklog(map, 2);
104
- expect(toBacklog.ok).toBe(true);
105
- const backlogged = toBacklog.result!.capabilities.filter((c) => c.id === 2 || c.id === 3);
106
- expect(backlogged.every((c) => c.backlog && c.address === '0.0.0')).toBe(true);
107
-
108
- const restored = restoreFromBacklog(toBacklog.result!, 2, 4);
109
- expect(restored.ok).toBe(true);
110
- const cap2 = restored.result!.capabilities.find((c) => c.id === 2)!;
111
- expect(cap2.backlog).toBe(false);
112
- expect(cap2.address).toBe('2.1.0');
113
- // Restoring the parent doesn't automatically restore its backlogged
114
- // children — matches deleteWithDescendants/addChild's scope (this
115
- // mutation acts on the single named id only).
116
- expect(restored.result!.capabilities.find((c) => c.id === 3)!.backlog).toBe(true);
117
- });
118
- });
119
-
120
- describe('normaliseAddresses', () => {
121
- it('moves a capability with an unresolvable parent address to the backlog', () => {
122
- const map: CapabilityMap = {
123
- organisation: 'Acme Corp',
124
- set_id: 'v1.0',
125
- capabilities: [
126
- { id: 1, name: 'Customer Acquisition', address: '1.0.0' },
127
- { id: 2, name: 'Dangling L2', address: '9.1.0' }, // no capability at 9.0.0
128
- ],
129
- };
130
- const result = normaliseAddresses(map);
131
- const dangling = result.capabilities.find((c) => c.id === 2)!;
132
- expect(dangling.backlog).toBe(true);
133
- expect(dangling.address).toBe('0.0.0');
134
- });
135
-
136
- it('leaves a well-formed hierarchy unchanged', () => {
137
- const map = baseMap();
138
- const result = normaliseAddresses(map);
139
- expect(result.capabilities).toEqual(map.capabilities);
140
- });
141
- });
@@ -1,65 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { validateCapabilityMapData } from '../dsm-validate.js';
3
- import type { CapabilityMap } from '../dsm-schema.js';
4
-
5
- function validMap(): CapabilityMap {
6
- return {
7
- organisation: 'Acme Corp',
8
- set_id: 'v1.0',
9
- capabilities: [
10
- { id: 1, name: 'Customer Acquisition', address: '1.0.0' },
11
- { id: 2, name: 'Lead Qualification', address: '1.1.0' },
12
- { id: 3, name: 'Inbound Lead Scoring', address: '1.1.1' },
13
- ],
14
- };
15
- }
16
-
17
- describe('validateCapabilityMapData', () => {
18
- it('accepts a well-formed map', () => {
19
- expect(validateCapabilityMapData(validMap()).valid).toBe(true);
20
- });
21
-
22
- it('flags a duplicate id', () => {
23
- const map = validMap();
24
- map.capabilities[1].id = 1;
25
- const result = validateCapabilityMapData(map);
26
- expect(result.valid).toBe(false);
27
- expect(result.errors.some((e) => e.code === 'DUPLICATE_ID')).toBe(true);
28
- });
29
-
30
- it('flags a malformed address', () => {
31
- const map = validMap();
32
- map.capabilities[0].address = 'not-an-address';
33
- const result = validateCapabilityMapData(map);
34
- expect(result.errors.some((e) => e.code === 'INVALID_ADDRESS_FORMAT')).toBe(true);
35
- });
36
-
37
- it('flags a too-deep address as MAX_DEPTH_EXCEEDED, not INVALID_ADDRESS_FORMAT', () => {
38
- const map = validMap();
39
- map.capabilities[0].address = '1.2.3.4';
40
- const result = validateCapabilityMapData(map);
41
- expect(result.errors.some((e) => e.code === 'MAX_DEPTH_EXCEEDED')).toBe(true);
42
- expect(result.errors.some((e) => e.code === 'INVALID_ADDRESS_FORMAT')).toBe(false);
43
- });
44
-
45
- it('flags a duplicate on-diagram address', () => {
46
- const map = validMap();
47
- map.capabilities[1].address = '1.0.0';
48
- const result = validateCapabilityMapData(map);
49
- expect(result.errors.some((e) => e.code === 'DUPLICATE_ADDRESS')).toBe(true);
50
- });
51
-
52
- it('warns on a missing parent by address', () => {
53
- const map = validMap();
54
- map.capabilities[1].address = '9.1.0'; // no capability at 9.0.0
55
- const result = validateCapabilityMapData(map);
56
- expect(result.warnings.some((w) => w.code === 'MISSING_PARENT_BY_ADDRESS')).toBe(true);
57
- });
58
-
59
- it('does not flag a backlog entry\'s address as a duplicate or requiring a parent', () => {
60
- const map = validMap();
61
- map.capabilities.push({ id: 4, name: 'Parked idea', address: '0.0.0', backlog: true });
62
- const result = validateCapabilityMapData(map);
63
- expect(result.valid).toBe(true);
64
- });
65
- });