Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 1 | import {FeatureFlagsService, Features} from "./feature-flags.service"; |
| 2 | import {getTestBed, TestBed} from "@angular/core/testing"; |
| 3 | import {NgRedux} from "@angular-redux/store"; |
| 4 | import each from 'jest-each'; |
| 5 | let flagValue:boolean; |
| 6 | |
| 7 | class MockReduxStore<T> { |
| 8 | |
| 9 | getState() { |
| 10 | return { |
| 11 | "global": { |
| 12 | "flags": { |
| 13 | "FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST": flagValue, |
| 14 | }, |
| 15 | }, |
| 16 | } |
| 17 | }; |
| 18 | } |
| 19 | |
| 20 | describe('Feature flags Service', () => { |
| 21 | |
| 22 | let injector; |
| 23 | let service: FeatureFlagsService; |
| 24 | |
| 25 | beforeAll(done => (async () => { |
| 26 | TestBed.configureTestingModule({ |
| 27 | providers: [ |
| 28 | FeatureFlagsService, |
| 29 | {provide: NgRedux, useClass: MockReduxStore}] |
| 30 | }); |
| 31 | await TestBed.compileComponents(); |
| 32 | |
| 33 | injector = getTestBed(); |
| 34 | service = injector.get(FeatureFlagsService); |
| 35 | |
| 36 | })().then(done).catch(done.fail)); |
| 37 | |
| 38 | let flagValueDataProvider = [ |
| 39 | ['flag is true', true], |
| 40 | ['flag is false', false] |
| 41 | ]; |
| 42 | |
| 43 | each(flagValueDataProvider).test("should return the correct flag %s", (desc: string, flag: boolean) => { |
| 44 | flagValue = flag; |
| 45 | expect(service.getFlagState(Features.FLAG_1810_CR_ADD_CLOUD_OWNER_TO_MSO_REQUEST)).toEqual(flag); |
| 46 | }); |
| 47 | }); |