|
8 | 8 | redoEdit, |
9 | 9 | undoEdit, |
10 | 10 | selectFieldsForCurrentModel, |
| 11 | + startCreatingCollection, |
| 12 | + addCollection, |
11 | 13 | } from './diagram'; |
12 | 14 | import type { |
13 | 15 | Edit, |
@@ -223,6 +225,58 @@ describe('Data Modeling store', function () { |
223 | 225 | expect(diagram.edits).to.deep.equal(loadedDiagram.edits); |
224 | 226 | }); |
225 | 227 |
|
| 228 | + it('should handle the collection creation flow', function () { |
| 229 | + store.dispatch(openDiagram(loadedDiagram)); |
| 230 | + |
| 231 | + // start creating a new collection |
| 232 | + store.dispatch(startCreatingCollection()); |
| 233 | + |
| 234 | + // the new collection is not yet in the edit history |
| 235 | + const diagramAtCreation = getCurrentDiagramFromState(store.getState()); |
| 236 | + expect(diagramAtCreation.edits).to.deep.equal(loadedDiagram.edits); |
| 237 | + |
| 238 | + // but the selection changes accordingly |
| 239 | + const selectedItems = store.getState().diagram?.selectedItems; |
| 240 | + expect(selectedItems).to.deep.equal({ |
| 241 | + type: 'collection', |
| 242 | + id: undefined, |
| 243 | + }); |
| 244 | + |
| 245 | + // save the new collection |
| 246 | + const newCollectionNs = 'db.newCollection'; |
| 247 | + store.dispatch(addCollection(newCollectionNs)); |
| 248 | + |
| 249 | + // now the collection is added to the edit history |
| 250 | + const diagramAfterCreation = getCurrentDiagramFromState(store.getState()); |
| 251 | + expect(diagramAfterCreation.edits).to.have.length(2); |
| 252 | + expect(diagramAfterCreation.edits[0]).to.deep.equal( |
| 253 | + loadedDiagram.edits[0] |
| 254 | + ); |
| 255 | + const addCollectionEdit = diagramAfterCreation.edits[1] as Extract< |
| 256 | + Edit, |
| 257 | + { type: 'AddCollection' } |
| 258 | + >; |
| 259 | + expect(addCollectionEdit.type).to.equal('AddCollection'); |
| 260 | + expect(addCollectionEdit.ns).to.equal(newCollectionNs); |
| 261 | + expect(addCollectionEdit.initialSchema).to.deep.equal({ |
| 262 | + bsonType: 'object', |
| 263 | + properties: { |
| 264 | + _id: { |
| 265 | + bsonType: 'objectId', |
| 266 | + }, |
| 267 | + }, |
| 268 | + required: ['_id'], |
| 269 | + }); |
| 270 | + |
| 271 | + // and it is selected |
| 272 | + const selectedItemsAfterCreation = |
| 273 | + store.getState().diagram?.selectedItems; |
| 274 | + expect(selectedItemsAfterCreation).to.deep.equal({ |
| 275 | + type: 'collection', |
| 276 | + id: newCollectionNs, |
| 277 | + }); |
| 278 | + }); |
| 279 | + |
226 | 280 | it('should apply a valid MoveCollection edit', function () { |
227 | 281 | store.dispatch(openDiagram(loadedDiagram)); |
228 | 282 |
|
|
0 commit comments