Skip to content

Commit c2792e5

Browse files
committed
finish tests
1 parent 7b8acd8 commit c2792e5

File tree

1 file changed

+77
-53
lines changed

1 file changed

+77
-53
lines changed
Lines changed: 77 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { expect } from 'chai';
22
import { setupStore } from '../../test/setup-store';
3-
import { applyEdit, openDiagram } from './diagram';
3+
import {
4+
applyEdit,
5+
getCurrentDiagramFromState,
6+
openDiagram,
7+
redoEdit,
8+
undoEdit,
9+
} from './diagram';
410

511
describe('Data Modeling store', function () {
612
let store;
@@ -10,73 +16,55 @@ describe('Data Modeling store', function () {
1016
});
1117

1218
it('openDiagram', function () {
13-
const diagram = {
19+
const loadedDiagram = {
1420
id: 'diagram-id',
1521
name: 'diagram-name',
1622
connectionId: 'connection-id',
1723
edits: [{ type: 'SetModel', model: {} }],
1824
};
1925

20-
store.dispatch(openDiagram(diagram));
26+
store.dispatch(openDiagram(loadedDiagram));
2127

22-
expect(store.getState().diagram.id).to.equal(diagram.id);
23-
expect(store.getState().diagram.name).to.equal(diagram.name);
24-
expect(store.getState().diagram.connectionId).to.equal(
25-
diagram.connectionId
26-
);
27-
expect(store.getState().diagram.edits.current).to.deep.equal(diagram.edits);
28-
});
29-
30-
it('openDiagram', function () {
31-
const diagram = {
32-
id: 'diagram-id',
33-
name: 'diagram-name',
34-
connectionId: 'connection-id',
35-
edits: [{ type: 'SetModel', model: {} }],
36-
};
37-
38-
store.dispatch(openDiagram(diagram));
39-
40-
expect(store.getState().diagram.id).to.equal(diagram.id);
41-
expect(store.getState().diagram.name).to.equal(diagram.name);
42-
expect(store.getState().diagram.connectionId).to.equal(
43-
diagram.connectionId
44-
);
45-
expect(store.getState().diagram.edits.current).to.deep.equal(diagram.edits);
28+
const diagram = getCurrentDiagramFromState(store.getState());
29+
expect(diagram.id).to.equal(loadedDiagram.id);
30+
expect(diagram.name).to.equal(loadedDiagram.name);
31+
expect(diagram.connectionId).to.equal(loadedDiagram.connectionId);
32+
expect(diagram.edits).to.deep.equal(loadedDiagram.edits);
4633
});
4734

4835
describe('applyEdit', function () {
4936
it('should apply a valid SetModel edit', function () {
50-
const diagram = {
37+
const loadedDiagram = {
5138
id: 'diagram-id',
5239
name: 'diagram-name',
5340
connectionId: 'connection-id',
5441
edits: [{ type: 'SetModel', model: {} }],
5542
};
5643

57-
store.dispatch(openDiagram(diagram));
44+
store.dispatch(openDiagram(loadedDiagram));
5845

5946
const newModel = { collections: [], relationships: [] };
6047
store.dispatch(applyEdit({ type: 'SetModel', model: newModel }));
6148

62-
const state = store.getState();
63-
expect(state.diagram.editErrors).to.be.undefined;
64-
expect(state.diagram.edits.current[0]).to.deep.equal(diagram.edits[0]);
65-
expect(state.diagram.edits.current[1]).to.deep.include({
49+
const diagram = getCurrentDiagramFromState(store.getState());
50+
expect(diagram.editErrors).to.be.undefined;
51+
expect(diagram.edits).to.have.length(2);
52+
expect(diagram.edits[0]).to.deep.equal(diagram.edits[0]);
53+
expect(diagram.edits[1]).to.deep.include({
6654
type: 'SetModel',
6755
model: newModel,
6856
});
6957
});
7058

7159
it('should apply a valid AddRelationship edit', function () {
72-
const diagram = {
60+
const loadedDiagram = {
7361
id: 'diagram-id',
7462
name: 'diagram-name',
7563
connectionId: 'connection-id',
7664
edits: [{ type: 'SetModel', model: {} }],
7765
};
7866

79-
store.dispatch(openDiagram(diagram));
67+
store.dispatch(openDiagram(loadedDiagram));
8068

8169
const newRelationship = {
8270
id: 'relationship1',
@@ -98,39 +86,75 @@ describe('Data Modeling store', function () {
9886
applyEdit({ type: 'AddRelationship', relationship: newRelationship })
9987
);
10088

101-
const state = store.getState();
102-
expect(state.diagram.editErrors).to.be.undefined;
103-
expect(state.diagram.edits.current[0]).to.deep.equal(diagram.edits[0]);
104-
expect(state.diagram.edits.current[1]).to.deep.include({
89+
const diagram = getCurrentDiagramFromState(store.getState());
90+
expect(diagram.editErrors).to.be.undefined;
91+
expect(diagram.edits).to.have.length(2);
92+
expect(diagram.edits[0]).to.deep.equal(diagram.edits[0]);
93+
expect(diagram.edits[1]).to.deep.include({
10594
type: 'AddRelationship',
10695
relationship: newRelationship,
10796
});
10897
});
10998

11099
it.only('should not apply invalid AddRelationship edit', function () {
111-
const diagram = {
100+
const loadedDiagram = {
112101
id: 'diagram-id',
113102
name: 'diagram-name',
114103
connectionId: 'connection-id',
115104
edits: [{ type: 'SetModel', model: {} }],
116105
};
117106

118-
store.dispatch(openDiagram(diagram));
107+
store.dispatch(openDiagram(loadedDiagram));
119108

120-
const newRelationship = {
121-
id: 'relationship1',
122-
isInferred: false,
109+
const edit = {
110+
type: 'AddRelationship',
111+
relationship: {
112+
id: 'relationship1',
113+
isInferred: false,
114+
},
123115
};
124-
store.dispatch(
125-
applyEdit({ type: 'AddRelationship', relationship: newRelationship })
126-
);
116+
store.dispatch(applyEdit(edit));
127117

128-
const state = store.getState();
129-
expect(state.diagram.editErrors).to.have.length(1);
130-
expect(state.diagram.editErrors[0]).to.equal(
131-
"'relationship,relationship' is required"
132-
);
133-
expect(state.diagram.edits.current).to.deep.equal(diagram.edits);
118+
const editErrors = store.getState().diagram.editErrors;
119+
expect(editErrors).to.have.length(1);
120+
expect(editErrors[0]).to.equal("'relationship,relationship' is required");
121+
const diagram = getCurrentDiagramFromState(store.getState());
122+
expect(diagram.edits).to.deep.equal(diagram.edits);
134123
});
135124
});
125+
126+
it('undo/redo', function () {
127+
const loadedDiagram = {
128+
id: 'diagram-id',
129+
name: 'diagram-name',
130+
connectionId: 'connection-id',
131+
edits: [{ type: 'SetModel', model: {} }],
132+
};
133+
134+
store.dispatch(openDiagram(loadedDiagram));
135+
136+
const edit = {
137+
type: 'SetModel',
138+
model: { collections: [], relationships: [] },
139+
};
140+
store.dispatch(applyEdit(edit));
141+
142+
const diagramAfterEdit = getCurrentDiagramFromState(store.getState());
143+
expect(diagramAfterEdit.edits).to.have.length(2);
144+
expect(diagramAfterEdit.edits[0]).to.deep.include(loadedDiagram.edits[0]);
145+
expect(diagramAfterEdit.edits[1]).to.deep.include(edit);
146+
147+
store.dispatch(undoEdit());
148+
149+
const diagramAfterUndo = getCurrentDiagramFromState(store.getState());
150+
expect(diagramAfterUndo.edits).to.have.length(1);
151+
expect(diagramAfterUndo.edits[0]).to.deep.include(loadedDiagram.edits[0]);
152+
153+
store.dispatch(redoEdit());
154+
155+
const diagramAfterRedo = getCurrentDiagramFromState(store.getState());
156+
expect(diagramAfterRedo.edits).to.have.length(2);
157+
expect(diagramAfterRedo.edits[0]).to.deep.include(loadedDiagram.edits[0]);
158+
expect(diagramAfterRedo.edits[1]).to.deep.include(edit);
159+
});
136160
});

0 commit comments

Comments
 (0)