]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import { HttpClientTestingModule } from '@angular/common/http/testing'; |
2 | import { ComponentFixture, TestBed } from '@angular/core/testing'; | |
3 | import { FormsModule } from '@angular/forms'; | |
4 | ||
5 | import { BsDatepickerModule } from 'ngx-bootstrap/datepicker'; | |
6 | import { TabsModule } from 'ngx-bootstrap/tabs'; | |
7 | import { TimepickerModule } from 'ngx-bootstrap/timepicker'; | |
8 | ||
9 | import { configureTestBed } from '../../../../testing/unit-test-helper'; | |
10 | import { SharedModule } from '../../../shared/shared.module'; | |
11 | import { LogsComponent } from './logs.component'; | |
12 | ||
13 | describe('LogsComponent', () => { | |
14 | let component: LogsComponent; | |
15 | let fixture: ComponentFixture<LogsComponent>; | |
16 | ||
17 | configureTestBed({ | |
18 | imports: [ | |
19 | HttpClientTestingModule, | |
20 | TabsModule.forRoot(), | |
21 | SharedModule, | |
22 | BsDatepickerModule.forRoot(), | |
23 | TimepickerModule.forRoot(), | |
24 | FormsModule | |
25 | ], | |
26 | declarations: [LogsComponent] | |
27 | }); | |
28 | ||
29 | beforeEach(() => { | |
30 | fixture = TestBed.createComponent(LogsComponent); | |
31 | component = fixture.componentInstance; | |
32 | fixture.detectChanges(); | |
33 | }); | |
34 | ||
35 | it('should create', () => { | |
36 | expect(component).toBeTruthy(); | |
37 | }); | |
38 | ||
39 | describe('abstractfilters', () => { | |
40 | it('after initializaed', () => { | |
41 | const filters = component.abstractfilters(); | |
42 | expect(filters.priority).toBe('All'); | |
43 | expect(filters.key).toBe(''); | |
44 | expect(filters.yearMonthDay).toBe(''); | |
45 | expect(filters.sTime).toBe(0); | |
46 | expect(filters.eTime).toBe(1439); | |
47 | }); | |
48 | it('change date', () => { | |
49 | component.selectedDate = new Date(2019, 0, 1); | |
50 | component.startTime = new Date(2019, 1, 1, 1, 10); | |
51 | component.endTime = new Date(2019, 1, 1, 12, 10); | |
52 | const filters = component.abstractfilters(); | |
53 | expect(filters.yearMonthDay).toBe('2019-01-01'); | |
54 | expect(filters.sTime).toBe(70); | |
55 | expect(filters.eTime).toBe(730); | |
56 | }); | |
57 | }); | |
58 | ||
59 | describe('filterLogs', () => { | |
9f95a23c | 60 | const contentData: Record<string, any> = { |
11fdf7f2 TL |
61 | clog: [ |
62 | { | |
63 | name: 'priority', | |
64 | stamp: '2019-02-21 09:39:49.572801', | |
65 | message: 'Manager daemon localhost is now available', | |
66 | priority: '[ERR]' | |
67 | }, | |
68 | { | |
69 | name: 'search', | |
70 | stamp: '2019-02-21 09:39:49.572801', | |
71 | message: 'Activating manager daemon localhost', | |
72 | priority: '[INF]' | |
73 | }, | |
74 | { | |
75 | name: 'date', | |
76 | stamp: '2019-01-21 09:39:49.572801', | |
77 | message: 'Manager daemon localhost is now available', | |
78 | priority: '[INF]' | |
79 | }, | |
80 | { | |
81 | name: 'time', | |
82 | stamp: '2019-02-21 01:39:49.572801', | |
83 | message: 'Manager daemon localhost is now available', | |
84 | priority: '[INF]' | |
85 | } | |
86 | ], | |
87 | audit_log: [] | |
88 | }; | |
89 | const resetFilter = () => { | |
90 | component.selectedDate = null; | |
91 | component.priority = 'All'; | |
92 | component.search = ''; | |
93 | component.startTime.setHours(0, 0); | |
94 | component.endTime.setHours(23, 59); | |
95 | }; | |
96 | beforeEach(() => { | |
97 | component.contentData = contentData; | |
98 | }); | |
99 | ||
100 | it('show all log', () => { | |
101 | component.filterLogs(); | |
102 | expect(component.clog.length).toBe(4); | |
103 | }); | |
104 | ||
105 | it('filter by search key', () => { | |
106 | resetFilter(); | |
107 | component.search = 'Activating'; | |
108 | component.filterLogs(); | |
109 | expect(component.clog.length).toBe(1); | |
110 | expect(component.clog[0].name).toBe('search'); | |
111 | }); | |
112 | ||
113 | it('filter by date', () => { | |
114 | resetFilter(); | |
115 | component.selectedDate = new Date(2019, 0, 21); | |
116 | component.filterLogs(); | |
117 | expect(component.clog.length).toBe(1); | |
118 | expect(component.clog[0].name).toBe('date'); | |
119 | }); | |
120 | ||
121 | it('filter by priority', () => { | |
122 | resetFilter(); | |
123 | component.priority = '[ERR]'; | |
124 | component.filterLogs(); | |
125 | expect(component.clog.length).toBe(1); | |
126 | expect(component.clog[0].name).toBe('priority'); | |
127 | }); | |
128 | ||
129 | it('filter by time range', () => { | |
130 | resetFilter(); | |
131 | component.startTime.setHours(1, 0); | |
132 | component.endTime.setHours(2, 0); | |
133 | component.filterLogs(); | |
134 | expect(component.clog.length).toBe(1); | |
135 | expect(component.clog[0].name).toBe('time'); | |
136 | }); | |
137 | }); | |
138 | }); |