1 import { HttpClientTestingModule } from '@angular/common/http/testing';
2 import { ComponentFixture, TestBed } from '@angular/core/testing';
3 import { FormsModule } from '@angular/forms';
5 import { BsDatepickerModule } from 'ngx-bootstrap/datepicker';
6 import { TabsModule } from 'ngx-bootstrap/tabs';
7 import { TimepickerModule } from 'ngx-bootstrap/timepicker';
9 import { configureTestBed } from '../../../../testing/unit-test-helper';
10 import { SharedModule } from '../../../shared/shared.module';
11 import { LogsComponent } from './logs.component';
13 describe('LogsComponent', () => {
14 let component: LogsComponent;
15 let fixture: ComponentFixture<LogsComponent>;
19 HttpClientTestingModule,
22 BsDatepickerModule.forRoot(),
23 TimepickerModule.forRoot(),
26 declarations: [LogsComponent]
30 fixture = TestBed.createComponent(LogsComponent);
31 component = fixture.componentInstance;
32 fixture.detectChanges();
35 it('should create', () => {
36 expect(component).toBeTruthy();
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);
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);
59 describe('filterLogs', () => {
60 const contentData: Record<string, any> = {
64 stamp: '2019-02-21 09:39:49.572801',
65 message: 'Manager daemon localhost is now available',
70 stamp: '2019-02-21 09:39:49.572801',
71 message: 'Activating manager daemon localhost',
76 stamp: '2019-01-21 09:39:49.572801',
77 message: 'Manager daemon localhost is now available',
82 stamp: '2019-02-21 01:39:49.572801',
83 message: 'Manager daemon localhost is now available',
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);
97 component.contentData = contentData;
100 it('show all log', () => {
101 component.filterLogs();
102 expect(component.clog.length).toBe(4);
105 it('filter by search key', () => {
107 component.search = 'Activating';
108 component.filterLogs();
109 expect(component.clog.length).toBe(1);
110 expect(component.clog[0].name).toBe('search');
113 it('filter by date', () => {
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');
121 it('filter by priority', () => {
123 component.priority = '[ERR]';
124 component.filterLogs();
125 expect(component.clog.length).toBe(1);
126 expect(component.clog[0].name).toBe('priority');
129 it('filter by time range', () => {
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');