From 0d82c8646627da208e9697e7f22506691dfa29e7 Mon Sep 17 00:00:00 2001 From: dangapay <divin.angapay@lam.fr> Date: Fri, 21 Oct 2022 16:31:54 +0200 Subject: [PATCH] add test for admin/instance/dataset/components/image --- .../image/add-image.component.spec.ts | 56 ++++++++++++ .../image/edit-image.component.spec.ts | 56 ++++++++++++ .../image/image-form.component.spec.ts | 88 +++++++++++++++++++ .../image/image-list.component.spec.ts | 45 ++++++++++ .../dataset/components/image/index.spec.ts | 20 +++++ 5 files changed, 265 insertions(+) create mode 100644 client/src/app/admin/instance/dataset/components/image/add-image.component.spec.ts create mode 100644 client/src/app/admin/instance/dataset/components/image/edit-image.component.spec.ts create mode 100644 client/src/app/admin/instance/dataset/components/image/image-form.component.spec.ts create mode 100644 client/src/app/admin/instance/dataset/components/image/image-list.component.spec.ts create mode 100644 client/src/app/admin/instance/dataset/components/image/index.spec.ts diff --git a/client/src/app/admin/instance/dataset/components/image/add-image.component.spec.ts b/client/src/app/admin/instance/dataset/components/image/add-image.component.spec.ts new file mode 100644 index 00000000..bacdb342 --- /dev/null +++ b/client/src/app/admin/instance/dataset/components/image/add-image.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 { AddImageComponent } from './add-image.component'; + +describe('[admin][instance][dataset][components][image] AddImageComponent', () => { + let component: AddImageComponent; + let fixture: ComponentFixture<AddImageComponent>; + const modalServiceStub = { + show: jest.fn(), + }; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + AddImageComponent, + ], + providers: [ + BsModalRef, + { provide: BsModalService, useValue: modalServiceStub } + ], + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule + ], + }); + fixture = TestBed.createComponent(AddImageComponent); + 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/image/edit-image.component.spec.ts b/client/src/app/admin/instance/dataset/components/image/edit-image.component.spec.ts new file mode 100644 index 00000000..57777a94 --- /dev/null +++ b/client/src/app/admin/instance/dataset/components/image/edit-image.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 { EditImageComponent } from './edit-image.component'; + +describe('[admin][instance][dataset][components][image] EditImageComponent', () => { + let component: EditImageComponent; + let fixture: ComponentFixture<EditImageComponent>; + const modalServiceStub = { + show: jest.fn(), + }; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + EditImageComponent, + ], + providers: [ + BsModalRef, + { provide: BsModalService, useValue: modalServiceStub } + ], + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule + ], + }); + fixture = TestBed.createComponent(EditImageComponent); + 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/image/image-form.component.spec.ts b/client/src/app/admin/instance/dataset/components/image/image-form.component.spec.ts new file mode 100644 index 00000000..9f2df998 --- /dev/null +++ b/client/src/app/admin/instance/dataset/components/image/image-form.component.spec.ts @@ -0,0 +1,88 @@ +/** + * 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 { Dataset, Instance } from 'src/app/metamodel/models'; +import { ImageFormComponent } from './image-form.component'; + +describe('[admin][instance][dataset][components][image] ImageFormComponent', () => { + let component: ImageFormComponent; + let fixture: ComponentFixture<ImageFormComponent>; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + ImageFormComponent, + ], + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule + ], + }); + fixture = TestBed.createComponent(ImageFormComponent); + component = fixture.componentInstance; + component.image = { + dec_max: 10, + dec_min: 1, + file_path: 'test_path', + file_size: 1000, + id: 1, + label: 'test', + pmax: 1, + pmin: 0, + ra_max: 3, + ra_min: 1, + stretch: 'test' + }; + let instance: Instance; + let dataset: Dataset; + component.instance = { ...instance, data_path: 'test3' }; + component.dataset = { ...dataset, data_path: 'test_dataset' } + fixture.detectChanges(); + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + it('onChangeFileSelect(path: string) should emit instance.data_path, dataset.data_path and path', () => { + let spy = jest.spyOn(component.loadRootDirectory, 'emit'); + let path: string = 'test1'; + component.onChangeFileSelect(path); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(component.instance.data_path + component.dataset.data_path + path); + }); + it('onFileSelect(fileInfo: FileInfo) should set form.file_size to 2000 and emit file_path value', () => { + let spy = jest.spyOn(component.retrieveFitsImageLimits, 'emit'); + expect(component.form.controls.file_size.value).toEqual(1000); + let fileInfo: FileInfo = { mimetype: 'test', name: 'test', size: 2000, type: 'test' }; + component.onFileSelect(fileInfo) + expect(component.form.controls.file_size.value).toEqual(2000); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith('test_path'); + }); + + it('submit() should emit file and form.getRawValue()', () => { + let spy = jest.spyOn(component.onSubmit, 'emit'); + component.submit(); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith({ ...component.image, ...component.form.getRawValue() }); + }); + it('submit() should emit only form.getRawValue()', () => { + let spy = jest.spyOn(component.onSubmit, 'emit'); + component.image = null; + component.submit(); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith({ ...component.form.getRawValue() }); + }) + +}); + diff --git a/client/src/app/admin/instance/dataset/components/image/image-list.component.spec.ts b/client/src/app/admin/instance/dataset/components/image/image-list.component.spec.ts new file mode 100644 index 00000000..1eac9275 --- /dev/null +++ b/client/src/app/admin/instance/dataset/components/image/image-list.component.spec.ts @@ -0,0 +1,45 @@ +/** + * 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 { ImageListComponent } from './image-list.component'; + +@Component({ + selector: 'app-add-image', +}) +export class AddImageComponent { } + +describe('[admin][instance][dataset][components][image] ImageListComponent', () => { + let component: ImageListComponent; + let fixture: ComponentFixture<ImageListComponent>; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + ImageListComponent, + AddImageComponent + ], + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule + ], + }); + fixture = TestBed.createComponent(ImageListComponent); + component = fixture.componentInstance; + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + +}); + + diff --git a/client/src/app/admin/instance/dataset/components/image/index.spec.ts b/client/src/app/admin/instance/dataset/components/image/index.spec.ts new file mode 100644 index 00000000..3f40ecb4 --- /dev/null +++ b/client/src/app/admin/instance/dataset/components/image/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 { imageComponents } from './index'; + + describe('[admin][instance][dataset][components][image] index', () => { + it('should test image index components', () => { + expect(imageComponents.length).toEqual(4); + }); + }); + + + + \ No newline at end of file -- GitLab