@c-a-f/testing 1.0.1

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 (70) hide show
  1. package/.build/__tests__/react/renderWithCAF.spec.d.ts +1 -0
  2. package/.build/__tests__/react/renderWithCAF.spec.js +53 -0
  3. package/.build/index.d.ts +1 -0
  4. package/.build/index.js +1 -0
  5. package/.build/src/angular/createTestPloc.d.ts +19 -0
  6. package/.build/src/angular/createTestPloc.js +21 -0
  7. package/.build/src/angular/index.d.ts +12 -0
  8. package/.build/src/angular/index.js +12 -0
  9. package/.build/src/angular/mockUseCase.d.ts +32 -0
  10. package/.build/src/angular/mockUseCase.js +40 -0
  11. package/.build/src/angular/provideTestingCAF.d.ts +29 -0
  12. package/.build/src/angular/provideTestingCAF.js +26 -0
  13. package/.build/src/angular/waitForPlocState.d.ts +18 -0
  14. package/.build/src/angular/waitForPlocState.js +20 -0
  15. package/.build/src/core/IntegrationTestHelpers.d.ts +77 -0
  16. package/.build/src/core/IntegrationTestHelpers.js +78 -0
  17. package/.build/src/core/PlocTestHelpers.d.ts +133 -0
  18. package/.build/src/core/PlocTestHelpers.js +205 -0
  19. package/.build/src/core/PulseTestHelpers.d.ts +71 -0
  20. package/.build/src/core/PulseTestHelpers.js +106 -0
  21. package/.build/src/core/RepositoryTestHelpers.d.ts +48 -0
  22. package/.build/src/core/RepositoryTestHelpers.js +76 -0
  23. package/.build/src/core/RouteTestHelpers.d.ts +67 -0
  24. package/.build/src/core/RouteTestHelpers.js +94 -0
  25. package/.build/src/core/UseCaseTestHelpers.d.ts +100 -0
  26. package/.build/src/core/UseCaseTestHelpers.js +161 -0
  27. package/.build/src/core/index.d.ts +6 -0
  28. package/.build/src/core/index.js +6 -0
  29. package/.build/src/i18n/I18nTestHelpers.d.ts +76 -0
  30. package/.build/src/i18n/I18nTestHelpers.js +122 -0
  31. package/.build/src/i18n/index.d.ts +1 -0
  32. package/.build/src/i18n/index.js +1 -0
  33. package/.build/src/index.d.ts +5 -0
  34. package/.build/src/index.js +10 -0
  35. package/.build/src/permission/PermissionTestHelpers.d.ts +75 -0
  36. package/.build/src/permission/PermissionTestHelpers.js +121 -0
  37. package/.build/src/permission/index.d.ts +1 -0
  38. package/.build/src/permission/index.js +1 -0
  39. package/.build/src/react/createTestPloc.d.ts +19 -0
  40. package/.build/src/react/createTestPloc.js +21 -0
  41. package/.build/src/react/index.d.ts +12 -0
  42. package/.build/src/react/index.js +12 -0
  43. package/.build/src/react/mockUseCase.d.ts +36 -0
  44. package/.build/src/react/mockUseCase.js +44 -0
  45. package/.build/src/react/renderWithCAF.d.ts +31 -0
  46. package/.build/src/react/renderWithCAF.js +23 -0
  47. package/.build/src/react/waitForPlocState.d.ts +22 -0
  48. package/.build/src/react/waitForPlocState.js +24 -0
  49. package/.build/src/validation/ValidationTestHelpers.d.ts +66 -0
  50. package/.build/src/validation/ValidationTestHelpers.js +118 -0
  51. package/.build/src/validation/index.d.ts +1 -0
  52. package/.build/src/validation/index.js +1 -0
  53. package/.build/src/vue/createTestPloc.d.ts +19 -0
  54. package/.build/src/vue/createTestPloc.js +21 -0
  55. package/.build/src/vue/index.d.ts +12 -0
  56. package/.build/src/vue/index.js +12 -0
  57. package/.build/src/vue/mockUseCase.d.ts +34 -0
  58. package/.build/src/vue/mockUseCase.js +42 -0
  59. package/.build/src/vue/mountWithCAF.d.ts +31 -0
  60. package/.build/src/vue/mountWithCAF.js +40 -0
  61. package/.build/src/vue/waitForPlocState.d.ts +19 -0
  62. package/.build/src/vue/waitForPlocState.js +21 -0
  63. package/.build/src/workflow/WorkflowTestHelpers.d.ts +75 -0
  64. package/.build/src/workflow/WorkflowTestHelpers.js +146 -0
  65. package/.build/src/workflow/index.d.ts +1 -0
  66. package/.build/src/workflow/index.js +1 -0
  67. package/.build/vitest.config.d.ts +7 -0
  68. package/.build/vitest.config.js +6 -0
  69. package/README.md +598 -0
  70. package/package.json +127 -0
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Wait for a Ploc to reach a state that matches a predicate. Useful in Vue tests
3
+ * after triggering an action that updates the Ploc asynchronously.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { mountWithCAF, createTestPloc, waitForPlocState } from '@c-a-f/testing/vue';
8
+ *
9
+ * const ploc = createTestPloc({ loading: true, items: [] });
10
+ * mountWithCAF(ListComponent, { plocs: { list: ploc } });
11
+ * ploc.changeState({ loading: false, items: [{ id: '1' }] });
12
+ * await waitForPlocState(ploc, (state) => !state.loading && state.items.length > 0);
13
+ * ```
14
+ */
15
+ import type { Ploc } from '@c-a-f/core';
16
+ /**
17
+ * Wait until the Ploc's state satisfies the predicate (or timeout).
18
+ */
19
+ export declare function waitForPlocState<S>(ploc: Ploc<S>, predicate: (state: S) => boolean, timeoutMs?: number): Promise<S>;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Wait for a Ploc to reach a state that matches a predicate. Useful in Vue tests
3
+ * after triggering an action that updates the Ploc asynchronously.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { mountWithCAF, createTestPloc, waitForPlocState } from '@c-a-f/testing/vue';
8
+ *
9
+ * const ploc = createTestPloc({ loading: true, items: [] });
10
+ * mountWithCAF(ListComponent, { plocs: { list: ploc } });
11
+ * ploc.changeState({ loading: false, items: [{ id: '1' }] });
12
+ * await waitForPlocState(ploc, (state) => !state.loading && state.items.length > 0);
13
+ * ```
14
+ */
15
+ import { waitForStateChange } from '../core/PlocTestHelpers';
16
+ /**
17
+ * Wait until the Ploc's state satisfies the predicate (or timeout).
18
+ */
19
+ export function waitForPlocState(ploc, predicate, timeoutMs = 5000) {
20
+ return waitForStateChange(ploc, predicate, timeoutMs);
21
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Test helpers for Workflow.
3
+ *
4
+ * Provides utilities for testing WorkflowManager instances.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { createWorkflowTester, waitForWorkflowState } from '@c-a-f/testing/workflow';
9
+ * import { WorkflowManager, WorkflowDefinition } from '@c-a-f/workflow';
10
+ *
11
+ * const workflow = new WorkflowManager(definition);
12
+ * const tester = createWorkflowTester(workflow);
13
+ *
14
+ * await tester.dispatch('approve');
15
+ * await waitForWorkflowState(workflow, 'approved');
16
+ * ```
17
+ */
18
+ import type { WorkflowManager, WorkflowStateId, WorkflowStateSnapshot } from '@c-a-f/workflow';
19
+ /**
20
+ * Workflow tester utility.
21
+ */
22
+ export declare class WorkflowTester {
23
+ readonly workflow: WorkflowManager;
24
+ private stateHistory;
25
+ private listener;
26
+ constructor(workflow: WorkflowManager);
27
+ /**
28
+ * Get the current state snapshot.
29
+ */
30
+ getState(): WorkflowStateSnapshot;
31
+ /**
32
+ * Get the current state ID.
33
+ */
34
+ getCurrentState(): WorkflowStateId;
35
+ /**
36
+ * Get the state history.
37
+ */
38
+ getStateHistory(): WorkflowStateSnapshot[];
39
+ /**
40
+ * Dispatch an event and wait for transition.
41
+ */
42
+ dispatch(event: string, payload?: unknown): Promise<boolean>;
43
+ /**
44
+ * Check if a transition is available.
45
+ */
46
+ canTransition(event: string): boolean;
47
+ /**
48
+ * Reset the workflow.
49
+ */
50
+ reset(): Promise<void>;
51
+ /**
52
+ * Update workflow context.
53
+ */
54
+ updateContext(context: Record<string, unknown>): void;
55
+ /**
56
+ * Get available transitions from current state.
57
+ */
58
+ getAvailableTransitions(): Record<string, unknown>;
59
+ /**
60
+ * Cleanup: unsubscribe from state changes.
61
+ */
62
+ cleanup(): void;
63
+ }
64
+ /**
65
+ * Create a Workflow tester instance.
66
+ */
67
+ export declare function createWorkflowTester(workflow: WorkflowManager): WorkflowTester;
68
+ /**
69
+ * Wait for workflow to reach a specific state.
70
+ */
71
+ export declare function waitForWorkflowState(workflow: WorkflowManager, targetState: WorkflowStateId, timeout?: number): Promise<WorkflowStateSnapshot>;
72
+ /**
73
+ * Wait for workflow to reach a final state.
74
+ */
75
+ export declare function waitForFinalState(workflow: WorkflowManager, timeout?: number): Promise<WorkflowStateSnapshot>;
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Test helpers for Workflow.
3
+ *
4
+ * Provides utilities for testing WorkflowManager instances.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { createWorkflowTester, waitForWorkflowState } from '@c-a-f/testing/workflow';
9
+ * import { WorkflowManager, WorkflowDefinition } from '@c-a-f/workflow';
10
+ *
11
+ * const workflow = new WorkflowManager(definition);
12
+ * const tester = createWorkflowTester(workflow);
13
+ *
14
+ * await tester.dispatch('approve');
15
+ * await waitForWorkflowState(workflow, 'approved');
16
+ * ```
17
+ */
18
+ /**
19
+ * Workflow tester utility.
20
+ */
21
+ export class WorkflowTester {
22
+ workflow;
23
+ stateHistory = [];
24
+ listener = null;
25
+ constructor(workflow) {
26
+ this.workflow = workflow;
27
+ this.stateHistory.push(workflow.getState());
28
+ this.listener = (snapshot) => {
29
+ this.stateHistory.push(snapshot);
30
+ };
31
+ workflow.subscribe(this.listener);
32
+ }
33
+ /**
34
+ * Get the current state snapshot.
35
+ */
36
+ getState() {
37
+ return this.workflow.getState();
38
+ }
39
+ /**
40
+ * Get the current state ID.
41
+ */
42
+ getCurrentState() {
43
+ return this.workflow.getState().currentState;
44
+ }
45
+ /**
46
+ * Get the state history.
47
+ */
48
+ getStateHistory() {
49
+ return [...this.stateHistory];
50
+ }
51
+ /**
52
+ * Dispatch an event and wait for transition.
53
+ */
54
+ async dispatch(event, payload) {
55
+ return await this.workflow.dispatch(event, payload);
56
+ }
57
+ /**
58
+ * Check if a transition is available.
59
+ */
60
+ canTransition(event) {
61
+ return this.workflow.canTransition(event);
62
+ }
63
+ /**
64
+ * Reset the workflow.
65
+ */
66
+ async reset() {
67
+ await this.workflow.reset();
68
+ }
69
+ /**
70
+ * Update workflow context.
71
+ */
72
+ updateContext(context) {
73
+ this.workflow.updateContext(context);
74
+ }
75
+ /**
76
+ * Get available transitions from current state.
77
+ */
78
+ getAvailableTransitions() {
79
+ return this.workflow.getAvailableTransitions();
80
+ }
81
+ /**
82
+ * Cleanup: unsubscribe from state changes.
83
+ */
84
+ cleanup() {
85
+ if (this.listener) {
86
+ this.workflow.unsubscribe(this.listener);
87
+ this.listener = null;
88
+ }
89
+ }
90
+ }
91
+ /**
92
+ * Create a Workflow tester instance.
93
+ */
94
+ export function createWorkflowTester(workflow) {
95
+ return new WorkflowTester(workflow);
96
+ }
97
+ /**
98
+ * Wait for workflow to reach a specific state.
99
+ */
100
+ export function waitForWorkflowState(workflow, targetState, timeout = 5000) {
101
+ return new Promise((resolve, reject) => {
102
+ // Check current state first
103
+ const currentState = workflow.getState();
104
+ if (currentState.currentState === targetState) {
105
+ resolve(currentState);
106
+ return;
107
+ }
108
+ const listener = (snapshot) => {
109
+ if (snapshot.currentState === targetState) {
110
+ clearTimeout(timer);
111
+ workflow.unsubscribe(listener);
112
+ resolve(snapshot);
113
+ }
114
+ };
115
+ const timer = setTimeout(() => {
116
+ workflow.unsubscribe(listener);
117
+ reject(new Error(`Timeout waiting for workflow state '${targetState}' (${timeout}ms)`));
118
+ }, timeout);
119
+ workflow.subscribe(listener);
120
+ });
121
+ }
122
+ /**
123
+ * Wait for workflow to reach a final state.
124
+ */
125
+ export function waitForFinalState(workflow, timeout = 5000) {
126
+ return new Promise((resolve, reject) => {
127
+ // Check current state first
128
+ const currentState = workflow.getState();
129
+ if (currentState.isFinal) {
130
+ resolve(currentState);
131
+ return;
132
+ }
133
+ const listener = (snapshot) => {
134
+ if (snapshot.isFinal) {
135
+ clearTimeout(timer);
136
+ workflow.unsubscribe(listener);
137
+ resolve(snapshot);
138
+ }
139
+ };
140
+ const timer = setTimeout(() => {
141
+ workflow.unsubscribe(listener);
142
+ reject(new Error(`Timeout waiting for final state (${timeout}ms)`));
143
+ }, timeout);
144
+ workflow.subscribe(listener);
145
+ });
146
+ }
@@ -0,0 +1 @@
1
+ export * from './WorkflowTestHelpers';
@@ -0,0 +1 @@
1
+ export * from './WorkflowTestHelpers';
@@ -0,0 +1,7 @@
1
+ declare const _default: {
2
+ test: {
3
+ environment: string;
4
+ include: string[];
5
+ };
6
+ };
7
+ export default _default;
@@ -0,0 +1,6 @@
1
+ export default {
2
+ test: {
3
+ environment: 'happy-dom',
4
+ include: ['**/*.spec.ts', '**/*.spec.tsx'],
5
+ },
6
+ };