@powerhousedao/academy 5.1.0-dev.9 → 5.1.0
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/CHANGELOG.md +43 -1108
- package/blog/BeyondCommunication-ABlueprintForDevelopment.md +1 -2
- package/blog/TheChallengeOfChange.md +0 -1
- package/docs/academy/00-EthereumArgentinaHackathon.md +207 -0
- package/docs/academy/01-GetStarted/00-ExploreDemoPackage.mdx +27 -24
- package/docs/academy/01-GetStarted/01-CreateNewPowerhouseProject.md +9 -118
- package/docs/academy/01-GetStarted/02-DefineToDoListDocumentModel.md +28 -110
- package/docs/academy/01-GetStarted/03-ImplementOperationReducers.md +145 -191
- package/docs/academy/01-GetStarted/04-BuildToDoListEditor.md +218 -0
- package/docs/academy/{02-MasteryTrack/01-BuilderEnvironment → 01-GetStarted}/05-VetraStudio.md +6 -48
- package/docs/academy/01-GetStarted/06-ReactorMCP.md +58 -0
- package/docs/academy/01-GetStarted/_04-BuildToDoListEditor +1 -1
- package/docs/academy/02-MasteryTrack/01-BuilderEnvironment/03-BuilderTools.md +2 -2
- package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/02-SpecifyTheStateSchema.md +44 -75
- package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/03-SpecifyDocumentOperations.md +22 -28
- package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/04-UseTheDocumentModelGenerator.md +31 -28
- package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/05-ImplementDocumentReducers.md +206 -211
- package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/06-ImplementDocumentModelTests.md +62 -176
- package/docs/academy/02-MasteryTrack/02-DocumentModelCreation/07-ExampleToDoListRepository.md +0 -21
- package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/01-BuildingDocumentEditors.md +319 -309
- package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/00-DocumentToolbar.mdx +0 -4
- package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/01-OperationHistory.md +0 -4
- package/docs/academy/02-MasteryTrack/05-Launch/04-ConfigureEnvironment.md +1 -1
- package/docs/academy/03-ExampleUsecases/Chatroom/02-CreateNewPowerhouseProject.md +35 -111
- package/docs/academy/03-ExampleUsecases/Chatroom/03-DefineChatroomDocumentModel.md +76 -255
- package/docs/academy/03-ExampleUsecases/Chatroom/04-ImplementOperationReducers.md +160 -281
- package/docs/academy/03-ExampleUsecases/Chatroom/05-ImplementChatroomEditor.md +35 -188
- package/docs/academy/03-ExampleUsecases/Chatroom/06-LaunchALocalReactor.md +7 -95
- package/docs/academy/03-ExampleUsecases/Chatroom/_category_.json +1 -1
- package/docs/academy/04-APIReferences/00-PowerhouseCLI.md +2 -6
- package/docs/academy/04-APIReferences/01-ReactHooks.md +501 -291
- package/docs/academy/05-Architecture/00-PowerhouseArchitecture.md +39 -7
- package/docs/academy/05-Architecture/02-ReferencingMonorepoPackages +65 -0
- package/docs/academy/05-Architecture/04-MovingBeyondCRUD +61 -0
- package/docs/academy/06-ComponentLibrary/00-DocumentEngineering.md +24 -72
- package/docs/academy/08-Glossary.md +0 -7
- package/docusaurus.config.ts +3 -28
- package/package.json +1 -1
- package/sidebars.ts +12 -49
- package/src/css/custom.css +18 -26
- package/docs/academy/01-GetStarted/04-WriteDocumentModelTests.md +0 -378
- package/docs/academy/01-GetStarted/05-BuildToDoListEditor.md +0 -560
- package/docs/academy/03-ExampleUsecases/TodoList/00-GetTheStarterCode.md +0 -24
- package/docs/academy/03-ExampleUsecases/TodoList/01-GenerateTodoListDocumentModel.md +0 -211
- package/docs/academy/03-ExampleUsecases/TodoList/02-ImplementTodoListDocumentModelReducerOperationHandlers.md +0 -171
- package/docs/academy/03-ExampleUsecases/TodoList/03-AddTestsForTodoListActions.md +0 -462
- package/docs/academy/03-ExampleUsecases/TodoList/04-GenerateTodoListDocumentEditor.md +0 -45
- package/docs/academy/03-ExampleUsecases/TodoList/05-ImplementTodoListDocumentEditorUIComponents.md +0 -422
- package/docs/academy/03-ExampleUsecases/TodoList/06-GenerateTodoDriveExplorer.md +0 -61
- package/docs/academy/03-ExampleUsecases/TodoList/07-AddSharedComponentForShowingTodoListStats.md +0 -384
- package/docs/academy/03-ExampleUsecases/TodoList/_category_.json +0 -8
- package/docs/academy/03-ExampleUsecases/VetraPackageLibrary/VetraPackageLibrary.md +0 -7
- package/docs/academy/03-ExampleUsecases/VetraPackageLibrary/_category_.json +0 -9
- package/docs/academy/04-APIReferences/06-VetraRemoteDrive.md +0 -160
- package/docs/academy/04-APIReferences/renown-sdk/00-Overview.md +0 -316
- package/docs/academy/04-APIReferences/renown-sdk/01-Authentication.md +0 -672
- package/docs/academy/04-APIReferences/renown-sdk/02-APIReference.md +0 -957
- package/docs/academy/04-APIReferences/renown-sdk/_category_.json +0 -8
- package/docs/academy/10-TodoListTutorial/02-ImplementTodoListDocumentModelReducerOperationHandlers.md +0 -171
- package/docs/academy/10-TodoListTutorial/03-AddTestsForTodoListActions.md +0 -462
- package/docs/academy/10-TodoListTutorial/05-ImplementTodoListDocumentEditorUIComponents.md +0 -422
- package/docs/academy/10-TodoListTutorial/07-AddSharedComponentForShowingTodoListStats.md +0 -370
- package/static/img/Vetra-logo-dark.svg +0 -11
- package/static/img/vetra-logo-light.svg +0 -11
- /package/docs/academy/{02-MasteryTrack/01-BuilderEnvironment → 01-GetStarted}/images/Modules.png +0 -0
- /package/docs/academy/{02-MasteryTrack/01-BuilderEnvironment → 01-GetStarted}/images/VetraStudioDrive.png +0 -0
- /package/docs/academy/02-MasteryTrack/03-BuildingUserExperiences/06-DocumentTools/{02-RevisionHistoryTimeline/360/237/232/247" → 02-RevisionHistoryTimeline} +0 -0
- /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /01-WhatIsADocumentModel" → 01-WhatIsADocumentModel} +0 -0
- /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /02-DAOandDocumentsModelsQ+A" → 02-DAOandDocumentsModelsQ+A} +0 -0
- /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /02-domain-modeling" → 02-domain-modeling} +0 -0
- /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /03-BenefitsOfDocumentModels" → 03-BenefitsOfDocumentModels} +0 -0
- /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /04-UtilitiesAndTips" → 04-UtilitiesAndTips} +0 -0
- /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /05-best-practices" → 05-best-practices} +0 -0
- /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /_category_.json" → _category_.json} +0 -0
- /package/docs/academy/05-Architecture/05-DocumentModelTheory/{360/237/232/247 /three-data-layers.png" → three-data-layers.png} +0 -0
|
@@ -1,378 +0,0 @@
|
|
|
1
|
-
# Write document model tests
|
|
2
|
-
|
|
3
|
-
:::tip Tutorial Repository
|
|
4
|
-
📦 **Reference Code**: [step-4-implement-tests-for-todos-operations](https://github.com/powerhouse-inc/todo-tutorial/tree/step-4-implement-tests-for-todos-operations)
|
|
5
|
-
|
|
6
|
-
This step focuses on writing comprehensive tests for the reducers you implemented in the previous step.
|
|
7
|
-
:::
|
|
8
|
-
|
|
9
|
-
<details>
|
|
10
|
-
<summary>📖 How to use this tutorial</summary>
|
|
11
|
-
|
|
12
|
-
### Compare your tests
|
|
13
|
-
|
|
14
|
-
After writing tests:
|
|
15
|
-
|
|
16
|
-
```bash
|
|
17
|
-
# Compare your tests with the reference
|
|
18
|
-
git diff tutorial/step-4-implement-tests-for-todos-operations -- document-models/todo-list/src/tests/
|
|
19
|
-
|
|
20
|
-
# View the reference test implementation
|
|
21
|
-
git show tutorial/step-4-implement-tests-for-todos-operations:document-models/todo-list/src/tests/todos.test.ts
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
### Visual comparison with GitHub Desktop
|
|
25
|
-
|
|
26
|
-
After committing your work, compare visually:
|
|
27
|
-
1. **Branch** menu → **"Compare to Branch..."**
|
|
28
|
-
2. Select `tutorial/step-4-implement-tests-for-todos-operations`
|
|
29
|
-
3. Review differences in the visual interface
|
|
30
|
-
|
|
31
|
-
</details>
|
|
32
|
-
|
|
33
|
-
In order to make sure the operation reducers are working as expected, you need to write tests for them. When you generated your document model code, we created some boilerplate tests for you. Now we'll enhance them to properly verify our reducer logic.
|
|
34
|
-
|
|
35
|
-
## Understanding the generated test file
|
|
36
|
-
|
|
37
|
-
Navigate to `/document-models/todo-list/src/tests/todos.test.ts`. You will see that we have some basic "sanity check" style tests already. These make sure that your operations at least result in a valid document model state.
|
|
38
|
-
|
|
39
|
-
```typescript
|
|
40
|
-
import { describe, it, expect } from "vitest";
|
|
41
|
-
import { generateMock } from "@powerhousedao/codegen";
|
|
42
|
-
import {
|
|
43
|
-
reducer,
|
|
44
|
-
utils,
|
|
45
|
-
isTodoListDocument,
|
|
46
|
-
addTodoItem,
|
|
47
|
-
AddTodoItemInputSchema,
|
|
48
|
-
updateTodoItem,
|
|
49
|
-
UpdateTodoItemInputSchema,
|
|
50
|
-
deleteTodoItem,
|
|
51
|
-
DeleteTodoItemInputSchema,
|
|
52
|
-
} from "todo-tutorial/document-models/todo-list";
|
|
53
|
-
|
|
54
|
-
describe("Todos Operations", () => {
|
|
55
|
-
it("should handle addTodoItem operation", () => {
|
|
56
|
-
// the `createDocument` utility function creates a new empty document
|
|
57
|
-
const document = utils.createDocument();
|
|
58
|
-
|
|
59
|
-
// generateMock creates an object with random values for each field
|
|
60
|
-
const input = generateMock(AddTodoItemInputSchema());
|
|
61
|
-
|
|
62
|
-
// call the reducer with the document and action
|
|
63
|
-
const updatedDocument = reducer(document, addTodoItem(input));
|
|
64
|
-
|
|
65
|
-
// validate the document conforms to the schema
|
|
66
|
-
expect(isTodoListDocument(updatedDocument)).toBe(true);
|
|
67
|
-
|
|
68
|
-
// check the operation was recorded
|
|
69
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
70
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("ADD_TODO_ITEM");
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it("should handle updateTodoItem operation", () => {
|
|
74
|
-
// ... boilerplate test
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("should handle deleteTodoItem operation", () => {
|
|
78
|
-
// ... boilerplate test
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## Enhance the tests
|
|
84
|
-
|
|
85
|
-
The boilerplate tests check that operations are applied, but they don't verify the **actual results**. Let's write more comprehensive tests.
|
|
86
|
-
|
|
87
|
-
### Test 1: Update the addTodoItem test
|
|
88
|
-
|
|
89
|
-
The add test is already fairly complete. We just need to add type annotations:
|
|
90
|
-
|
|
91
|
-
```typescript
|
|
92
|
-
it("should handle addTodoItem operation", () => {
|
|
93
|
-
const document = utils.createDocument();
|
|
94
|
-
// added-line
|
|
95
|
-
const input: AddTodoItemInput = generateMock(AddTodoItemInputSchema());
|
|
96
|
-
|
|
97
|
-
const updatedDocument = reducer(document, addTodoItem(input));
|
|
98
|
-
expect(isTodoListDocument(updatedDocument)).toBe(true);
|
|
99
|
-
|
|
100
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
101
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("ADD_TODO_ITEM");
|
|
102
|
-
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
103
|
-
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
104
|
-
});
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### Test 2: Replace the updateTodoItem test
|
|
108
|
-
|
|
109
|
-
Delete the existing boilerplate and add two separate tests - one for updating text, one for updating the checked state:
|
|
110
|
-
|
|
111
|
-
```typescript
|
|
112
|
-
// removed-start
|
|
113
|
-
it("should handle updateTodoItem operation", () => {
|
|
114
|
-
const document = utils.createDocument();
|
|
115
|
-
const input = generateMock(UpdateTodoItemInputSchema());
|
|
116
|
-
const updatedDocument = reducer(document, updateTodoItem(input));
|
|
117
|
-
expect(isTodoListDocument(updatedDocument)).toBe(true);
|
|
118
|
-
// ...
|
|
119
|
-
});
|
|
120
|
-
// removed-end
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
**Add the new test for updating text:**
|
|
124
|
-
|
|
125
|
-
```typescript
|
|
126
|
-
it("should handle updateTodoItem operation to update text", () => {
|
|
127
|
-
// Create an existing item to update
|
|
128
|
-
const mockItem = generateMock(TodoItemSchema());
|
|
129
|
-
const input: UpdateTodoItemInput = generateMock(UpdateTodoItemInputSchema());
|
|
130
|
-
|
|
131
|
-
// Set the input ID to match our existing item
|
|
132
|
-
input.id = mockItem.id;
|
|
133
|
-
const newText = "new text";
|
|
134
|
-
input.text = newText;
|
|
135
|
-
input.checked = undefined; // Don't change checked state
|
|
136
|
-
|
|
137
|
-
// Create document with existing item
|
|
138
|
-
const document = utils.createDocument({
|
|
139
|
-
global: {
|
|
140
|
-
items: [mockItem],
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
const updatedDocument = reducer(document, updateTodoItem(input));
|
|
145
|
-
expect(isTodoListDocument(updatedDocument)).toBe(true);
|
|
146
|
-
|
|
147
|
-
// Verify operation was recorded
|
|
148
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
149
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("UPDATE_TODO_ITEM");
|
|
150
|
-
|
|
151
|
-
// Verify state was updated correctly
|
|
152
|
-
const updatedItem = updatedDocument.state.global.items.find(
|
|
153
|
-
(item) => item.id === input.id,
|
|
154
|
-
);
|
|
155
|
-
expect(updatedItem?.text).toBe(newText);
|
|
156
|
-
expect(updatedItem?.checked).toBe(mockItem.checked); // Unchanged
|
|
157
|
-
});
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
**Add the new test for updating checked state:**
|
|
161
|
-
|
|
162
|
-
```typescript
|
|
163
|
-
it("should handle updateTodoItem operation to update checked", () => {
|
|
164
|
-
const mockItem = generateMock(TodoItemSchema());
|
|
165
|
-
const input: UpdateTodoItemInput = generateMock(UpdateTodoItemInputSchema());
|
|
166
|
-
|
|
167
|
-
input.id = mockItem.id;
|
|
168
|
-
const newChecked = !mockItem.checked; // Toggle the checked state
|
|
169
|
-
input.checked = newChecked;
|
|
170
|
-
input.text = undefined; // Don't change text
|
|
171
|
-
|
|
172
|
-
const document = utils.createDocument({
|
|
173
|
-
global: {
|
|
174
|
-
items: [mockItem],
|
|
175
|
-
},
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
const updatedDocument = reducer(document, updateTodoItem(input));
|
|
179
|
-
expect(isTodoListDocument(updatedDocument)).toBe(true);
|
|
180
|
-
|
|
181
|
-
const updatedItem = updatedDocument.state.global.items.find(
|
|
182
|
-
(item) => item.id === input.id,
|
|
183
|
-
);
|
|
184
|
-
expect(updatedItem?.text).toBe(mockItem.text); // Unchanged
|
|
185
|
-
expect(updatedItem?.checked).toBe(newChecked);
|
|
186
|
-
});
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
### Test 3: Update the deleteTodoItem test
|
|
190
|
-
|
|
191
|
-
The boilerplate delete test passes even without an existing item to delete. Let's fix that:
|
|
192
|
-
|
|
193
|
-
```typescript
|
|
194
|
-
it("should handle deleteTodoItem operation", () => {
|
|
195
|
-
// removed-start
|
|
196
|
-
const document = utils.createDocument();
|
|
197
|
-
const input = generateMock(DeleteTodoItemInputSchema());
|
|
198
|
-
// removed-end
|
|
199
|
-
// added-start
|
|
200
|
-
// Create an existing item to delete
|
|
201
|
-
const mockItem = generateMock(TodoItemSchema());
|
|
202
|
-
const document = utils.createDocument({
|
|
203
|
-
global: {
|
|
204
|
-
items: [mockItem],
|
|
205
|
-
},
|
|
206
|
-
});
|
|
207
|
-
const input: DeleteTodoItemInput = generateMock(DeleteTodoItemInputSchema());
|
|
208
|
-
input.id = mockItem.id;
|
|
209
|
-
// added-end
|
|
210
|
-
|
|
211
|
-
const updatedDocument = reducer(document, deleteTodoItem(input));
|
|
212
|
-
expect(isTodoListDocument(updatedDocument)).toBe(true);
|
|
213
|
-
|
|
214
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
215
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("DELETE_TODO_ITEM");
|
|
216
|
-
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
217
|
-
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
218
|
-
|
|
219
|
-
// added-start
|
|
220
|
-
// Verify the item was actually removed
|
|
221
|
-
const updatedItems = updatedDocument.state.global.items;
|
|
222
|
-
expect(updatedItems).toHaveLength(0);
|
|
223
|
-
// added-end
|
|
224
|
-
});
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
## Complete test file
|
|
228
|
-
|
|
229
|
-
Here's the complete test file with all updates. Don't forget to add the missing imports:
|
|
230
|
-
|
|
231
|
-
<details>
|
|
232
|
-
<summary>Complete todos.test.ts</summary>
|
|
233
|
-
|
|
234
|
-
```typescript
|
|
235
|
-
import { describe, it, expect } from "vitest";
|
|
236
|
-
import { generateMock } from "@powerhousedao/codegen";
|
|
237
|
-
import type {
|
|
238
|
-
AddTodoItemInput,
|
|
239
|
-
DeleteTodoItemInput,
|
|
240
|
-
UpdateTodoItemInput,
|
|
241
|
-
} from "todo-tutorial/document-models/todo-list";
|
|
242
|
-
import {
|
|
243
|
-
reducer,
|
|
244
|
-
utils,
|
|
245
|
-
isTodoListDocument,
|
|
246
|
-
addTodoItem,
|
|
247
|
-
AddTodoItemInputSchema,
|
|
248
|
-
updateTodoItem,
|
|
249
|
-
UpdateTodoItemInputSchema,
|
|
250
|
-
deleteTodoItem,
|
|
251
|
-
DeleteTodoItemInputSchema,
|
|
252
|
-
TodoItemSchema,
|
|
253
|
-
} from "todo-tutorial/document-models/todo-list";
|
|
254
|
-
|
|
255
|
-
describe("Todos Operations", () => {
|
|
256
|
-
it("should handle addTodoItem operation", () => {
|
|
257
|
-
const document = utils.createDocument();
|
|
258
|
-
const input: AddTodoItemInput = generateMock(AddTodoItemInputSchema());
|
|
259
|
-
|
|
260
|
-
const updatedDocument = reducer(document, addTodoItem(input));
|
|
261
|
-
expect(isTodoListDocument(updatedDocument)).toBe(true);
|
|
262
|
-
|
|
263
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
264
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("ADD_TODO_ITEM");
|
|
265
|
-
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
266
|
-
expect(updatedDocument.operations.global[0].index).toEqual(0);
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
it("should handle updateTodoItem operation to update text", () => {
|
|
270
|
-
const mockItem = generateMock(TodoItemSchema());
|
|
271
|
-
const input: UpdateTodoItemInput = generateMock(UpdateTodoItemInputSchema());
|
|
272
|
-
input.id = mockItem.id;
|
|
273
|
-
const newText = "new text";
|
|
274
|
-
input.text = newText;
|
|
275
|
-
input.checked = undefined;
|
|
276
|
-
|
|
277
|
-
const document = utils.createDocument({
|
|
278
|
-
global: {
|
|
279
|
-
items: [mockItem],
|
|
280
|
-
},
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
const updatedDocument = reducer(document, updateTodoItem(input));
|
|
284
|
-
expect(isTodoListDocument(updatedDocument)).toBe(true);
|
|
285
|
-
|
|
286
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
287
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("UPDATE_TODO_ITEM");
|
|
288
|
-
|
|
289
|
-
const updatedItem = updatedDocument.state.global.items.find(
|
|
290
|
-
(item) => item.id === input.id,
|
|
291
|
-
);
|
|
292
|
-
expect(updatedItem?.text).toBe(newText);
|
|
293
|
-
expect(updatedItem?.checked).toBe(mockItem.checked);
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
it("should handle updateTodoItem operation to update checked", () => {
|
|
297
|
-
const mockItem = generateMock(TodoItemSchema());
|
|
298
|
-
const input: UpdateTodoItemInput = generateMock(UpdateTodoItemInputSchema());
|
|
299
|
-
input.id = mockItem.id;
|
|
300
|
-
const newChecked = !mockItem.checked;
|
|
301
|
-
input.checked = newChecked;
|
|
302
|
-
input.text = undefined;
|
|
303
|
-
|
|
304
|
-
const document = utils.createDocument({
|
|
305
|
-
global: {
|
|
306
|
-
items: [mockItem],
|
|
307
|
-
},
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
const updatedDocument = reducer(document, updateTodoItem(input));
|
|
311
|
-
expect(isTodoListDocument(updatedDocument)).toBe(true);
|
|
312
|
-
|
|
313
|
-
const updatedItem = updatedDocument.state.global.items.find(
|
|
314
|
-
(item) => item.id === input.id,
|
|
315
|
-
);
|
|
316
|
-
expect(updatedItem?.text).toBe(mockItem.text);
|
|
317
|
-
expect(updatedItem?.checked).toBe(newChecked);
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
it("should handle deleteTodoItem operation", () => {
|
|
321
|
-
const mockItem = generateMock(TodoItemSchema());
|
|
322
|
-
const document = utils.createDocument({
|
|
323
|
-
global: {
|
|
324
|
-
items: [mockItem],
|
|
325
|
-
},
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
const input: DeleteTodoItemInput = generateMock(DeleteTodoItemInputSchema());
|
|
329
|
-
input.id = mockItem.id;
|
|
330
|
-
|
|
331
|
-
const updatedDocument = reducer(document, deleteTodoItem(input));
|
|
332
|
-
expect(isTodoListDocument(updatedDocument)).toBe(true);
|
|
333
|
-
|
|
334
|
-
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
335
|
-
expect(updatedDocument.operations.global[0].action.type).toBe("DELETE_TODO_ITEM");
|
|
336
|
-
|
|
337
|
-
const updatedItems = updatedDocument.state.global.items;
|
|
338
|
-
expect(updatedItems).toHaveLength(0);
|
|
339
|
-
});
|
|
340
|
-
});
|
|
341
|
-
```
|
|
342
|
-
|
|
343
|
-
</details>
|
|
344
|
-
|
|
345
|
-
:::tip Check your work
|
|
346
|
-
|
|
347
|
-
To make sure everything works as expected:
|
|
348
|
-
|
|
349
|
-
```bash
|
|
350
|
-
# Check types compile correctly
|
|
351
|
-
pnpm tsc
|
|
352
|
-
|
|
353
|
-
# Check linting passes
|
|
354
|
-
pnpm lint
|
|
355
|
-
|
|
356
|
-
# Run tests
|
|
357
|
-
pnpm test
|
|
358
|
-
|
|
359
|
-
# Compare with reference implementation
|
|
360
|
-
git diff tutorial/step-4-implement-tests-for-todos-operations -- document-models/todo-list/src/tests/
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
Expected test output:
|
|
364
|
-
|
|
365
|
-
```bash
|
|
366
|
-
✓ document-models/todo-list/src/tests/document-model.test.ts (3 tests) 1ms
|
|
367
|
-
✓ document-models/todo-list/src/tests/todos.test.ts (4 tests) 8ms
|
|
368
|
-
|
|
369
|
-
Test Files 2 passed (2)
|
|
370
|
-
Tests 7 passed (7)
|
|
371
|
-
```
|
|
372
|
-
|
|
373
|
-
:::
|
|
374
|
-
|
|
375
|
-
## Up next: Building the editor
|
|
376
|
-
|
|
377
|
-
In the next chapter, you'll learn how to implement a user interface (editor) for your document model so you can interact with it visually in Connect Studio.
|
|
378
|
-
|