import { ChangeDetectorRef } from '@angular/core'; import { Store } from '@ngrx/store'; import { CookiesService } from '@hdca/fe-angular-shared'; import * as petaReducer from '@core/modules/peta/reducers'; import { mockPETARequestData, mockPETAListRequestData } from '@core/stubs'; import { PersonalizedETAContainer } from '@core/modules/peta/containers/peta.container'; export const ui = 30; export const accessibility = null; describe('Cart', () => { describe('Personalized ETA component', () => { let storeMock: jasmine.SpyObj>; let petaStoreMock: jasmine.SpyObj>; let cookiesServiceMock: jasmine.SpyObj; let changeDetectorRefMock: jasmine.SpyObj; let personalizedETAComponent: PersonalizedETAContainer; let mockData: any; let mockDataList: any; beforeEach(() => { storeMock = jasmine.createSpyObj('store', {'select': { 'subscribe': () => {}}, 'dispatch': () => {}}); petaStoreMock = jasmine.createSpyObj('petaStore', {'select': { 'subscribe': () => {}}, 'dispatch': () => {}}); cookiesServiceMock = jasmine.createSpyObj('CookiesService', ['getCookie', 'removeCookie']); changeDetectorRefMock = jasmine.createSpyObj('ChangeDetectorRef', ['markForCheck']); personalizedETAComponent = new PersonalizedETAContainer(storeMock, petaStoreMock, cookiesServiceMock, changeDetectorRefMock); mockData = mockPETARequestData.SOURCING_RESULT; mockDataList = mockPETAListRequestData; }); it('should have `PersonalizedETAContainer` defined', () => { expect(personalizedETAComponent).toBeTruthy(); }); it('should have these methods existed: getEstimateDeliveryTime and ngOnDestroy`', () => { expect(personalizedETAComponent.getEstimateDeliveryTime).toBeTruthy(); expect(personalizedETAComponent.ngOnDestroy).toBeTruthy(); }); it('should have default value to these fields: `productCode, fulfillmentType, genericETAValue, genericETAUnit, ' + 'isLoading, genericETAValueWithUnit and estimateDelivery` when `ngOnInit` is not called', () => { expect(personalizedETAComponent.productCode).toBeUndefined(); expect(personalizedETAComponent.fulfillmentType).toBeUndefined(); expect(personalizedETAComponent.genericETAValue).toBeUndefined(); expect(personalizedETAComponent.genericETAUnit).toBeUndefined(); expect(personalizedETAComponent.genericETAValueWithUnit).toBeUndefined(); expect(personalizedETAComponent.estimateDelivery).toBeUndefined(); expect(personalizedETAComponent.isInStoreList).toBeUndefined(); expect(personalizedETAComponent.storeName).toBeUndefined(); }); it('should have `estimateDeliveryData` updated for `BOSS` when `getEstimateDeliveryTime` is called with data responded', () => { personalizedETAComponent.productCode = '1000100565'; personalizedETAComponent.fulfillmentType = 'BOSS'; personalizedETAComponent.dash = '–'; personalizedETAComponent.genericETAValueWithUnit = null; personalizedETAComponent.getEstimateDeliveryTime(mockData); expect(personalizedETAComponent.estimateDelivery).toEqual('5 – 12 days'); }); it('should have `estimateDeliveryData` updated for `SHIPTOHOME` when `getEstimateDeliveryTime` is called with data responded', () => { personalizedETAComponent.productCode = '1000834551'; personalizedETAComponent.fulfillmentType = 'SHIPTOHOME'; personalizedETAComponent.dash = '–'; personalizedETAComponent.genericETAValueWithUnit = null; personalizedETAComponent.getEstimateDeliveryTime(mockData); expect(personalizedETAComponent.estimateDelivery).toEqual('2 – 5 days'); }); it('should have `estimateDeliveryData` updated for `BOSS` when `getETAStoreList` with specific store `7001` is called with data responded', () => { personalizedETAComponent.storeName = '7001'; personalizedETAComponent.fulfillmentType = 'BOSS'; personalizedETAComponent.dash = '–'; personalizedETAComponent.genericETAValueWithUnit = null; personalizedETAComponent.getETAStoreList(mockDataList); expect(personalizedETAComponent.estimateDelivery).toEqual('200 – 202 days'); }); it('should have `estimateDeliveryData` updated for `BOSS` when `getETAStoreList` with specific store `7006` is called with data responded', () => { personalizedETAComponent.storeName = '7006'; personalizedETAComponent.fulfillmentType = 'BOSS'; personalizedETAComponent.dash = '–'; personalizedETAComponent.genericETAValueWithUnit = null; personalizedETAComponent.getETAStoreList(mockDataList); expect(personalizedETAComponent.estimateDelivery).toEqual('17 – 19 days'); }); it('should have `estimateDeliveryData` updated for `BOSS` when `getSAPPETAValue` with specific store `7001` in store list is called with data responded', () => { personalizedETAComponent.storeName = '7001'; personalizedETAComponent.fulfillmentType = 'BOSS'; personalizedETAComponent.dash = '–'; personalizedETAComponent.genericETAValueWithUnit = null; personalizedETAComponent.getSAPPETAValue(mockDataList[0].SOURCING_RESULT.SOURCING_RESULTS[0], true); expect(personalizedETAComponent.estimateDelivery).toEqual('200 – 202 days'); }); it('should have `estimateDeliveryData` updated for `BOSS` when `getSAPPETAValue` with specific article SKU `1000100565` not in store list is called with data responded', () => { personalizedETAComponent.productCode = '1000100565'; personalizedETAComponent.fulfillmentType = 'BOSS'; personalizedETAComponent.dash = '–'; personalizedETAComponent.genericETAValueWithUnit = null; personalizedETAComponent.getSAPPETAValue(mockData.SOURCING_RESULTS[0]); expect(personalizedETAComponent.estimateDelivery).toEqual('5 – 12 days'); }); }); });