From f2550f8c5294ab9b2d0cb623403a3a44d6b45c13 Mon Sep 17 00:00:00 2001 From: dangapay <divin.angapay@lam.fr> Date: Fri, 7 Oct 2022 11:47:24 +0200 Subject: [PATCH] add test for admin/instance/dataset/components/cone-search-config --- .../cone-search-config-form.component.spec.ts | 62 +++++++++++++++++++ .../cone-search-config.component.spec.ts | 62 +++++++++++++++++++ .../cone-search-config/index.spec.ts | 19 ++++++ 3 files changed, 143 insertions(+) create mode 100644 client/src/app/admin/instance/dataset/components/cone-search-config/cone-search-config-form.component.spec.ts create mode 100644 client/src/app/admin/instance/dataset/components/cone-search-config/cone-search-config.component.spec.ts create mode 100644 client/src/app/admin/instance/dataset/components/cone-search-config/index.spec.ts diff --git a/client/src/app/admin/instance/dataset/components/cone-search-config/cone-search-config-form.component.spec.ts b/client/src/app/admin/instance/dataset/components/cone-search-config/cone-search-config-form.component.spec.ts new file mode 100644 index 00000000..206957e4 --- /dev/null +++ b/client/src/app/admin/instance/dataset/components/cone-search-config/cone-search-config-form.component.spec.ts @@ -0,0 +1,62 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ReactiveFormsModule } from '@angular/forms'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { ConeSearchConfigFormComponent } from './cone-search-config-form.component'; + +describe('[admin][instance][dataset][components][cone-search-config] ConeSearchConfigFormComponent', () => { + let component: ConeSearchConfigFormComponent; + let fixture: ComponentFixture<ConeSearchConfigFormComponent>; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + ConeSearchConfigFormComponent + ], + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule + ], + }); + fixture = TestBed.createComponent(ConeSearchConfigFormComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + it('enable() should set (opened, column_ra, colomn_dec, plot_enabled) disabled property to false', () => { + + component.form.controls.enabled.setValue(true); + expect(component.form.controls.opened.disabled).toEqual(true) + expect(component.form.controls.column_ra.disabled).toEqual(true) + expect(component.form.controls.plot_enabled.disabled).toEqual(true) + expect(component.form.controls.column_dec.disabled).toEqual(true); + component.checkConeSearchDisableOpened(); + expect(component.form.controls.opened.disabled).toEqual(false) + expect(component.form.controls.column_ra.disabled).toEqual(false) + expect(component.form.controls.plot_enabled.disabled).toEqual(false) + expect(component.form.controls.column_dec.disabled).toEqual(false); + }); + it('should emit form.getRawValue and call makAsPristine', () => { + let spyOnSubmit = jest.spyOn(component.onSubmit, 'emit'); + let spyForm = jest.spyOn(component.form, 'markAsPristine'); + component.submit(); + expect(spyOnSubmit).toHaveBeenCalledTimes(1); + expect(spyOnSubmit).toHaveBeenCalledWith({ ...component.form.getRawValue() }) + expect(spyForm).toHaveBeenCalledTimes(1); + + + }) + +}); + diff --git a/client/src/app/admin/instance/dataset/components/cone-search-config/cone-search-config.component.spec.ts b/client/src/app/admin/instance/dataset/components/cone-search-config/cone-search-config.component.spec.ts new file mode 100644 index 00000000..6f965156 --- /dev/null +++ b/client/src/app/admin/instance/dataset/components/cone-search-config/cone-search-config.component.spec.ts @@ -0,0 +1,62 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +import { Component } from '@angular/core'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { UntypedFormGroup } from '@angular/forms'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { ConeSearchConfig } from 'src/app/metamodel/models'; +import { ConeSearchConfigComponent } from './cone-search-config.component'; +@Component({ + selector: 'app-cone-search-config-form', + +}) +class ConeSearchConfigFormComponent { + form = new UntypedFormGroup({}); +} +describe('[admin][instance][dataset][components][cone-search-config] ConeSearchConfigComponent', () => { + let component: ConeSearchConfigComponent; + let fixture: ComponentFixture<ConeSearchConfigComponent>; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + ConeSearchConfigComponent, + ConeSearchConfigFormComponent + ], + imports: [ + BrowserAnimationsModule, + ], + }); + fixture = TestBed.createComponent(ConeSearchConfigComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + it(' save(coneSearchConfig: ConeSearchConfig) should emit the current coneSearchConfig, coneSearchConfig in args', () => { + let spy = jest.spyOn(component.editConeSearchConfig, 'emit'); + let coneSearchConfig: ConeSearchConfig = { column_dec: 10, column_ra: 5, enabled: false, id: 1, opened: false, plot_enabled: false }; + component.coneSearchConfig = coneSearchConfig; + let param: ConeSearchConfig = { ...coneSearchConfig, id: 2 } + component.save(param); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith({ ...component.coneSearchConfig, ...param }) + }) + it(' save(coneSearchConfig: ConeSearchConfig) should emit the coneSearchConfig passed in args', () => { + let spy = jest.spyOn(component.addConeSearchConfig, 'emit'); + let coneSearchConfig: ConeSearchConfig = { column_dec: 10, column_ra: 5, enabled: false, id: 1, opened: false, plot_enabled: false }; + component.save(coneSearchConfig); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(coneSearchConfig); + }) + +}) \ No newline at end of file diff --git a/client/src/app/admin/instance/dataset/components/cone-search-config/index.spec.ts b/client/src/app/admin/instance/dataset/components/cone-search-config/index.spec.ts new file mode 100644 index 00000000..e2a4ffa0 --- /dev/null +++ b/client/src/app/admin/instance/dataset/components/cone-search-config/index.spec.ts @@ -0,0 +1,19 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +import { coneSearchConfigComponents } from './index'; + +describe('[admin][instance][dataset][components][cone-search-config] index', () => { + it('Test output index components', () => { + expect(coneSearchConfigComponents.length).toEqual(2); + }); +}); + + + -- GitLab