Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should load all countries on effects init and dispatch a LoadCountriesSuccess action', () => {
const action = { type: CountryActionTypes.LoadCountries } as Action;
const expected = new LoadCountriesSuccess({ countries });
actions$ = hot('-a-------', { a: action });
expect(effects.loadCountries$).toBeObservable(cold('-b-------', { b: expected }));
});
it('should accumulate AddProductToBasket to a single AddItemsToBasket action', () => {
store$.dispatch(new LoadProductSuccess({ product: { sku: 'SKU1', packingUnit: 'pcs.' } as Product }));
store$.dispatch(new LoadProductSuccess({ product: { sku: 'SKU2', packingUnit: 'pcs.' } as Product }));
const action1 = new basketActions.AddProductToBasket({ sku: 'SKU1', quantity: 1 });
const action2 = new basketActions.AddProductToBasket({ sku: 'SKU2', quantity: 1 });
const completion = new basketActions.AddItemsToBasket({
items: [{ sku: 'SKU2', quantity: 2, unit: 'pcs.' }, { sku: 'SKU1', quantity: 2, unit: 'pcs.' }],
});
actions$ = hot(' -b-a-b-a--|', { a: action1, b: action2 });
const expected$ = cold('----------(c|)', { c: completion });
expect(effects.addProductToBasket$).toBeObservable(expected$);
});
});
it('should map to action of type LoadQuotes if SubmitQuoteRequestSuccess action triggered', () => {
const action = new SubmitQuoteRequestSuccess(anyString());
const completion = new quoteActions.LoadQuotes();
actions$ = hot('-a-a-a', { a: action });
const expected$ = cold('-c-c-c', { c: completion });
expect(effects.loadQuotesAfterChangeSuccess$).toBeObservable(expected$);
});
it('should map invalid request to action of type LoadPromotionFail only once', () => {
const promoId = 'invalid';
const action = new fromActions.LoadPromotion({ promoId });
const completion = new fromActions.LoadPromotionFail({ error: { message: 'invalid' } as HttpError, promoId });
actions$ = hot('-a-a-a', { a: action });
const expected$ = cold('-c----', { c: completion });
expect(effects.loadPromotion$).toBeObservable(expected$);
});
});
it('should trigger LoadProduct action if LoadProductSuccess contains productMasterSKU', () => {
const action = new fromActions.LoadProductSuccess({
product: {
productMasterSKU: 'MSKU',
type: 'VariationProduct',
} as VariationProduct,
});
const completion = new fromActions.LoadProductIfNotLoaded({ sku: 'MSKU', level: ProductCompletenessLevel.List });
actions$ = hot('-a', { a: action });
const expected$ = cold('-c', { c: completion });
expect(effects.loadMasterProductForProduct$).toBeObservable(expected$);
});
it('should not fire when product is not yet loaded', () => {
actions$ = hot('a', { a: new SelectProduct({ sku: 'A' }) });
expect(effects.viewedProduct$).toBeObservable(cold('------'));
});
it('should map to action of type LoadBasket in case of success', () => {
const action = new basketActions.UpdateBasketPaymentSuccess();
const completion = new basketActions.LoadBasket();
actions$ = hot('-a-a-a', { a: action });
const expected$ = cold('-c-c-c', { c: completion });
expect(effects.loadBasketAfterBasketChangeSuccess$).toBeObservable(expected$);
});
});
it('should map to action of type LoadFilterSuccess', () => {
const action = new fromActions.LoadFilterForCategory({ uniqueId: 'c' });
const completion = new fromActions.LoadFilterSuccess({ filterNavigation: filterNav });
actions$ = hot('-a-a-a', { a: action });
const expected$ = cold('-c-c-c', { c: completion });
expect(effects.loadAvailableFilterForCategories$).toBeObservable(expected$);
});
it('should call the user service on LoadUserByAPIToken action and do nothing when failing', () => {
when(userServiceMock.signinUserByToken('dummy')).thenReturn(EMPTY);
actions$ = hot('a-a-a-', { a: new ua.LoadUserByAPIToken({ apiToken: 'dummy' }) });
expect(effects.loadUserByAPIToken$).toBeObservable(cold('------'));
});
});
value: 'test',
filters: 'b*',
},
searchParameter: 'b',
});
const completion = new SetProductListingPages({
id: {
type: 'search',
value: 'test',
filters: 'b*',
},
1: ['123', '234'],
itemCount: 2,
sortKeys: [],
});
actions$ = hot(' -a-b-|', { a: routing, b: action });
const expected$ = cold('---c-|', { c: completion });
expect(effects.loadFilteredProducts$).toBeObservable(expected$);
});
});