From f661f510f2f938d7dbdf15d368b9221ca830eeea Mon Sep 17 00:00:00 2001 From: dangapay <divin.angapay@lam.fr> Date: Fri, 21 Oct 2022 16:47:48 +0200 Subject: [PATCH] add test for admin/instance/dataset/components/output-category --- .../add-output-category.component.spec.ts | 56 +++++++++++++++++ .../edit-output-category.component.spec.ts | 56 +++++++++++++++++ .../components/output-category/index.spec.ts | 20 +++++++ .../output-category-form.component.spec.ts | 60 +++++++++++++++++++ .../output-category-list.component.spec.ts | 43 +++++++++++++ 5 files changed, 235 insertions(+) create mode 100644 client/src/app/admin/instance/dataset/components/output-category/add-output-category.component.spec.ts create mode 100644 client/src/app/admin/instance/dataset/components/output-category/edit-output-category.component.spec.ts create mode 100644 client/src/app/admin/instance/dataset/components/output-category/index.spec.ts create mode 100644 client/src/app/admin/instance/dataset/components/output-category/output-category-form.component.spec.ts create mode 100644 client/src/app/admin/instance/dataset/components/output-category/output-category-list.component.spec.ts diff --git a/client/src/app/admin/instance/dataset/components/output-category/add-output-category.component.spec.ts b/client/src/app/admin/instance/dataset/components/output-category/add-output-category.component.spec.ts new file mode 100644 index 00000000..2ee1382a --- /dev/null +++ b/client/src/app/admin/instance/dataset/components/output-category/add-output-category.component.spec.ts @@ -0,0 +1,56 @@ +/** + * 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 { TemplateRef } from '@angular/core'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ReactiveFormsModule } from '@angular/forms'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; +import { AddOutputCategoryComponent } from './add-output-category.component'; + +describe('[admin][instance][dataset][components][output-category] AddOutputCategoryComponent', () => { + let component: AddOutputCategoryComponent; + let fixture: ComponentFixture<AddOutputCategoryComponent>; + const modalServiceStub = { + show: jest.fn(), + }; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + AddOutputCategoryComponent, + ], + providers: [ + BsModalRef, + { provide: BsModalService, useValue: modalServiceStub } + ], + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule + ], + }); + fixture = TestBed.createComponent(AddOutputCategoryComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + + it('should call modalRef.show(template)', () => { + let template: TemplateRef<any> = null; + let spy = jest.spyOn(modalServiceStub, 'show'); + component.openModal(template); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(template); + }); + +}); + diff --git a/client/src/app/admin/instance/dataset/components/output-category/edit-output-category.component.spec.ts b/client/src/app/admin/instance/dataset/components/output-category/edit-output-category.component.spec.ts new file mode 100644 index 00000000..fc840b3a --- /dev/null +++ b/client/src/app/admin/instance/dataset/components/output-category/edit-output-category.component.spec.ts @@ -0,0 +1,56 @@ +/** + * 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 { TemplateRef } from '@angular/core'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ReactiveFormsModule } from '@angular/forms'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; +import { EditOutputCategoryComponent } from './edit-output-category.component'; + +describe('[admin][instance][dataset][components][output-category] EditOutputCategoryComponent', () => { + let component: EditOutputCategoryComponent; + let fixture: ComponentFixture<EditOutputCategoryComponent>; + const modalServiceStub = { + show: jest.fn(), + }; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + EditOutputCategoryComponent, + ], + providers: [ + BsModalRef, + { provide: BsModalService, useValue: modalServiceStub } + ], + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule + ], + }); + fixture = TestBed.createComponent(EditOutputCategoryComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + + it('should call modalRef.show(template)', () => { + let template: TemplateRef<any> = null; + let spy = jest.spyOn(modalServiceStub, 'show'); + component.openModal(template); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(template); + }); + +}); + diff --git a/client/src/app/admin/instance/dataset/components/output-category/index.spec.ts b/client/src/app/admin/instance/dataset/components/output-category/index.spec.ts new file mode 100644 index 00000000..c9aa822e --- /dev/null +++ b/client/src/app/admin/instance/dataset/components/output-category/index.spec.ts @@ -0,0 +1,20 @@ +/** + * 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 { outputCategoryComponents } from './index'; + + describe('[admin][instance][dataset][components][output-category] index', () => { + it('should test output-category index components', () => { + expect(outputCategoryComponents.length).toEqual(4); + }); + }); + + + + \ No newline at end of file diff --git a/client/src/app/admin/instance/dataset/components/output-category/output-category-form.component.spec.ts b/client/src/app/admin/instance/dataset/components/output-category/output-category-form.component.spec.ts new file mode 100644 index 00000000..6689a827 --- /dev/null +++ b/client/src/app/admin/instance/dataset/components/output-category/output-category-form.component.spec.ts @@ -0,0 +1,60 @@ +/** + * 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 { FileInfo } from 'src/app/admin/store/models'; +import { OutputCategoryFormComponent } from './output-category-form.component'; + +describe('[admin][instance][dataset][components][output-category] OutputCategoryFormComponent', () => { + let component: OutputCategoryFormComponent; + let fixture: ComponentFixture<OutputCategoryFormComponent>; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + OutputCategoryFormComponent, + ], + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule + ], + }); + fixture = TestBed.createComponent(OutputCategoryFormComponent); + component = fixture.componentInstance; + component.outputCategory = { + display: 10, + id: 1, + id_output_family: 1, + label: 'test' + }; + fixture.detectChanges(); + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + + it('submit() should emit outputCategory and form.value()', () => { + let spy = jest.spyOn(component.onSubmit, 'emit'); + component.submit(); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith({ ...component.outputCategory, ...component.form.value }); + }); + it('submit() should emit only form.value()', () => { + let spy = jest.spyOn(component.onSubmit, 'emit'); + component.outputCategory = null; + component.submit(); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith({ ...component.form.value }); + }) + +}); + diff --git a/client/src/app/admin/instance/dataset/components/output-category/output-category-list.component.spec.ts b/client/src/app/admin/instance/dataset/components/output-category/output-category-list.component.spec.ts new file mode 100644 index 00000000..055940de --- /dev/null +++ b/client/src/app/admin/instance/dataset/components/output-category/output-category-list.component.spec.ts @@ -0,0 +1,43 @@ +/** + * 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 { ReactiveFormsModule } from '@angular/forms'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { OutputCategoryListComponent } from './output-category-list.component'; +@Component({ + selector: 'app-add-output-category', +}) +class AddOutputCategoryComponent { } + +describe('[admin][instance][dataset][components][output-category] OutputCategoryListComponent', () => { + let component: OutputCategoryListComponent; + let fixture: ComponentFixture<OutputCategoryListComponent>; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + OutputCategoryListComponent, + ], + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule + ], + }); + fixture = TestBed.createComponent(OutputCategoryListComponent); + component = fixture.componentInstance; + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + +}); + + -- GitLab