b71d6660a6
some code reformatting adding tests for services and components. cleanup of unused dependencies in components. refactor dashboard service so that wrapper is removed before data is passed to component. (no more this.data.data...). refactored components so that variable names are consistent (dashboardService vs smartService). ensure argument and return types are specified everywhere. adding tests for pipes. adding ng test to ci steps. change dir before running npm install. trying to install nodejs in continer. test frontend separately. upload coverage for frontend and backend. upload coverage for frontend and backend. testing coverage file locations. retry file upload.
106 lines
4.1 KiB
TypeScript
106 lines
4.1 KiB
TypeScript
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
|
|
|
import {DashboardDeviceComponent} from './dashboard-device.component';
|
|
import {MatDialog} from '@angular/material/dialog';
|
|
import {MatButtonModule} from '@angular/material/button';
|
|
import {MatIconModule} from '@angular/material/icon';
|
|
import {SharedModule} from 'app/shared/shared.module';
|
|
import {MatMenuModule} from '@angular/material/menu';
|
|
import {TREO_APP_CONFIG} from '@treo/services/config/config.constants';
|
|
import {DeviceSummaryModel} from 'app/core/models/device-summary-model';
|
|
import * as moment from 'moment';
|
|
|
|
describe('DashboardDeviceComponent', () => {
|
|
let component: DashboardDeviceComponent;
|
|
let fixture: ComponentFixture<DashboardDeviceComponent>;
|
|
|
|
const matDialogSpy = jasmine.createSpyObj('MatDialog', ['open']);
|
|
// const configServiceSpy = jasmine.createSpyObj('TreoConfigService', ['config$']);
|
|
|
|
|
|
beforeEach(async(() => {
|
|
TestBed.configureTestingModule({
|
|
imports: [
|
|
MatButtonModule,
|
|
MatIconModule,
|
|
MatMenuModule,
|
|
SharedModule,
|
|
],
|
|
providers: [
|
|
{provide: MatDialog, useValue: matDialogSpy},
|
|
{provide: TREO_APP_CONFIG, useValue: {dashboardDisplay: 'name'}}
|
|
],
|
|
declarations: [DashboardDeviceComponent]
|
|
})
|
|
.compileComponents();
|
|
}));
|
|
|
|
beforeEach(() => {
|
|
// configServiceSpy.config$.and.returnValue(of({'success': true}));
|
|
fixture = TestBed.createComponent(DashboardDeviceComponent);
|
|
component = fixture.componentInstance;
|
|
});
|
|
|
|
it('should create', () => {
|
|
expect(component).toBeTruthy();
|
|
});
|
|
|
|
describe('#classDeviceLastUpdatedOn()', () => {
|
|
|
|
it('if non-zero device status, should be red', () => {
|
|
// component.deviceSummary = summary.data.summary['0x5000c500673e6b5f'] as DeviceSummaryModel
|
|
expect(component.classDeviceLastUpdatedOn({
|
|
device: {
|
|
device_status: 2
|
|
}
|
|
} as DeviceSummaryModel)).toBe('text-red')
|
|
});
|
|
|
|
it('if non-zero device status, should be red', () => {
|
|
// component.deviceSummary = summary.data.summary['0x5000c500673e6b5f'] as DeviceSummaryModel
|
|
expect(component.classDeviceLastUpdatedOn({
|
|
device: {
|
|
device_status: 2
|
|
}
|
|
} 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
|
|
expect(component.classDeviceLastUpdatedOn({
|
|
device: {
|
|
device_status: 0
|
|
},
|
|
smart: {
|
|
collector_date: moment().subtract(13, 'days').toISOString()
|
|
}
|
|
} as DeviceSummaryModel)).toBe('text-green')
|
|
});
|
|
|
|
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
|
|
expect(component.classDeviceLastUpdatedOn({
|
|
device: {
|
|
device_status: 0
|
|
},
|
|
smart: {
|
|
collector_date: moment().subtract(3, 'weeks').toISOString()
|
|
}
|
|
} as DeviceSummaryModel)).toBe('text-yellow')
|
|
});
|
|
|
|
it('if healthy device status and updated more 1 month ago, should be red', () => {
|
|
// component.deviceSummary = summary.data.summary['0x5000c500673e6b5f'] as DeviceSummaryModel
|
|
expect(component.classDeviceLastUpdatedOn({
|
|
device: {
|
|
device_status: 0
|
|
},
|
|
smart: {
|
|
collector_date: moment().subtract(5, 'weeks').toISOString()
|
|
}
|
|
} as DeviceSummaryModel)).toBe('text-red')
|
|
});
|
|
})
|
|
|
|
});
|