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

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

parent 247df324
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 { AddFileComponent } from './add-file.component';
describe('[admin][instance][dataset][components][file] AddFileComponent', () => {
let component: AddFileComponent;
let fixture: ComponentFixture<AddFileComponent>;
const modalServiceStub = {
show: jest.fn(),
};
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
AddFileComponent,
],
providers: [
BsModalRef,
{ provide: BsModalService, useValue: modalServiceStub }
],
imports: [
BrowserAnimationsModule,
ReactiveFormsModule
],
});
fixture = TestBed.createComponent(AddFileComponent);
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 { EditFileComponent } from './edit-file.component';
describe('[admin][instance][dataset][components][file] EditFileComponent', () => {
let component: EditFileComponent;
let fixture: ComponentFixture<EditFileComponent>;
const modalServiceStub = {
show: jest.fn(),
};
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
EditFileComponent,
],
providers: [
BsModalRef,
{ provide: BsModalService, useValue: modalServiceStub }
],
imports: [
BrowserAnimationsModule,
ReactiveFormsModule
],
});
fixture = TestBed.createComponent(EditFileComponent);
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 { FileFormComponent } from './file-form.component';
describe('[admin][instance][dataset][components][file] FileFormComponent', () => {
let component: FileFormComponent;
let fixture: ComponentFixture<FileFormComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
FileFormComponent,
],
imports: [
BrowserAnimationsModule,
ReactiveFormsModule
],
});
fixture = TestBed.createComponent(FileFormComponent);
component = fixture.componentInstance;
component.file = { id: 1, file_path: 'test', file_size: 1000, label: 'test', type: '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', () => {
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);
});
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.file, ...component.form.getRawValue()});
} );
it('submit() should emit only form.getRawValue()', () => {
let spy = jest.spyOn(component.onSubmit, 'emit');
component.file = 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 { ComponentFixture, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FileListComponent } from './file-list.component';
describe('[admin][instance][dataset][components][file] FileListComponent', () => {
let component: FileListComponent;
let fixture: ComponentFixture<FileListComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
FileListComponent
],
imports: [
BrowserAnimationsModule,
ReactiveFormsModule
],
});
fixture = TestBed.createComponent(FileListComponent);
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 { fileComponents } from './index';
describe('[admin][instance][dataset][components][file] index', () => {
it('should test file index components', () => {
expect(fileComponents.length).toEqual(4);
});
});
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