Skip to content

Commit b8a5705

Browse files
committed
update tests
1 parent db5de48 commit b8a5705

File tree

3 files changed

+118
-56
lines changed

3 files changed

+118
-56
lines changed

packages/compass-data-modeling/src/components/drawer/diagram-editor-side-panel.spec.tsx

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import {
1010
import { DataModelingWorkspaceTab } from '../../index';
1111
import DiagramEditorSidePanel from './diagram-editor-side-panel';
1212
import {
13+
addCollection,
1314
openDiagram,
1415
selectCollection,
1516
selectCurrentModelFromState,
1617
selectRelationship,
17-
startCreatingCollection,
1818
} from '../../store/diagram';
1919
import dataModel from '../../../test/fixtures/data-model-with-relationships.json';
2020
import type {
@@ -338,7 +338,7 @@ describe('DiagramEditorSidePanel', function () {
338338

339339
it('should handle new collection creation', async function () {
340340
const result = renderDrawer();
341-
result.plugin.store.dispatch(startCreatingCollection());
341+
result.plugin.store.dispatch(addCollection());
342342

343343
await waitForDrawerToOpen();
344344

@@ -349,19 +349,11 @@ describe('DiagramEditorSidePanel', function () {
349349
const activeElement = document.activeElement;
350350
expect(activeElement).to.equal(nameInput);
351351

352-
// The other controls are not usable in this state
353-
expect(screen.getByRole('textbox', { name: 'Notes' })).to.have.attribute(
354-
'aria-disabled',
355-
'true'
356-
);
357-
expect(screen.queryByRole('button', { name: 'Delete Collection' })).not.to
358-
.exist;
359-
360352
// Update the name.
361353
userEvent.clear(nameInput);
362354
userEvent.type(nameInput, 'pineapple');
363355

364-
// Blur/unfocus the input - now the collection should be created
356+
// Blur/unfocus the input - now the collection should be names
365357
userEvent.click(document.body);
366358

367359
// Check the name in the model.
@@ -372,17 +364,8 @@ describe('DiagramEditorSidePanel', function () {
372364
});
373365
expect(newCollection).to.exist;
374366

375-
// The name appears and controls are enabled
367+
// See the name in the input
376368
expect(screen.getByText('flights.pineapple')).to.be.visible;
377-
expect(screen.getByRole('textbox', { name: 'Notes' })).to.have.attribute(
378-
'aria-disabled',
379-
'false'
380-
);
381-
expect(screen.getByRole('button', { name: 'Delete Collection' })).to.be
382-
.visible;
383-
expect(
384-
screen.getByRole('button', { name: 'Delete Collection' })
385-
).to.have.attribute('aria-disabled', 'false');
386369
});
387370

388371
it('should prevent editing to an empty collection name', async function () {

packages/compass-data-modeling/src/store/diagram.spec.ts

Lines changed: 107 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
redoEdit,
99
undoEdit,
1010
selectFieldsForCurrentModel,
11-
startCreatingCollection,
1211
addCollection,
12+
nameDraftCollection,
1313
} from './diagram';
1414
import type {
1515
Edit,
@@ -21,14 +21,14 @@ import { UUID } from 'bson';
2121
const model: StaticModel = {
2222
collections: [
2323
{
24-
ns: 'collection1',
24+
ns: 'db.collection1',
2525
indexes: [],
2626
displayPosition: [0, 0],
2727
shardKey: {},
2828
jsonSchema: { bsonType: 'object' },
2929
},
3030
{
31-
ns: 'collection2',
31+
ns: 'db.collection2',
3232
indexes: [],
3333
displayPosition: [1, 1],
3434
shardKey: {},
@@ -79,12 +79,12 @@ describe('Data Modeling store', function () {
7979
connectionId: 'connection-id',
8080
collections: [
8181
{
82-
ns: 'collection1',
82+
ns: 'db.collection1',
8383
schema: model.collections[0].jsonSchema,
8484
position: { x: 0, y: 0 },
8585
},
8686
{
87-
ns: 'collection2',
87+
ns: 'db.collection2',
8888
schema: model.collections[1].jsonSchema,
8989
position: { x: 0, y: 0 },
9090
},
@@ -142,7 +142,7 @@ describe('Data Modeling store', function () {
142142
model: {
143143
collections: [
144144
{
145-
ns: 'collection2',
145+
ns: 'db.collection2',
146146
indexes: [],
147147
displayPosition: [0, 0],
148148
shardKey: {},
@@ -229,22 +229,38 @@ describe('Data Modeling store', function () {
229229
store.dispatch(openDiagram(loadedDiagram));
230230

231231
// start creating a new collection
232-
store.dispatch(startCreatingCollection());
232+
store.dispatch(addCollection());
233233

234-
// the new collection is not yet in the edit history
234+
// the new collection is in the diagram
235235
const diagramAtCreation = getCurrentDiagramFromState(store.getState());
236-
expect(diagramAtCreation.edits).to.deep.equal(loadedDiagram.edits);
236+
expect(diagramAtCreation.edits).to.have.length(2);
237+
const firstAddCollectionEdit = diagramAtCreation.edits[1] as Extract<
238+
Edit,
239+
{ type: 'AddCollection' }
240+
>;
241+
const firstCollectionDraftName = 'db.new-collection';
242+
expect(firstAddCollectionEdit.type).to.equal('AddCollection');
243+
expect(firstAddCollectionEdit.ns).to.equal(firstCollectionDraftName);
244+
expect(firstAddCollectionEdit.initialSchema).to.deep.equal({
245+
bsonType: 'object',
246+
properties: {
247+
_id: {
248+
bsonType: 'objectId',
249+
},
250+
},
251+
required: ['_id'],
252+
});
237253

238-
// but the selection changes accordingly
254+
// the selection changes to the new collection
239255
const selectedItems = store.getState().diagram?.selectedItems;
240256
expect(selectedItems).to.deep.equal({
241257
type: 'collection',
242-
id: undefined,
258+
id: firstCollectionDraftName,
243259
});
244260

245-
// save the new collection
246-
const newCollectionNs = 'db.newCollection';
247-
store.dispatch(addCollection(newCollectionNs));
261+
// name the new collection
262+
const newCollectionNs = 'db.myCollection';
263+
store.dispatch(nameDraftCollection(newCollectionNs));
248264

249265
// now the collection is added to the edit history
250266
const diagramAfterCreation = getCurrentDiagramFromState(store.getState());
@@ -277,6 +293,48 @@ describe('Data Modeling store', function () {
277293
});
278294
});
279295

296+
it('should iterate the names for new collections', function () {
297+
store.dispatch(openDiagram(loadedDiagram));
298+
299+
// start creating a new collection
300+
store.dispatch(addCollection());
301+
302+
// creates the first collection and makes it selected
303+
const firstCollectionDraftName = 'db.new-collection';
304+
const diagram1 = getCurrentDiagramFromState(store.getState());
305+
expect(diagram1.edits).to.have.length(2);
306+
const firstAddCollectionEdit = diagram1.edits[1] as Extract<
307+
Edit,
308+
{ type: 'AddCollection' }
309+
>;
310+
expect(firstAddCollectionEdit.type).to.equal('AddCollection');
311+
expect(firstAddCollectionEdit.ns).to.equal(firstCollectionDraftName);
312+
const selectedItems1 = store.getState().diagram?.selectedItems;
313+
expect(selectedItems1).to.deep.equal({
314+
type: 'collection',
315+
id: firstCollectionDraftName,
316+
});
317+
318+
// start creating another new collection
319+
store.dispatch(addCollection());
320+
321+
// creates the second collection and makes it selected
322+
const secondCollectionDraftName = 'db.new-collection-1';
323+
const diagramAtCreation = getCurrentDiagramFromState(store.getState());
324+
expect(diagramAtCreation.edits).to.have.length(3);
325+
const secondAddCollectionEdit = diagramAtCreation.edits[2] as Extract<
326+
Edit,
327+
{ type: 'AddCollection' }
328+
>;
329+
expect(secondAddCollectionEdit.type).to.equal('AddCollection');
330+
expect(secondAddCollectionEdit.ns).to.equal(secondCollectionDraftName);
331+
const selectedItems2 = store.getState().diagram?.selectedItems;
332+
expect(selectedItems2).to.deep.equal({
333+
type: 'collection',
334+
id: secondCollectionDraftName,
335+
});
336+
});
337+
280338
it('should apply a valid MoveCollection edit', function () {
281339
store.dispatch(openDiagram(loadedDiagram));
282340

@@ -361,7 +419,7 @@ describe('Data Modeling store', function () {
361419
model: {
362420
collections: [
363421
{
364-
ns: 'collection1',
422+
ns: 'db.collection1',
365423
indexes: [],
366424
displayPosition: [0, 0],
367425
shardKey: {},
@@ -382,7 +440,7 @@ describe('Data Modeling store', function () {
382440
const selectedFields = selectFieldsForCurrentModel(edits);
383441

384442
expect(selectedFields).to.deep.equal({
385-
collection1: [['field1'], ['field2'], ['field3']],
443+
'db.collection1': [['field1'], ['field2'], ['field3']],
386444
});
387445
});
388446

@@ -395,7 +453,7 @@ describe('Data Modeling store', function () {
395453
model: {
396454
collections: [
397455
{
398-
ns: 'collection1',
456+
ns: 'db.collection1',
399457
indexes: [],
400458
displayPosition: [0, 0],
401459
shardKey: {},
@@ -471,29 +529,46 @@ describe('Data Modeling store', function () {
471529
},
472530
];
473531
const selectedFields = selectFieldsForCurrentModel(edits);
474-
475-
expect(selectedFields).to.have.property('collection1');
476-
expect(selectedFields.collection1).to.deep.include(['prop1']);
477-
expect(selectedFields.collection1).to.deep.include(['prop2']);
478-
expect(selectedFields.collection1).to.deep.include(['prop2', 'prop2A']);
479-
expect(selectedFields.collection1).to.deep.include([
532+
expect(selectedFields).to.have.property('db.collection1');
533+
expect(selectedFields['db.collection1']).to.deep.include(['prop1']);
534+
expect(selectedFields['db.collection1']).to.deep.include(['prop2']);
535+
expect(selectedFields['db.collection1']).to.deep.include([
536+
'prop2',
537+
'prop2A',
538+
]);
539+
expect(selectedFields['db.collection1']).to.deep.include([
480540
'prop2',
481541
'prop2B',
482542
'prop2B1',
483543
]);
484-
expect(selectedFields.collection1).to.deep.include([
544+
expect(selectedFields['db.collection1']).to.deep.include([
485545
'prop2',
486546
'prop2B',
487547
'prop2B2',
488548
]);
489-
expect(selectedFields.collection1).to.deep.include(['prop3']);
490-
expect(selectedFields.collection1).to.deep.include(['prop3', 'prop3A']);
491-
expect(selectedFields.collection1).to.deep.include(['prop4']);
492-
expect(selectedFields.collection1).to.deep.include(['prop4', 'prop4A']);
493-
expect(selectedFields.collection1).to.deep.include(['prop4', 'prop4B']);
494-
expect(selectedFields.collection1).to.deep.include(['prop5']);
495-
expect(selectedFields.collection1).to.deep.include(['prop5', 'prop5A']);
496-
expect(selectedFields.collection1).to.deep.include(['prop5', 'prop5B']);
549+
expect(selectedFields['db.collection1']).to.deep.include(['prop3']);
550+
expect(selectedFields['db.collection1']).to.deep.include([
551+
'prop3',
552+
'prop3A',
553+
]);
554+
expect(selectedFields['db.collection1']).to.deep.include(['prop4']);
555+
expect(selectedFields['db.collection1']).to.deep.include([
556+
'prop4',
557+
'prop4A',
558+
]);
559+
expect(selectedFields['db.collection1']).to.deep.include([
560+
'prop4',
561+
'prop4B',
562+
]);
563+
expect(selectedFields['db.collection1']).to.deep.include(['prop5']);
564+
expect(selectedFields['db.collection1']).to.deep.include([
565+
'prop5',
566+
'prop5A',
567+
]);
568+
expect(selectedFields['db.collection1']).to.deep.include([
569+
'prop5',
570+
'prop5B',
571+
]);
497572
});
498573
});
499574
});

packages/compass-e2e-tests/tests/data-modeling-tab.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,10 @@ describe('Data Modeling tab', function () {
748748
// Click on the add collection button.
749749
await browser.clickVisible(Selectors.DataModelAddCollectionBtn);
750750

751+
// Verify that the new collection is added to the diagram.
752+
const nodes = await getDiagramNodes(browser, 3);
753+
expect(nodes[2].id).to.equal('test.new-collection');
754+
751755
// Verify that the drawer is opened.
752756
const drawer = browser.$(Selectors.SideDrawer);
753757
await drawer.waitForDisplayed();
@@ -760,9 +764,9 @@ describe('Data Modeling tab', function () {
760764
);
761765
await drawer.click(); // Unfocus the input.
762766

763-
// Verify that the new collection is added to the diagram.
764-
const nodes = await getDiagramNodes(browser, 3);
765-
expect(nodes[2].id).to.equal('test.testCollection-newOne');
767+
// Verify that the new collection is named in the diagram.
768+
const nodesAfterNaming = await getDiagramNodes(browser, 3);
769+
expect(nodesAfterNaming[2].id).to.equal(`test.${collectionName}`);
766770

767771
// Undo once - verify that the collection is removed
768772
// This is to ensure that the initial edit of the collection name wasn't a separate edit

0 commit comments

Comments
 (0)