Skip to content

Commit bf0b124

Browse files
committed
test(store): test ngsg-store.service
1 parent 69df0ec commit bf0b124

File tree

3 files changed

+71
-30
lines changed

3 files changed

+71
-30
lines changed

projects/ng-sortgrid-demo/src/app/app.component.spec.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import {NgsgStoreService} from './ngsg-store.service';
2+
import {NgsgDragelement} from './ngsg-dragelement.model';
3+
4+
describe('NgsgStoreService', () => {
5+
6+
let sut: NgsgStoreService;
7+
8+
beforeEach(() => {
9+
sut = new NgsgStoreService();
10+
});
11+
12+
describe('InitState', () => {
13+
14+
it('should add the items to the group', () => {
15+
const group = 'testgroup';
16+
const items = ['Item1', 'Item2'];
17+
const classes = [];
18+
19+
sut.initState(group, items, classes);
20+
expect(sut.getItems(group)).toEqual(items);
21+
});
22+
23+
it('should add empty items to the group if we do not pass items in', () => {
24+
const group = 'testgroup';
25+
const items = undefined;
26+
const classes = [];
27+
28+
sut.initState(group, items, classes);
29+
expect(sut.getItems(group)).toEqual([]);
30+
});
31+
32+
it('should add the classes to the group', () => {
33+
const group = 'testgroup';
34+
const items = ['Item1', 'Item2'];
35+
const classes = ['Class1', 'Class2'];
36+
37+
sut.initState(group, items, classes);
38+
expect(sut.getClasses(group)).toEqual(classes);
39+
});
40+
});
41+
42+
it('should set the items and then return it', () => {
43+
const group = 'testGroup';
44+
const items = ['ItemOne', 'ItemTwo'];
45+
sut.initState(group);
46+
47+
sut.setItems(group, items);
48+
expect(sut.getItems(group)).toEqual(items);
49+
});
50+
51+
it('should set the selectedItems and then return it', () => {
52+
const group = 'testGroup';
53+
const selectedItems = ['ItemOne', 'ItemTwo'];
54+
sut.initState(group);
55+
56+
sut.setSelectedItems(group, selectedItems);
57+
expect(sut.getSelectedItems(group) as any).toEqual(selectedItems);
58+
});
59+
60+
it('should get the first selectedItem', () => {
61+
const group = 'testGroup';
62+
const firstItem = 'ItemOne' as any;
63+
const selectedItems = [firstItem, 'ItemTwo'] as any[];
64+
sut.initState(group);
65+
66+
sut.setSelectedItems(group, selectedItems);
67+
expect(sut.getFirstSelectItem(group)).toEqual(firstItem);
68+
});
69+
70+
});

projects/ng-sortgrid/src/lib/ngsg-store.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export interface NgsgState {
1414
export class NgsgStoreService {
1515
private state = new Map<string, NgsgState>();
1616

17-
public initState(group: string, items: any[] = [], classes: any): void {
17+
public initState(group: string, items: any[] = [], classes: any[] = []): void {
1818
this.state.set(group, {items: [...items], classes, selectedItems: []});
1919
}
2020

0 commit comments

Comments
 (0)