Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
loreanvictor committed Nov 20, 2023
1 parent 8448377 commit c1eac47
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/tests/unit/apollon-editor-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,47 @@ describe('test apollon editor ', () => {
}, 500);
}, 500);
});

it('remoteSelection.', () => {
const state = ModelState.fromModel(testClassDiagram as any);
const elements = Object.keys(state.elements!).map((id) => state.elements![id]);
const store = getRealStore(state, elements);
// inject store
Object.defineProperty(editor, 'store', { value: store });

const elA = 'c10b995a-036c-4e9e-aa67-0570ada5cb6a';
const elB = '4d3509e-0dce-458b-bf62-f3555497a5a4';
const john = { name: 'john', color: 'red' };
const jane = { name: 'jane', color: 'blue' };

act(() => {
editor.remoteSelect(john.name, john.color, [elA]);
});

expect(store.getState().remoteSelection[elA]).toEqual([john]);

act(() => {
editor.remoteSelect(jane.name, jane.color, [elA, elB]);
});

expect(store.getState().remoteSelection[elA]).toEqual([john, jane]);
expect(store.getState().remoteSelection[elB]).toEqual([jane]);

act(() => {
editor.remoteSelect(john.name, john.color, [elB], [elA]);
});

expect(store.getState().remoteSelection[elA]).toEqual([jane]);
expect(store.getState().remoteSelection[elB]).toEqual([jane, john]);

act(() => {
editor.pruneRemoteSelectors([john]);
});

expect(store.getState().remoteSelection[elA]).toEqual([]);
expect(store.getState().remoteSelection[elB]).toEqual([john]);
});

it('set type to UseCaseDiagram', () => {
act(() => {
editor.type = UMLDiagramType.UseCaseDiagram;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { getRealStore } from '../../../test-utils/test-utils';
import { UMLClass } from '../../../../../main/packages/uml-class-diagram/uml-class/uml-class';
import { RemoteSelectable } from '../../../../../main/services/uml-element/remote-selectable/remote-selection-repository';


describe('test redux state upon changing remote selection.', () => {
test('elements can be selected.', () => {
const classA = new UMLClass({ name: 'ClassA' });
const classB = new UMLClass({ name: 'ClassB' });

const john = { name: 'John', color: 'red' };
const jane = { name: 'Jane', color: 'blue' };

const store = getRealStore({}, [classA, classB]);

expect(store.getState().remoteSelection).toEqual({});

store.dispatch(RemoteSelectable.remoteSelect(john, [classA.id]));
expect(store.getState().remoteSelection).toEqual({ [classA.id]: [john] });

store.dispatch(RemoteSelectable.remoteSelect(jane, [classA.id, classB.id]));
expect(store.getState().remoteSelection).toEqual({ [classA.id]: [john, jane], [classB.id]: [jane] });

store.dispatch(RemoteSelectable.remoteDeselect(jane, [classA.id]));
expect(store.getState().remoteSelection).toEqual({ [classA.id]: [john], [classB.id]: [jane] });

store.dispatch(RemoteSelectable.remoteSelectDeselect(john, [classB.id], [classA.id]));
expect(store.getState().remoteSelection).toEqual({ [classA.id]: [], [classB.id]: [jane, john] });

store.dispatch(RemoteSelectable.pruneRemoteSelectors([jane]));
expect(store.getState().remoteSelection).toEqual({ [classA.id]: [], [classB.id]: [jane] });
});
});

0 comments on commit c1eac47

Please sign in to comment.