/
list.component.spec.ts
107 lines (98 loc) · 3.85 KB
/
list.component.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ListComponent } from './list.component';
import {
ListConfigService,
FormModule,
IconModule,
SymbolModule,
UtilityModule, GroupPipe, SearchbarComponent, PaginationComponent, ListHeaderComponent,
ListItemsComponent
} from '../../public_api';
import { FormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';
import { Item } from '@ec.components/core';
/* import { mocked } from '../../mocks/data'; */
describe('ListComponent', () => {
let component: ListComponent<any>;
let fixture: ComponentFixture<ListComponent<any>>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
ListComponent,
ListItemsComponent,
ListHeaderComponent,
PaginationComponent,
SearchbarComponent,
GroupPipe,
],
imports: [CommonModule, FormsModule, FormModule, IconModule, SymbolModule, UtilityModule],
providers: [ListConfigService],
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
component.ngOnChanges();
});
it('should detect change to items and create a list', () => {
component.items = ['a', 'b', 'c'].map((i) => new Item(i));
component.ngOnChanges();
expect(component.list).toBeDefined();
expect(component.list.items.length).toBe(component.items.length);
expect(component.selection).toBeDefined();
});
/* it('should support selectNext and selectPrevious', () => {
component.list = mocked.lists.trees;
component.ngOnChanges();
expect(component.list.items[0].getBody().name).toBe('Appletree');
expect(component.selection.items.length).toBe(0);
component.selectNext();
expect(component.selection.items.length).toBe(1);
expect(component.selection.items[0].getBody().name).toBe('Appletree');
component.selectNext();
expect(component.selection.items.length).toBe(1);
expect(component.selection.items[0].getBody().name).toBe('Lemontree');
component.selectPrev();
expect(component.selection.items.length).toBe(1);
expect(component.selection.items[0].getBody().name).toBe('Appletree');
component.selection.removeAll();
expect(component.selection.items.length).toBe(0);
component.selectPrev();
expect(component.selection.items.length).toBe(1);
expect(component.selection.items[0].getBody().name).toBe('ba');
component.selectPrev();
expect(component.selection.items.length).toBe(1);
expect(component.selection.items[0].getBody().name).toBe('aa');
}); */
// TODO fix
/*it('should use collection input', () => {
component.collection = new Collection(mocked.muffins);
component.ngOnChanges();
expect(component.list).toBeDefined();
expect(component.list.items.length).toBe(mocked.muffins.length);
expect(component.selection).toBeDefined();
});
it('should toggle selection on columnClick', () => {
component.collection = new Collection(mocked.products);
component.ngOnChanges();
component.columnClick(component.list.items[0]);
expect(component.selection.has(component.list.items[0])).toBeTruthy();
component.columnClick(component.list.items[0]);
expect(component.selection.has(component.list.items[0])).toBeFalsy();
});
it('should support custom select', () => {
component.collection = new Collection(mocked.products);
component.ngOnChanges();
let selected;
component.select.subscribe((item) => {
selected = item;
});
component.columnClick(component.list.items[0]); //selection should not change
expect(component.selection.has(component.list.items[0])).toBeFalsy();
expect(selected).toBe(component.list.items[0]);
});*/
});