|
|
|
@ -10,6 +10,10 @@ import {TREO_APP_CONFIG} from '@treo/services/config/config.constants';
|
|
|
|
|
import {DeviceSummaryModel} from 'app/core/models/device-summary-model';
|
|
|
|
|
import * as moment from 'moment';
|
|
|
|
|
import {HttpClientTestingModule} from '@angular/common/http/testing';
|
|
|
|
|
import {HttpClient} from '@angular/common/http';
|
|
|
|
|
import {ScrutinyConfigService} from 'app/core/config/scrutiny-config.service';
|
|
|
|
|
import {of} from 'rxjs';
|
|
|
|
|
import {MetricsStatusThreshold} from 'app/core/config/app.config';
|
|
|
|
|
|
|
|
|
|
describe('DashboardDeviceComponent', () => {
|
|
|
|
|
let component: DashboardDeviceComponent;
|
|
|
|
@ -17,9 +21,14 @@ describe('DashboardDeviceComponent', () => {
|
|
|
|
|
|
|
|
|
|
const matDialogSpy = jasmine.createSpyObj('MatDialog', ['open']);
|
|
|
|
|
// const configServiceSpy = jasmine.createSpyObj('ScrutinyConfigService', ['config$']);
|
|
|
|
|
|
|
|
|
|
let configService: ScrutinyConfigService;
|
|
|
|
|
let httpClientSpy: jasmine.SpyObj<HttpClient>;
|
|
|
|
|
|
|
|
|
|
beforeEach(async(() => {
|
|
|
|
|
|
|
|
|
|
httpClientSpy = jasmine.createSpyObj('HttpClient', ['get']);
|
|
|
|
|
configService = new ScrutinyConfigService(httpClientSpy, {});
|
|
|
|
|
|
|
|
|
|
TestBed.configureTestingModule({
|
|
|
|
|
imports: [
|
|
|
|
|
MatButtonModule,
|
|
|
|
@ -30,7 +39,8 @@ describe('DashboardDeviceComponent', () => {
|
|
|
|
|
],
|
|
|
|
|
providers: [
|
|
|
|
|
{provide: MatDialog, useValue: matDialogSpy},
|
|
|
|
|
{provide: TREO_APP_CONFIG, useValue: {dashboard_display: 'name'}}
|
|
|
|
|
{provide: TREO_APP_CONFIG, useValue: {dashboard_display: 'name', metrics: {status_threshold: 3}}},
|
|
|
|
|
{provide: ScrutinyConfigService, useValue: configService}
|
|
|
|
|
],
|
|
|
|
|
declarations: [DashboardDeviceComponent]
|
|
|
|
|
})
|
|
|
|
@ -50,25 +60,53 @@ describe('DashboardDeviceComponent', () => {
|
|
|
|
|
describe('#classDeviceLastUpdatedOn()', () => {
|
|
|
|
|
|
|
|
|
|
it('if non-zero device status, should be red', () => {
|
|
|
|
|
httpClientSpy.get.and.returnValue(of({
|
|
|
|
|
settings: {
|
|
|
|
|
metrics: {
|
|
|
|
|
status_threshold: MetricsStatusThreshold.Both,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
component.ngOnInit()
|
|
|
|
|
// component.deviceSummary = summary.data.summary['0x5000c500673e6b5f'] as DeviceSummaryModel
|
|
|
|
|
expect(component.classDeviceLastUpdatedOn({
|
|
|
|
|
device: {
|
|
|
|
|
device_status: 2
|
|
|
|
|
}
|
|
|
|
|
device_status: 2,
|
|
|
|
|
},
|
|
|
|
|
smart: {
|
|
|
|
|
collector_date: moment().subtract(13, 'days').toISOString()
|
|
|
|
|
},
|
|
|
|
|
} as DeviceSummaryModel)).toBe('text-red')
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('if non-zero device status, should be red', () => {
|
|
|
|
|
// component.deviceSummary = summary.data.summary['0x5000c500673e6b5f'] as DeviceSummaryModel
|
|
|
|
|
httpClientSpy.get.and.returnValue(of({
|
|
|
|
|
settings: {
|
|
|
|
|
metrics: {
|
|
|
|
|
status_threshold: MetricsStatusThreshold.Both,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
component.ngOnInit()
|
|
|
|
|
expect(component.classDeviceLastUpdatedOn({
|
|
|
|
|
device: {
|
|
|
|
|
device_status: 2
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
smart: {
|
|
|
|
|
collector_date: moment().subtract(13, 'days').toISOString()
|
|
|
|
|
},
|
|
|
|
|
} as DeviceSummaryModel)).toBe('text-red')
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('if healthy device status and updated in the last two weeks, should be green', () => {
|
|
|
|
|
// component.deviceSummary = summary.data.summary['0x5000c500673e6b5f'] as DeviceSummaryModel
|
|
|
|
|
httpClientSpy.get.and.returnValue(of({
|
|
|
|
|
settings: {
|
|
|
|
|
metrics: {
|
|
|
|
|
status_threshold: MetricsStatusThreshold.Both,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
component.ngOnInit()
|
|
|
|
|
expect(component.classDeviceLastUpdatedOn({
|
|
|
|
|
device: {
|
|
|
|
|
device_status: 0
|
|
|
|
@ -80,7 +118,14 @@ describe('DashboardDeviceComponent', () => {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('if healthy device status and updated more than two weeks ago, but less than 1 month, should be yellow', () => {
|
|
|
|
|
// component.deviceSummary = summary.data.summary['0x5000c500673e6b5f'] as DeviceSummaryModel
|
|
|
|
|
httpClientSpy.get.and.returnValue(of({
|
|
|
|
|
settings: {
|
|
|
|
|
metrics: {
|
|
|
|
|
status_threshold: MetricsStatusThreshold.Both,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
component.ngOnInit()
|
|
|
|
|
expect(component.classDeviceLastUpdatedOn({
|
|
|
|
|
device: {
|
|
|
|
|
device_status: 0
|
|
|
|
@ -92,7 +137,14 @@ describe('DashboardDeviceComponent', () => {
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('if healthy device status and updated more 1 month ago, should be red', () => {
|
|
|
|
|
// component.deviceSummary = summary.data.summary['0x5000c500673e6b5f'] as DeviceSummaryModel
|
|
|
|
|
httpClientSpy.get.and.returnValue(of({
|
|
|
|
|
settings: {
|
|
|
|
|
metrics: {
|
|
|
|
|
status_threshold: MetricsStatusThreshold.Both,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
component.ngOnInit()
|
|
|
|
|
expect(component.classDeviceLastUpdatedOn({
|
|
|
|
|
device: {
|
|
|
|
|
device_status: 0
|
|
|
|
@ -104,4 +156,114 @@ describe('DashboardDeviceComponent', () => {
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe('#deviceStatusString()', () => {
|
|
|
|
|
|
|
|
|
|
it('if healthy device, should be passing', () => {
|
|
|
|
|
httpClientSpy.get.and.returnValue(of({
|
|
|
|
|
settings: {
|
|
|
|
|
metrics: {
|
|
|
|
|
status_threshold: MetricsStatusThreshold.Both,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
component.ngOnInit()
|
|
|
|
|
expect(component.deviceStatusString({
|
|
|
|
|
device: {
|
|
|
|
|
device_status: 0
|
|
|
|
|
},
|
|
|
|
|
smart: {
|
|
|
|
|
collector_date: moment().subtract(13, 'days').toISOString()
|
|
|
|
|
},
|
|
|
|
|
} as DeviceSummaryModel)).toBe('passed')
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('if device with no smart data, should be unknown', () => {
|
|
|
|
|
httpClientSpy.get.and.returnValue(of({
|
|
|
|
|
settings: {
|
|
|
|
|
metrics: {
|
|
|
|
|
status_threshold: MetricsStatusThreshold.Both,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
component.ngOnInit()
|
|
|
|
|
expect(component.deviceStatusString({
|
|
|
|
|
device: {
|
|
|
|
|
device_status: 0
|
|
|
|
|
},
|
|
|
|
|
} as DeviceSummaryModel)).toBe('unknown')
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const testCases = [
|
|
|
|
|
{
|
|
|
|
|
'deviceStatus': 1,
|
|
|
|
|
'threshold': MetricsStatusThreshold.Smart,
|
|
|
|
|
'result': 'failed'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
'deviceStatus': 1,
|
|
|
|
|
'threshold': MetricsStatusThreshold.Scrutiny,
|
|
|
|
|
'result': 'passed'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
'deviceStatus': 1,
|
|
|
|
|
'threshold': MetricsStatusThreshold.Both,
|
|
|
|
|
'result': 'failed'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
'deviceStatus': 2,
|
|
|
|
|
'threshold': MetricsStatusThreshold.Smart,
|
|
|
|
|
'result': 'passed'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
'deviceStatus': 2,
|
|
|
|
|
'threshold': MetricsStatusThreshold.Scrutiny,
|
|
|
|
|
'result': 'failed'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
'deviceStatus': 2,
|
|
|
|
|
'threshold': MetricsStatusThreshold.Both,
|
|
|
|
|
'result': 'failed'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
'deviceStatus': 3,
|
|
|
|
|
'threshold': MetricsStatusThreshold.Smart,
|
|
|
|
|
'result': 'failed'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
'deviceStatus': 3,
|
|
|
|
|
'threshold': MetricsStatusThreshold.Scrutiny,
|
|
|
|
|
'result': 'failed'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
'deviceStatus': 3,
|
|
|
|
|
'threshold': MetricsStatusThreshold.Both,
|
|
|
|
|
'result': 'failed'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
testCases.forEach((test, index) => {
|
|
|
|
|
it(`if device with status (${test.deviceStatus}) and threshold (${test.threshold}), should be ${test.result}`, () => {
|
|
|
|
|
httpClientSpy.get.and.returnValue(of({
|
|
|
|
|
settings: {
|
|
|
|
|
metrics: {
|
|
|
|
|
status_threshold: test.threshold,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
component.ngOnInit()
|
|
|
|
|
expect(component.deviceStatusString({
|
|
|
|
|
device: {
|
|
|
|
|
device_status: test.deviceStatus
|
|
|
|
|
},
|
|
|
|
|
smart: {
|
|
|
|
|
collector_date: moment().subtract(13, 'days').toISOString()
|
|
|
|
|
},
|
|
|
|
|
} as DeviceSummaryModel)).toBe(test.result)
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|