2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * 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.
16 import { storeCreator } from 'sdc-app/AppStore.js';
17 import { OnboardStoreFactory } from 'test-utils/factories/onboard/OnboardFactories.js';
18 import OnboardActionHelper from 'sdc-app/onboarding/onboard/OnboardActionHelper.js';
19 import OnboardingCatalogActionHelper from 'sdc-app/onboarding/onboard/onboardingCatalog/OnboardingCatalogActionHelper.js';
20 import { tabsMapping as onboardTabsMapping } from 'sdc-app/onboarding/onboard/OnboardConstants.js';
21 import { tabsMapping as onboardCatalogTabsMapping } from 'sdc-app/onboarding/onboard/onboardingCatalog/OnboardingCatalogConstants.js';
22 import { FilterFactory } from 'test-utils/factories/onboard/FilterFactories.js';
23 import mockRest from 'test-utils/MockRest.js';
27 } from 'sdc-app/common/helpers/ItemsHelperConstants.js';
29 describe('Onboard Module Tests', () => {
30 it('should return default state', () => {
31 const store = storeCreator();
32 const expectedStore = OnboardStoreFactory.build();
33 expect(store.getState().onboard).toEqual(expectedStore);
36 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' })
43 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
44 expect(baseUrl).toEqual(
45 `/onboarding-api/v1.0/items?&itemStatus=${
47 }&versionStatus=${versionStatus.CERTIFIED}`
49 expect(data).toEqual(undefined);
50 expect(options).toEqual(undefined);
51 return { results: [] };
54 OnboardActionHelper.changeActiveTab(
56 onboardTabsMapping.CATALOG
58 expect(store.getState().onboard).toEqual(expectedStore);
61 it('should change searchValue', () => {
62 const store = storeCreator();
63 const expectedStore = OnboardStoreFactory.build({
66 OnboardActionHelper.changeSearchValue(store.dispatch, 'hello');
67 expect(store.getState().onboard).toEqual(expectedStore);
70 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);
78 it('should reset store', () => {
79 const store = storeCreator();
80 const expectedStore = OnboardStoreFactory.build();
81 OnboardActionHelper.changeSearchValue(store.dispatch, 'hello');
83 mockRest.addHandler('fetch', ({ data, options, baseUrl }) => {
84 expect(baseUrl).toEqual(
85 `/onboarding-api/v1.0/items?&itemStatus=${
87 }&versionStatus=${versionStatus.CERTIFIED}`
89 expect(data).toEqual(undefined);
90 expect(options).toEqual(undefined);
91 return { results: [] };
94 OnboardActionHelper.changeActiveTab(
96 onboardTabsMapping.CATALOG
98 OnboardingCatalogActionHelper.changeActiveTab(
100 onboardCatalogTabsMapping.ACTIVE
103 OnboardActionHelper.resetOnboardStore(store.dispatch, 'hello');
104 expect(store.getState().onboard).toEqual(expectedStore);