svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016-2018 European Support Limited |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 3 | * |
| 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 |
Yarin Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame] | 7 | * |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Yarin Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame] | 9 | * |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
svishnev | 091edfd | 2018-03-19 12:15:19 +0200 | [diff] [blame] | 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. |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 15 | */ |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 16 | import { storeCreator } from 'sdc-app/AppStore.js'; |
| 17 | import { OnboardStoreFactory } from 'test-utils/factories/onboard/OnboardFactories.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 18 | import OnboardActionHelper from 'sdc-app/onboarding/onboard/OnboardActionHelper.js'; |
| 19 | import OnboardingCatalogActionHelper from 'sdc-app/onboarding/onboard/onboardingCatalog/OnboardingCatalogActionHelper.js'; |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 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'; |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 23 | import mockRest from 'test-utils/MockRest.js'; |
| 24 | import { |
| 25 | itemStatus, |
| 26 | versionStatus |
| 27 | } from 'sdc-app/common/helpers/ItemsHelperConstants.js'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 28 | |
| 29 | describe('Onboard Module Tests', () => { |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 30 | it('should return default state', () => { |
| 31 | const store = storeCreator(); |
| 32 | const expectedStore = OnboardStoreFactory.build(); |
| 33 | expect(store.getState().onboard).toEqual(expectedStore); |
| 34 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 35 | |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 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' }) |
| 41 | }); |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 42 | |
| 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 | |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 54 | OnboardActionHelper.changeActiveTab( |
| 55 | store.dispatch, |
| 56 | onboardTabsMapping.CATALOG |
| 57 | ); |
| 58 | expect(store.getState().onboard).toEqual(expectedStore); |
| 59 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 60 | |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 61 | it('should change searchValue', () => { |
| 62 | const store = storeCreator(); |
Yarin Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame] | 63 | const searchValue = 'test'; |
| 64 | const searchValueObj = { |
| 65 | WORKSPACE: searchValue, |
| 66 | CATALOG: '' |
| 67 | }; |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 68 | const expectedStore = OnboardStoreFactory.build({ |
Yarin Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame] | 69 | searchValue: searchValueObj |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 70 | }); |
Yarin Dekel | 811fb48 | 2018-11-04 15:00:34 +0200 | [diff] [blame] | 71 | OnboardActionHelper.changeSearchValue( |
| 72 | store.dispatch, |
| 73 | searchValue, |
| 74 | 'WORKSPACE' |
| 75 | ); |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 76 | expect(store.getState().onboard).toEqual(expectedStore); |
| 77 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 78 | |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 79 | it('should clear searchValue', () => { |
| 80 | const store = storeCreator(); |
| 81 | const expectedStore = OnboardStoreFactory.build(); |
| 82 | OnboardActionHelper.changeSearchValue(store.dispatch, 'hello'); |
| 83 | OnboardActionHelper.clearSearchValue(store.dispatch); |
| 84 | expect(store.getState().onboard).toEqual(expectedStore); |
| 85 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 86 | |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 87 | it('should reset store', () => { |
| 88 | const store = storeCreator(); |
| 89 | const expectedStore = OnboardStoreFactory.build(); |
| 90 | OnboardActionHelper.changeSearchValue(store.dispatch, 'hello'); |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 91 | |
| 92 | mockRest.addHandler('fetch', ({ data, options, baseUrl }) => { |
| 93 | expect(baseUrl).toEqual( |
| 94 | `/onboarding-api/v1.0/items?&itemStatus=${ |
| 95 | itemStatus.ACTIVE |
| 96 | }&versionStatus=${versionStatus.CERTIFIED}` |
| 97 | ); |
| 98 | expect(data).toEqual(undefined); |
| 99 | expect(options).toEqual(undefined); |
| 100 | return { results: [] }; |
| 101 | }); |
| 102 | |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 103 | OnboardActionHelper.changeActiveTab( |
| 104 | store.dispatch, |
| 105 | onboardTabsMapping.CATALOG |
| 106 | ); |
| 107 | OnboardingCatalogActionHelper.changeActiveTab( |
| 108 | store.dispatch, |
| 109 | onboardCatalogTabsMapping.ACTIVE |
| 110 | ); |
svishnev | 57c5c4a | 2018-04-22 14:14:31 +0300 | [diff] [blame] | 111 | |
svishnev | ea5e43c | 2018-04-15 09:06:57 +0300 | [diff] [blame] | 112 | OnboardActionHelper.resetOnboardStore(store.dispatch, 'hello'); |
| 113 | expect(store.getState().onboard).toEqual(expectedStore); |
| 114 | }); |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 115 | }); |