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

add tests for admin/instance/webpage/components

parent 10d3960a
No related branches found
No related tags found
2 merge requests!72Develop,!62Resolve "Tests client: Tester le module webpage 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 { EditWebpageFamilyComponent } from './edit-webpage-family.component';
describe('[admin][instance][webpage][components]EditWebpageFamilyComponent ', () => {
let component: EditWebpageFamilyComponent;
let fixture: ComponentFixture<EditWebpageFamilyComponent>;
const modalServiceStub = {
show: jest.fn(),
};
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
EditWebpageFamilyComponent,
],
providers: [
BsModalRef,
{ provide: BsModalService, useValue: modalServiceStub }
],
imports: [
BrowserAnimationsModule,
ReactiveFormsModule
],
});
fixture = TestBed.createComponent(EditWebpageFamilyComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('should call modalService.show', () => {
let template: TemplateRef<any> = null;
const 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 { dummiesComponents } from './index';
describe('[[admin][instance][webpage][components]index', () => {
it('Test index components', () => {
expect(dummiesComponents.length).toEqual(6);
});
});
/**
* 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 { WebpageButtonsComponent } from './webpage-buttons.component';
describe('[admin][instance][webpage][components]WebpageButtonsComponent ', () => {
let component: WebpageButtonsComponent;
let fixture: ComponentFixture<WebpageButtonsComponent>;
const modalServiceStub = {
show: jest.fn(),
};
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
WebpageButtonsComponent,
],
providers: [
BsModalRef,
{ provide: BsModalService, useValue: modalServiceStub }
],
imports: [
BrowserAnimationsModule,
ReactiveFormsModule
],
});
fixture = TestBed.createComponent(WebpageButtonsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('should call modalService.show', () => {
let template: TemplateRef<any> = null;
const 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 { WebpageCardComponent } from './webpage-card.component';
describe('[admin][instance][webpage][components]WebpageCardComponent ', () => {
let component: WebpageCardComponent;
let fixture: ComponentFixture<WebpageCardComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
WebpageCardComponent,
],
imports: [
BrowserAnimationsModule,
ReactiveFormsModule
],
});
fixture = TestBed.createComponent(WebpageCardComponent);
component = fixture.componentInstance;
component.webpage = {icon:'', content:'', display: 10, id: 0, id_webpage_family: 0, label:'', title:''};
fixture.detectChanges();
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
});
\ No newline at end of file
/**
* 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 { Pipe, PipeTransform } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { Webpage } from 'src/app/metamodel/models';
import { WebpageFamilyCardComponent } from './webpage-family-card.component';
// mock webpageListByFamilyPipe
@Pipe({name: 'webpageListByFamily'})
class MockPipe implements PipeTransform {
transform(webpageList: Webpage[], idWebpageFamily: number): Webpage[] {
return webpageList.filter(webpage => webpage.id_webpage_family === idWebpageFamily);
}
}
describe('[admin][instance][webpage][components] WebpageFamilyCardComponent ', () => {
let component: WebpageFamilyCardComponent;
let fixture: ComponentFixture<WebpageFamilyCardComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
WebpageFamilyCardComponent,
MockPipe
],
imports: [
BrowserAnimationsModule,
],
});
fixture = TestBed.createComponent(WebpageFamilyCardComponent);
component = fixture.componentInstance;
component.webpageFamily = { display: 10, icon: 'test', id: 0, label: 'webpageFamilly test label' };
component.webpageList = [
{ icon: 'test1', content: 'test1', display: 10, id: 0, id_webpage_family: 0, label: 'test1', title: 'test-title1' },
{ icon: 'test2', content: 'test2', display: 10, id: 0, id_webpage_family: 0, label: 'test2', title: 'test-title2' },
{ icon: 'test3', content: 'test3', display: 10, id: 0, id_webpage_family: 1, label: 'test3', title: 'test-title3' }
];
fixture.detectChanges();
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
it(' nbWebpagesByWebpageFamily should return 2', () => {
expect(component.nbWebpagesByWebpageFamily()).toEqual(2);
})
});
/**
* 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, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { WebpageFamily } from 'src/app/metamodel/models';
import { WebpageFamilyFormComponent } from './webpage-family-form.component';
describe('[admin][instance][webpage][components] WebpageFamilyFormComponent', () => {
let component: WebpageFamilyFormComponent;
let fixture: ComponentFixture<WebpageFamilyFormComponent>;
let spy = null;
let webpageFamilly: WebpageFamily = { display: 10, icon: 'test', id: 0, label: 'webpageFamilly test label' };
let form = new UntypedFormGroup({
label: new UntypedFormControl('test', [Validators.required]),
icon: new UntypedFormControl(null),
display: new UntypedFormControl(10, [Validators.required])
});
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
WebpageFamilyFormComponent,
],
imports: [
BrowserAnimationsModule,
ReactiveFormsModule
]
});
fixture = TestBed.createComponent(WebpageFamilyFormComponent);
component = fixture.componentInstance;
component.webpageFamily = webpageFamilly;
component.form = form;
spy = jest.spyOn(component.onSubmit, 'emit');
fixture.detectChanges();
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('it should emit webpageFamily and form.value', () => {
component.submit();
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith({ ...webpageFamilly, ...form.value })
});
it('it should emit form.value only', () => {
component.webpageFamily = null;
component.submit();
expect(spy).toHaveBeenCalledTimes(1);
expect(spy).toHaveBeenCalledWith({ ...form.value })
});
});
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