diff --git a/client/src/app/admin/instance/webpage/components/edit-webpage-familly.component.spec.ts b/client/src/app/admin/instance/webpage/components/edit-webpage-familly.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..0568f46b5506f7d6582ec3878b28e7eb594b94bd --- /dev/null +++ b/client/src/app/admin/instance/webpage/components/edit-webpage-familly.component.spec.ts @@ -0,0 +1,62 @@ +/** + * 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); + }) + + +}); diff --git a/client/src/app/admin/instance/webpage/components/index.spec.ts b/client/src/app/admin/instance/webpage/components/index.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..a833d0e390aaf6890789080ee3e06bad23a9b371 --- /dev/null +++ b/client/src/app/admin/instance/webpage/components/index.spec.ts @@ -0,0 +1,17 @@ +/** + * 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); + }); +}); + diff --git a/client/src/app/admin/instance/webpage/components/webpage-buttons.component.spec.ts b/client/src/app/admin/instance/webpage/components/webpage-buttons.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..904ab3901dc5dc3caf39081c8697b4e9e34fe3c4 --- /dev/null +++ b/client/src/app/admin/instance/webpage/components/webpage-buttons.component.spec.ts @@ -0,0 +1,63 @@ +/** + * 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); + }) + + +}); diff --git a/client/src/app/admin/instance/webpage/components/webpage-card.component.spec.ts b/client/src/app/admin/instance/webpage/components/webpage-card.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..eedb83c0d193b78f77328647aab44ef359a9f06e --- /dev/null +++ b/client/src/app/admin/instance/webpage/components/webpage-card.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 { 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 diff --git a/client/src/app/admin/instance/webpage/components/webpage-family-card.component.spec.ts b/client/src/app/admin/instance/webpage/components/webpage-family-card.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..7adda617543634106a1c4c4a59b9c77171c5921b --- /dev/null +++ b/client/src/app/admin/instance/webpage/components/webpage-family-card.component.spec.ts @@ -0,0 +1,62 @@ +/** + * 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); + }) + + +}); diff --git a/client/src/app/admin/instance/webpage/components/webpage-family-form.component.spec.ts b/client/src/app/admin/instance/webpage/components/webpage-family-form.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..c92c9015d359fc2d377cb094fa7141cdd4e7a1f2 --- /dev/null +++ b/client/src/app/admin/instance/webpage/components/webpage-family-form.component.spec.ts @@ -0,0 +1,61 @@ +/** + * 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 }) + }); + +}); +