diff --git a/client/src/app/admin/instance/components/footer-logo-form.component.spec.ts b/client/src/app/admin/instance/components/footer-logo-form.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..b4b47bb8cc2fb0348d51545a970899752455a5cf --- /dev/null +++ b/client/src/app/admin/instance/components/footer-logo-form.component.spec.ts @@ -0,0 +1,36 @@ +/** + * 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 { FooterLogoFormComponent } from './footer-logo-form.component'; + +describe('[admin][instance][Components] FooterLogoFormComponent', () => { + let component: FooterLogoFormComponent; + let fixture: ComponentFixture<FooterLogoFormComponent>; + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + FooterLogoFormComponent + ], + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule + ], + }) + fixture = TestBed.createComponent(FooterLogoFormComponent); + component = fixture.componentInstance; + }); + + it('should create component', () => { + expect(component).toBeTruthy(); + }); +}) + diff --git a/client/src/app/admin/instance/components/footer-logos-list.component.spec.ts b/client/src/app/admin/instance/components/footer-logos-list.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..d082002a347deb45d272b5c17037977cb275ebf4 --- /dev/null +++ b/client/src/app/admin/instance/components/footer-logos-list.component.spec.ts @@ -0,0 +1,68 @@ +/** + * 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 { FormArray, FormControl, FormGroup, ReactiveFormsModule, UntypedFormGroup } from '@angular/forms'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { FooterLogosListComponent } from './footer-logos-list.component'; + +@Component({ + selector: 'app-footer-logo-form', +}) +export class FooterLogoFormComponent { + form = new FormGroup({}); +} +describe('[admin][instance][Components] FooterLogosListComponent', () => { + let component: FooterLogosListComponent; + let fixture: ComponentFixture<FooterLogosListComponent>; + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + FooterLogosListComponent, + FooterLogoFormComponent + ], + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule + ], + }) + fixture = TestBed.createComponent(FooterLogosListComponent); + component = fixture.componentInstance; + component.form = new FormArray([]); + component.logoList = [{ display: 10, file: 'test', href: 'test', title: 'test' }]; + component.newLogoFormGroup = new FormGroup({}); + fixture.detectChanges(); + }); + + it('should create component', () => { + expect(component).toBeTruthy(); + }); + it(' buildFormGroup() should return an instance of UntypedFormGroup', () => { + let result = component.buildFormGroup(); + expect(result instanceof UntypedFormGroup).toBe(true); + }); + it('addLogo() should add newLogoFormGroup in form', () => { + let spyOnForm = jest.spyOn(component.form, 'markAsDirty'); + let spyOnBuildFormGroup = jest.spyOn(component, 'buildFormGroup'); + expect(component.form.controls.length).toEqual(1); + component.addLogo(); + expect(spyOnBuildFormGroup).toHaveBeenCalledTimes(1); + expect(spyOnForm).toHaveBeenCalledTimes(1); + expect(component.form.controls.length).toEqual(2); + }); + it('removeLogo(index: number) should remove a logo from form', () => { + let spyOnForm = jest.spyOn(component.form, 'markAsDirty'); + expect(component.form.controls.length).toEqual(1); + component.removeLogo(0); + expect(spyOnForm).toHaveBeenCalledTimes(1); + expect(component.form.controls.length).toEqual(0); + }) +}) + diff --git a/client/src/app/admin/instance/components/index.spec.ts b/client/src/app/admin/instance/components/index.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..af398f1a216ed8031d8d030e00c067311432d915 --- /dev/null +++ b/client/src/app/admin/instance/components/index.spec.ts @@ -0,0 +1,15 @@ + +/** + * 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 { dummiesComponents } from './index'; +describe('[admin][instance][Components] index', () => { + it('Test index components', () => { + expect(dummiesComponents.length).toEqual(6); + }); +}); diff --git a/client/src/app/admin/instance/components/instance-card.component.spec.ts b/client/src/app/admin/instance/components/instance-card.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..d856f55d2a921eb06e63ab4f439b2840a1ce3147 --- /dev/null +++ b/client/src/app/admin/instance/components/instance-card.component.spec.ts @@ -0,0 +1,33 @@ +/** + * 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 { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { InstanceCardComponent } from './instance-card.component'; + +describe('[admin][instance][Components] InstanceCardComponent', () => { + let component: InstanceCardComponent; + let fixture: ComponentFixture<InstanceCardComponent>; + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + InstanceCardComponent + ], + imports: [ + BrowserAnimationsModule, + ], + }) + fixture = TestBed.createComponent(InstanceCardComponent); + component = fixture.componentInstance; + }); + + it('should create component', () => { + expect(component).toBeTruthy(); + }); +}) + diff --git a/client/src/app/admin/instance/components/instance-form.component.spec.ts b/client/src/app/admin/instance/components/instance-form.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..197cf6f9eca118976e58cedf6fe23f4d826d4dc9 --- /dev/null +++ b/client/src/app/admin/instance/components/instance-form.component.spec.ts @@ -0,0 +1,172 @@ +/** + * 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, UntypedFormGroup } from '@angular/forms'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { Instance, Logo } from 'src/app/metamodel/models'; +import { InstanceFormComponent } from './instance-form.component'; + +describe('[admin][instance][Components] InstanceFormComponent', () => { + let component: InstanceFormComponent; + let fixture: ComponentFixture<InstanceFormComponent>; + let instance: Instance; + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + InstanceFormComponent + ], + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule + ], + }) + fixture = TestBed.createComponent(InstanceFormComponent); + component = fixture.componentInstance; + component.instance = { ...instance, label: 'test' }; + fixture.detectChanges(); + }); + + it('should create component', () => { + expect(component).toBeTruthy(); + }); + it('ngOnInit() should enable search_multiple_all_datasets_selected and search_multiple_label', () => { + component.form.controls.search_multiple_allowed.setValue(true); + expect(component.form.controls.search_multiple_label.enabled).toBe(false); + expect(component.form.controls.search_multiple_all_datasets_selected.enabled).toBe(false); + component.ngOnInit(); + expect(component.form.controls.search_multiple_label.enabled).toBe(true); + expect(component.form.controls.search_multiple_all_datasets_selected.enabled).toBe(true); + }); + it('ngOnInit() should enable documentation_label', () => { + component.form.controls.documentation_allowed.setValue(true); + expect(component.form.controls.documentation_label.enabled).toBe(false); + component.ngOnInit(); + expect(component.form.controls.documentation_label.enabled).toBe(true); + }); + it('isDataPathEmpty() should return false', () => { + component.form.controls.data_path.setValue('test'); + let result = component.isDataPathEmpty(); + expect(result).toBe(false); + }); + it('isFilesPathEmpty() should return false', () => { + component.form.controls.files_path.setValue('test'); + let result = component.isFilesPathEmpty(); + expect(result).toBe(false); + }); + it('onChangeFilesPath(path: string) should call emit on loadRootDirectory', () => { + let spy = jest.spyOn(component.loadRootDirectory, 'emit'); + component.form.controls.data_path.setValue('test_data_path'); + component.form.controls.files_path.setValue('test_files_path'); + + component.onChangeFilesPath('test_path'); + let param = `${component.form.controls.data_path.value}${'test_path'}` + expect(spy).toHaveBeenCalledWith(param); + expect(spy).toHaveBeenCalledTimes(1); + }); + it('onChangeFileSelect(path: string) should call emit on loadRootDirectory', () => { + let spy = jest.spyOn(component.loadRootDirectory, 'emit'); + component.onChangeFileSelect('test_path'); + let param = `${component.form.controls.data_path.value}${component.form.controls.files_path.value}${'test_path'}` + expect(spy).toHaveBeenCalledWith(param); + expect(spy).toHaveBeenCalledTimes(1); + }); + it('getHomeConfigFormGroup should return an instance of UntypedFormGroup', () => { + let result = component.getHomeConfigFormGroup(); + expect(result).toEqual(component.form.controls.home_component_config as UntypedFormGroup); + }); + it('checkDisableSearchByCriteriaAllowed() should enable search_by_criteria_label', () => { + component.form.controls.search_by_criteria_allowed.setValue(true); + component.form.controls.search_by_criteria_label.disable(); + expect(component.form.controls.search_by_criteria_label.enabled).toBe(false); + component.checkDisableSearchByCriteriaAllowed(); + expect(component.form.controls.search_by_criteria_label.enabled).toBe(true); + + }); + it('checkDisableSearchByCriteriaAllowed() should desable search_by_criteria_label', () => { + component.form.controls.search_by_criteria_allowed.setValue(false); + component.form.controls.search_by_criteria_label.enable(); + expect(component.form.controls.search_by_criteria_label.enabled).toBe(true); + component.checkDisableSearchByCriteriaAllowed(); + expect(component.form.controls.search_by_criteria_label.enabled).toBe(false); + + }); + it('checkDisableAllDatasetsSelected() should enable search_multiple_label and search_multiple_all_datasets_selected ', () => { + component.form.controls.search_multiple_allowed.setValue(true); + component.form.controls.search_multiple_label.disable(); + component.form.controls.search_multiple_all_datasets_selected.disable(); + expect(component.form.controls.search_multiple_label.enabled).toBe(false); + expect(component.form.controls.search_multiple_all_datasets_selected.enabled).toBe(false); + component.checkDisableAllDatasetsSelected(); + expect(component.form.controls.search_multiple_label.enabled).toBe(true); + expect(component.form.controls.search_multiple_all_datasets_selected.enabled).toBe(true); + + }); + it('checkDisableDocumentationAllowed() should desable search_multiple_label and search_multiple_all_datasets_selected ', () => { + component.form.controls.search_multiple_allowed.setValue(false); + component.form.controls.search_multiple_label.enable(); + component.form.controls.search_multiple_all_datasets_selected.enable(); + expect(component.form.controls.search_multiple_label.enabled).toBe(true); + expect(component.form.controls.search_multiple_all_datasets_selected.enabled).toBe(true); + component.checkDisableAllDatasetsSelected(); + expect(component.form.controls.search_multiple_label.enabled).toBe(false); + expect(component.form.controls.search_multiple_all_datasets_selected.enabled).toBe(false); + + }); + it('checkDisableSearchByCriteriaAllowed() should enable documentation_label', () => { + component.form.controls.documentation_allowed.setValue(true); + component.form.controls.documentation_label.disable(); + expect(component.form.controls.documentation_label.enabled).toBe(false); + component.checkDisableDocumentationAllowed(); + expect(component.form.controls.documentation_label.enabled).toBe(true); + + }); + it('checkDisableSearchByCriteriaAllowed() should desable documentation_label', () => { + component.form.controls.documentation_allowed.setValue(false); + component.form.controls.documentation_label.enable(); + expect(component.form.controls.documentation_label.enabled).toBe(true); + component.checkDisableDocumentationAllowed(); + expect(component.form.controls.documentation_label.enabled).toBe(false); + + }); + it('getFooterLogoListByDisplay() return a array of logo sorted by display ', () => { + + let footer_logos: Logo[] = [ + { display: 4, file: 'test1', title: 'test1', href: 'test1' }, + { display: 2, file: 'test2', title: 'test2', href: 'test2' }, + { display: 3, file: 'test3', title: 'test3', href: 'test4' }, + ]; + component.instance.footer_logos = footer_logos; + let result = component.getFooterLogoListByDisplay(); + let expected = [ + { display: 2, file: 'test2', title: 'test2', href: 'test2' }, + { display: 3, file: 'test3', title: 'test3', href: 'test4' }, + { display: 4, file: 'test1', title: 'test1', href: 'test1' }, + ] + expect(result).toEqual(expected); + + }); + it('submit() should emit instance and form.getRawValue()', () => { + let spyOnOnSubmit = jest.spyOn(component.onSubmit, 'emit'); + let spyOnForm = jest.spyOn(component.form, 'markAsPristine'); + component.submit(); + expect(spyOnOnSubmit).toHaveBeenCalledTimes(1); + expect(spyOnOnSubmit).toHaveBeenCalledWith({ ...component.instance, ...component.form.getRawValue() }); + expect(spyOnForm).toHaveBeenCalledTimes(1); + + }); + it('submit() should emit form.getRawValue()', () => { + let spyOnOnSubmit = jest.spyOn(component.onSubmit, 'emit'); + component.instance = null; + component.submit(); + expect(spyOnOnSubmit).toHaveBeenCalledTimes(1); + expect(spyOnOnSubmit).toHaveBeenCalledWith({ ...component.form.getRawValue() }); + }); + +}) + diff --git a/client/src/app/admin/instance/components/instance-group-form.component.spec.ts b/client/src/app/admin/instance/components/instance-group-form.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..334e2accde393ec56f4e62cf4599c22706b7c1d1 --- /dev/null +++ b/client/src/app/admin/instance/components/instance-group-form.component.spec.ts @@ -0,0 +1,93 @@ +/** + * 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 { Instance } from 'src/app/metamodel/models'; +import { InstanceGroupFormComponent } from './instance-group-form.component'; + +describe('[admin][instance][Components] InstanceGroupFormComponent', () => { + let component: InstanceGroupFormComponent; + let fixture: ComponentFixture<InstanceGroupFormComponent>; + let instance: Instance; + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + InstanceGroupFormComponent + ], + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule + ], + }) + fixture = TestBed.createComponent(InstanceGroupFormComponent); + component = fixture.componentInstance; + component.instanceGroup = { id: 1, instances: [], role: 'test' }; + component.instanceList = [ + { ...instance, name: 'test1' }, + { ...instance, name: 'test2' }, + { ...instance, name: 'test3' }, + { ...instance, name: 'test4' } + ] + fixture.detectChanges(); + }); + + it('should create component', () => { + expect(component).toBeTruthy(); + }); + it('submit() should emit instanceGroup and form.value and instanceGroupInstances', () => { + let spyOnOnSubmit = jest.spyOn(component.onSubmit, 'emit'); + component.submit(); + expect(spyOnOnSubmit).toHaveBeenCalledTimes(1); + expect(spyOnOnSubmit).toHaveBeenCalledWith({ + ...component.instanceGroup, + ...component.form.value, + instances: component.instanceGroupInstances + }); + }); + it('submit() should emit form.value and instanceGroupInstances', () => { + let spyOnOnSubmit = jest.spyOn(component.onSubmit, 'emit'); + component.instanceGroup = null; + component.submit(); + expect(spyOnOnSubmit).toHaveBeenCalledTimes(1); + expect(spyOnOnSubmit).toHaveBeenCalledWith({ ...component.form.value, instances: component.instanceGroupInstances }); + }); + it('getAvailableInstances() should return a array of instances that don t have their names in instanceGroupInstances', () => { + component.instanceGroupInstances = ['test1', 'test2']; + let expected = [{ ...instance, name: 'test3' }, { ...instance, name: 'test4' }]; + let result = component.getAvailableInstances(); + expect(result).toEqual(expected); + }); + it('addInstances() should add the availableInstanceSelected in instanceGroupInstances array', () => { + let selectElement = { + options: [ + { selected: true, value: 'test1' } + ], + } + let spy = jest.spyOn(component.form, 'markAsDirty'); + expect(component.instanceGroupInstances.length).toEqual(0); + component.addInstances(selectElement); + expect(component.instanceGroupInstances.length).toEqual(1); + expect(spy).toHaveBeenCalledTimes(1); + }); + it('removeInstances() should remove the instanceGroupInstancesSelected from instanceGroupInstances array', () => { + let selectElement = { + options: [ + { selected: true, value: 'test1' } + ], + } + component.instanceGroupInstances = ['test1', 'test2']; + let spy = jest.spyOn(component.form, 'markAsDirty'); + expect(component.instanceGroupInstances.length).toEqual(2); + component.removeInstances(selectElement); + expect(component.instanceGroupInstances.length).toEqual(1); + expect(spy).toHaveBeenCalledTimes(1); + }); +}) + diff --git a/client/src/app/admin/instance/components/instance-group-table.component.spec.ts b/client/src/app/admin/instance/components/instance-group-table.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..9e53a1ab84dfe19c116ab5a32809b605f73147e2 --- /dev/null +++ b/client/src/app/admin/instance/components/instance-group-table.component.spec.ts @@ -0,0 +1,33 @@ +/** + * 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 { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { InstanceGroupTableComponent } from './instance-group-table.component'; + +describe('[admin][instance][Components] InstanceGroupTableComponent', () => { + let component: InstanceGroupTableComponent; + let fixture: ComponentFixture<InstanceGroupTableComponent>; + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + InstanceGroupTableComponent + ], + imports: [ + BrowserAnimationsModule, + ], + }) + fixture = TestBed.createComponent(InstanceGroupTableComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + it('should create component', () => { + expect(component).toBeTruthy(); + }); +}) +