import { HttpClient, HttpHandler } from '@angular/common/http'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { EDeviceStatus, ProvisioningType } from '@app/device-enrolment/constants'; import { NgxsDispatchPluginModule } from '@ngxs-labs/dispatch-decorator'; import { NgxsModule, Store } from '@ngxs/store'; import { KeycloakService } from 'keycloak-angular'; import { DeviceStatusSuccessComponent } from './device-status-success.component'; import { DeviceEnrolmentState, DeviceQrCodeState } from '@app/device-enrolment/store'; import { BrowserModule } from '@angular/platform-browser'; import { SharedModule } from '@app/shared/shared.module'; import { PreCheckStatus } from '@app/device-enrolment/types'; describe('DeviceStatusSuccessComponent', () => { let component: DeviceStatusSuccessComponent; let fixture: ComponentFixture; let store: Store; const preCheckStatusMock: PreCheckStatus = { tac: { modelMarketingName: 'Huawei', modelFormalName: 'p30 lite', provisioningType: ProvisioningType.PAY_TRIGGER, }, defaultPolicy: { id: 'id-1', names: { name: 'Default name', alternativeNames: [] } }, policies: [ { id: 'id-2', names: { name: 'the first policy', alternativeNames: [] } }, { id: 'id-2', names: { name: 'the second policy', alternativeNames: [] } }, { id: 'id-3', names: { name: 'the 3d policy', alternativeNames: [] } }, ], }; const defaultStoreState = { deviceQRCode: { isReady: false, isActive: false }, deviceEnrolment: { preCheckStatus: preCheckStatusMock, posSubmitted: true, posPolicy: '' }, }; const initComponent = (storeState = defaultStoreState) => { store.reset(storeState); fixture = TestBed.createComponent(DeviceStatusSuccessComponent); fixture.detectChanges(); component = fixture.componentInstance; fixture.detectChanges(); }; beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [DeviceStatusSuccessComponent], imports: [ SharedModule, BrowserModule, NgxsModule.forRoot([DeviceEnrolmentState, DeviceQrCodeState]), NgxsDispatchPluginModule.forRoot(), ], providers: [HttpClient, HttpHandler, KeycloakService], }).compileComponents(); store = TestBed.inject(Store); })); describe('component', () => { beforeEach(() => { initComponent(); }); it('should be defined', () => { expect(component).toBeDefined(); }); }); describe('deviceStatus', () => { describe(`when provisioning type is "${ProvisioningType.ALPS}" and posSubmitted, isReady and isActive are true`, () => { beforeEach(() => { initComponent({ deviceEnrolment: { ...defaultStoreState.deviceEnrolment, preCheckStatus: { ...defaultStoreState.deviceEnrolment.preCheckStatus, tac: { ...defaultStoreState.deviceEnrolment.preCheckStatus.tac, provisioningType: ProvisioningType.ALPS, }, }, posSubmitted: true, }, deviceQRCode: { isReady: true, isActive: true, }, }); }); it(`should equal to ${EDeviceStatus.REGISTRATION_COMPLETED}"`, () => { expect(component.deviceStatus).toEqual(EDeviceStatus.REGISTRATION_COMPLETED); }); }); describe(`when provisioning type is "${ProvisioningType.KNOX_GUARD}" and posSubmitted and isReady are true`, () => { beforeEach(() => { initComponent({ deviceEnrolment: { ...defaultStoreState.deviceEnrolment, preCheckStatus: { ...defaultStoreState.deviceEnrolment.preCheckStatus, tac: { ...defaultStoreState.deviceEnrolment.preCheckStatus.tac, provisioningType: ProvisioningType.KNOX_GUARD, }, }, posSubmitted: true, }, deviceQRCode: { isReady: true, isActive: false, }, }); }); it(`should equal to ${EDeviceStatus.REGISTRATION_COMPLETED}"`, () => { expect(component.deviceStatus).toEqual(EDeviceStatus.REGISTRATION_COMPLETED); }); }); describe(`when provisioning type is "${ProvisioningType.PAY_TRIGGER}" and posSubmitted and isReady are true`, () => { beforeEach(() => { initComponent({ deviceEnrolment: { ...defaultStoreState.deviceEnrolment, preCheckStatus: { ...defaultStoreState.deviceEnrolment.preCheckStatus, tac: { ...defaultStoreState.deviceEnrolment.preCheckStatus.tac, provisioningType: ProvisioningType.PAY_TRIGGER, }, }, posSubmitted: true, }, deviceQRCode: { isReady: true, isActive: false, }, }); }); it(`should equal to ${EDeviceStatus.REGISTRATION_COMPLETED}"`, () => { expect(component.deviceStatus).toEqual(EDeviceStatus.REGISTRATION_COMPLETED); }); }); }); describe(`when provisioning type is "${ProvisioningType.ZERO_TOUCH}" and posSubmitted and isReady are true`, () => { beforeEach(() => { initComponent({ deviceEnrolment: { ...defaultStoreState.deviceEnrolment, preCheckStatus: { ...defaultStoreState.deviceEnrolment.preCheckStatus, tac: { ...defaultStoreState.deviceEnrolment.preCheckStatus.tac, provisioningType: ProvisioningType.ZERO_TOUCH, }, }, posSubmitted: true, }, deviceQRCode: { isReady: true, isActive: false, }, }); }); it(`should equal to ${EDeviceStatus.REGISTRATION_COMPLETED}"`, () => { expect(component.deviceStatus).toEqual(EDeviceStatus.REGISTRATION_COMPLETED); }); }); describe(`when provisioning type is "${ProvisioningType.ZERO_TOUCH}" and posSubmitted and isReady are false`, () => { beforeEach(() => { initComponent({ deviceEnrolment: { ...defaultStoreState.deviceEnrolment, preCheckStatus: { ...defaultStoreState.deviceEnrolment.preCheckStatus, tac: { ...defaultStoreState.deviceEnrolment.preCheckStatus.tac, provisioningType: ProvisioningType.ZERO_TOUCH, }, }, posSubmitted: false, }, deviceQRCode: { isReady: false, isActive: false, }, }); }); it(`should be undefined`, () => { expect(component.deviceStatus).toBeUndefined(); }); }); describe(`when provisioning type is "${ProvisioningType.KNOX_GUARD}" and posSubmitted and isReady are false`, () => { beforeEach(() => { initComponent({ deviceEnrolment: { ...defaultStoreState.deviceEnrolment, preCheckStatus: { ...defaultStoreState.deviceEnrolment.preCheckStatus, tac: { ...defaultStoreState.deviceEnrolment.preCheckStatus.tac, provisioningType: ProvisioningType.KNOX_GUARD, }, }, posSubmitted: false, }, deviceQRCode: { isReady: false, isActive: false, }, }); }); it(`should be undefined`, () => { expect(component.deviceStatus).toBeUndefined(); }); }); });