Skip to content
Snippets Groups Projects
Commit 0d82c864 authored by Angapay Divin's avatar Angapay Divin
Browse files

add test for admin/instance/dataset/components/image

parent 517fa40b
No related branches found
No related tags found
2 merge requests!72Develop,!66Resolve "Tests client: Tester le module dataset de la partie admin->instance"
/**
* 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);
});
});
/**
* 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);
});
});
/**
* 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() });
})
});
/**
* 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();
});
});
/**
* 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment