blob: b2131ceed5587be39732f528f70cf3c46dad86bd [file] [log] [blame]
svishnev091edfd2018-03-19 12:15:19 +02001/*
2 * Copyright © 2016-2018 European Support Limited
AviZi280f8012017-06-09 02:39:56 +03003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
svishnev091edfd2018-03-19 12:15:19 +02007 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
AviZi280f8012017-06-09 02:39:56 +030010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
svishnev091edfd2018-03-19 12:15:19 +020012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
AviZi280f8012017-06-09 02:39:56 +030015 */
svishnevea5e43c2018-04-15 09:06:57 +030016import { storeCreator } from 'sdc-app/AppStore.js';
17import { OnboardStoreFactory } from 'test-utils/factories/onboard/OnboardFactories.js';
AviZi280f8012017-06-09 02:39:56 +030018import OnboardActionHelper from 'sdc-app/onboarding/onboard/OnboardActionHelper.js';
19import OnboardingCatalogActionHelper from 'sdc-app/onboarding/onboard/onboardingCatalog/OnboardingCatalogActionHelper.js';
svishnevea5e43c2018-04-15 09:06:57 +030020import { tabsMapping as onboardTabsMapping } from 'sdc-app/onboarding/onboard/OnboardConstants.js';
21import { tabsMapping as onboardCatalogTabsMapping } from 'sdc-app/onboarding/onboard/onboardingCatalog/OnboardingCatalogConstants.js';
22import { FilterFactory } from 'test-utils/factories/onboard/FilterFactories.js';
svishnev57c5c4a2018-04-22 14:14:31 +030023import mockRest from 'test-utils/MockRest.js';
24import {
25 itemStatus,
26 versionStatus
27} from 'sdc-app/common/helpers/ItemsHelperConstants.js';
AviZi280f8012017-06-09 02:39:56 +030028
29describe('Onboard Module Tests', () => {
svishnevea5e43c2018-04-15 09:06:57 +030030 it('should return default state', () => {
31 const store = storeCreator();
32 const expectedStore = OnboardStoreFactory.build();
33 expect(store.getState().onboard).toEqual(expectedStore);
34 });
AviZi280f8012017-06-09 02:39:56 +030035
svishnevea5e43c2018-04-15 09:06:57 +030036 it('should change active tab to Catalog', () => {
37 const store = storeCreator();
38 const expectedStore = OnboardStoreFactory.build({
39 activeTab: onboardTabsMapping.CATALOG,
40 filter: FilterFactory.build({ versionStatus: 'Certified' })
41 });
svishnev57c5c4a2018-04-22 14:14:31 +030042
43 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
44 expect(baseUrl).toEqual(
45 `/onboarding-api/v1.0/items?&itemStatus=${
46 itemStatus.ACTIVE
47 }&versionStatus=${versionStatus.CERTIFIED}`
48 );
49 expect(data).toEqual(undefined);
50 expect(options).toEqual(undefined);
51 return { results: [] };
52 });
53
svishnevea5e43c2018-04-15 09:06:57 +030054 OnboardActionHelper.changeActiveTab(
55 store.dispatch,
56 onboardTabsMapping.CATALOG
57 );
58 expect(store.getState().onboard).toEqual(expectedStore);
59 });
AviZi280f8012017-06-09 02:39:56 +030060
svishnevea5e43c2018-04-15 09:06:57 +030061 it('should change searchValue', () => {
62 const store = storeCreator();
63 const expectedStore = OnboardStoreFactory.build({
64 searchValue: 'hello'
65 });
66 OnboardActionHelper.changeSearchValue(store.dispatch, 'hello');
67 expect(store.getState().onboard).toEqual(expectedStore);
68 });
AviZi280f8012017-06-09 02:39:56 +030069
svishnevea5e43c2018-04-15 09:06:57 +030070 it('should clear searchValue', () => {
71 const store = storeCreator();
72 const expectedStore = OnboardStoreFactory.build();
73 OnboardActionHelper.changeSearchValue(store.dispatch, 'hello');
74 OnboardActionHelper.clearSearchValue(store.dispatch);
75 expect(store.getState().onboard).toEqual(expectedStore);
76 });
AviZi280f8012017-06-09 02:39:56 +030077
svishnevea5e43c2018-04-15 09:06:57 +030078 it('should reset store', () => {
79 const store = storeCreator();
80 const expectedStore = OnboardStoreFactory.build();
81 OnboardActionHelper.changeSearchValue(store.dispatch, 'hello');
svishnev57c5c4a2018-04-22 14:14:31 +030082
83 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
84 expect(baseUrl).toEqual(
85 `/onboarding-api/v1.0/items?&itemStatus=${
86 itemStatus.ACTIVE
87 }&versionStatus=${versionStatus.CERTIFIED}`
88 );
89 expect(data).toEqual(undefined);
90 expect(options).toEqual(undefined);
91 return { results: [] };
92 });
93
svishnevea5e43c2018-04-15 09:06:57 +030094 OnboardActionHelper.changeActiveTab(
95 store.dispatch,
96 onboardTabsMapping.CATALOG
97 );
98 OnboardingCatalogActionHelper.changeActiveTab(
99 store.dispatch,
100 onboardCatalogTabsMapping.ACTIVE
101 );
svishnev57c5c4a2018-04-22 14:14:31 +0300102
svishnevea5e43c2018-04-15 09:06:57 +0300103 OnboardActionHelper.resetOnboardStore(store.dispatch, 'hello');
104 expect(store.getState().onboard).toEqual(expectedStore);
105 });
AviZi280f8012017-06-09 02:39:56 +0300106});