diff options
author | Yoav Schneiderman <yoav.schneiderman@intl.att.com> | 2019-12-18 21:04:38 +0200 |
---|---|---|
committer | Yoav Schneiderman <yoav.schneiderman@intl.att.com> | 2019-12-22 14:01:45 +0200 |
commit | 4c87ecaa8cce40f078f8540a15928e7e805e4ef7 (patch) | |
tree | f31c55200451d13f108c8583b8d275ae7a7c8bab /vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/control.generator.util.service.spec.ts | |
parent | 54af5cdca044c7b486f02f4163d16c39e990f701 (diff) |
Refactor Generic Generators
Issue-ID: VID-731
Signed-off-by: Yoav Schneiderman <yoav.schneiderman@intl.att.com>
Change-Id: Ib851ff4056d64e12eaf415c5d689c832196ec8b0
Signed-off-by: Yoav Schneiderman <yoav.schneiderman@intl.att.com>
Diffstat (limited to 'vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/control.generator.util.service.spec.ts')
-rw-r--r-- | vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/control.generator.util.service.spec.ts | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/control.generator.util.service.spec.ts b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/control.generator.util.service.spec.ts new file mode 100644 index 000000000..9aefa98b8 --- /dev/null +++ b/vid-webpack-master/src/app/shared/components/genericForm/formControlsServices/control.generator.util.service.spec.ts @@ -0,0 +1,112 @@ +import {getTestBed, TestBed} from '@angular/core/testing'; +import {AaiService} from "../../../services/aaiService/aai.service"; +import {FeatureFlagsService} from "../../../services/featureFlag/feature-flags.service"; +import {ControlGeneratorUtil} from "./control.generator.util.service"; +import {NgRedux} from '@angular-redux/store'; +import each from "jest-each"; +import {HttpClientTestingModule, HttpTestingController} from '@angular/common/http/testing'; +import {FileFormControl} from "../../../models/formControlModels/fileFormControl.model"; +import {AppState} from "../../../store/reducers"; +import {SelectOption} from "../../../models/selectOption"; +import {SharedControllersService} from "./sharedControlles/shared.controllers.service"; + +describe('Control Generator Util', () => { + let injector; + let service: ControlGeneratorUtil; + let sharedControllersService : SharedControllersService; + let httpMock: HttpTestingController; + let store: NgRedux<AppState>; + + + beforeAll(done => (async () => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + providers: [ControlGeneratorUtil, + SharedControllersService, + AaiService, + {provide:FeatureFlagsService, useClass: MockFeatureFlagsService}, + {provide: NgRedux, useClass: MockAppStore}] + }); + await TestBed.compileComponents(); + + injector = getTestBed(); + service = injector.get(ControlGeneratorUtil); + httpMock = injector.get(HttpTestingController); + sharedControllersService = injector.get(SharedControllersService); + store = injector.get(NgRedux); + + })().then(done).catch(done.fail)); + + + test('given instance, get supp file from getSupplementaryFile ', () => { + const instance = {}; + const suppFileForInstance: FileFormControl = service.getSupplementaryFile(instance); + expect(suppFileForInstance.isVisible).toBeTruthy(); + expect(suppFileForInstance.hiddenFile.length).toBeGreaterThanOrEqual(1); + expect(suppFileForInstance.hiddenFile[0].validations[0].validatorName).toEqual("isFileTooBig"); + }); + + test('concatSupplementaryFile add SupplementaryFile control and hidden file', () => { + + //given + const instance = {}; + const controls = [sharedControllersService.getLegacyRegion(instance)]; + expect(controls).toHaveLength(1); + + //when + const result = service.concatSupplementaryFile(controls, instance); + + //then + expect(controls).toHaveLength(1); //original controls remain the same + + expect(result.map((control) => {return control.controlName})).toEqual([ + "legacyRegion", + "supplementaryFile", + "supplementaryFile_hidden", + "supplementaryFile_hidden_content" + ]); + }); + each([ + [null, false], + [{}, true] + ]). + test('retrieveInstanceIfUpdateMode returns %s if update mode is %s', (expected, isUpdateModalMode) => { + //given + const store= <any>{ + getState() { + return { + global: { + isUpdateModalMode + } + }}}; + const instance = {}; + + //when + let retrievedInstance = service.retrieveInstanceIfUpdateMode (store, instance); + + //then + expect(retrievedInstance).toEqual(expected); + + }); + + test('getRollBackOnFailureOptions', async (done)=> { + service.getRollBackOnFailureOptions().subscribe((rollBackOnFailureOptions : SelectOption[])=>{ + expect(rollBackOnFailureOptions[0].id).toEqual('true'); + expect(rollBackOnFailureOptions[0].name).toEqual('Rollback'); + expect(rollBackOnFailureOptions[1].id).toEqual('false'); + expect(rollBackOnFailureOptions[1].name).toEqual('Don\'t Rollback'); + done(); + }); + }); + + +}); + + +class MockAppStore<T> { + getState() { + return {} + } +} + +class MockFeatureFlagsService {} |