Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame^] | 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; |
| 2 | import {InstantiationStatusComponent} from './instantiationStatus.component'; |
| 3 | import {ServiceInfoService} from '../shared/server/serviceInfo/serviceInfo.service'; |
| 4 | import {InstantiationStatusComponentService} from './instantiationStatus.component.service'; |
| 5 | import { ContextMenuModule, ContextMenuService } from 'ngx-contextmenu'; |
| 6 | import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core'; |
| 7 | import { HttpClientTestingModule } from '@angular/common/http/testing'; |
| 8 | import { ScrollToModule } from '@nicky-lenaers/ngx-scroll-to'; |
| 9 | import { ConfigurationService } from '../services/configuration.service'; |
| 10 | import { LogService } from '../shared/utils/log/log.service'; |
| 11 | |
| 12 | describe('Instantiation Status Component', () => { |
| 13 | let component: InstantiationStatusComponent; |
| 14 | let fixture: ComponentFixture<InstantiationStatusComponent>; |
| 15 | let enableDeleteItems = [ |
| 16 | { jobStatus:"PENDING" }, |
| 17 | { jobStatus:"STOPPED" }]; |
| 18 | let disableDeleteItems = [ |
| 19 | { jobStatus:"COMPLETED" }, |
| 20 | { jobStatus:"FAILED" }, |
| 21 | {jobStatus:"IN_PROGRESS"}, |
| 22 | {jobStatus:"UnknownOne"}]; |
| 23 | |
| 24 | |
| 25 | beforeEach(async(() => { |
| 26 | TestBed.configureTestingModule({ |
| 27 | imports: [HttpClientTestingModule, ContextMenuModule, ScrollToModule.forRoot()], |
| 28 | providers: [ServiceInfoService, InstantiationStatusComponentService, ContextMenuService, ConfigurationService, LogService], |
| 29 | declarations: [InstantiationStatusComponent], |
| 30 | schemas: [ CUSTOM_ELEMENTS_SCHEMA ] |
| 31 | }).compileComponents(); |
| 32 | })); |
| 33 | |
| 34 | beforeEach(() => { |
| 35 | fixture = TestBed.createComponent(InstantiationStatusComponent); |
| 36 | component = fixture.componentInstance; |
| 37 | fixture.detectChanges(); |
| 38 | }); |
| 39 | |
| 40 | it('component should initialize basic parameters', (done: DoneFn) => { |
| 41 | component.TIMER_TIME_IN_SECONDS = 2; |
| 42 | expect(component.TIMER_TIME_IN_SECONDS).toEqual(2); |
| 43 | expect(component.dataIsReady).toBeFalsy(); |
| 44 | expect(component.lastUpdatedDate).toBeNull(); |
| 45 | done(); |
| 46 | }); |
| 47 | |
| 48 | it('component constructor should call activateInterval and ngOnInit', (done: DoneFn) => { |
| 49 | component.refreshData(); |
| 50 | expect(component.dataIsReady).toBeFalsy(); |
| 51 | done(); |
| 52 | }); |
| 53 | |
| 54 | it('stopped and pending status isDeleteEnabled button should be enabled, not allowed delete statuses isDeleteEnabled button should be disabled', (done: DoneFn) => { |
| 55 | enableDeleteItems.forEach((item) => { |
| 56 | let isDeleteEnabled: boolean = component.isDeleteEnabled(item); |
| 57 | expect(isDeleteEnabled).toBeTruthy(); |
| 58 | }); |
| 59 | |
| 60 | disableDeleteItems.forEach((item) => { |
| 61 | let isDeleteEnabled: boolean = component.isDeleteEnabled(item); |
| 62 | expect(isDeleteEnabled).toBeFalsy(); |
| 63 | }); |
| 64 | done(); |
| 65 | }); |
| 66 | |
| 67 | it('[COMPLETED, FAILED, STOPPED] status isHideEnable button should be enabled, [IN_PROGRESS, PAUSE, PENDING] status isHideEnable button should be disabled', (done: DoneFn) => { |
| 68 | const enableHideItems = [ |
| 69 | { jobStatus:"COMPLETED" }, |
| 70 | { jobStatus:"FAILED" }, |
| 71 | { jobStatus:"STOPPED" }]; |
| 72 | enableHideItems.forEach((item) => { |
| 73 | let isDeleteEnabled: boolean = component.isHideEnabled(item); |
| 74 | expect(isDeleteEnabled).toBeTruthy(); |
| 75 | }); |
| 76 | |
| 77 | const disableHideItems = [ |
| 78 | { jobStatus:"IN_PROGRESS" }, |
| 79 | { jobStatus:"PAUSE" }, |
| 80 | { jobStatus:"PENDING" }, |
| 81 | { jobStatus:"NOT_MATTER"}]; |
| 82 | disableHideItems.forEach((item) => { |
| 83 | let isDeleteEnabled: boolean = component.isHideEnabled(item); |
| 84 | expect(isDeleteEnabled).toBeFalsy(); |
| 85 | }); |
| 86 | done(); |
| 87 | }); |
| 88 | }); |