diff --git a/client/src/app/admin/database/containers/new-database.component.spec.ts b/client/src/app/admin/database/containers/new-database.component.spec.ts index 43ebf1501f219e080f31bee0878eb416d646ebd8..ddafffe83a0d11f8080601db507a16380dfd4bf4 100644 --- a/client/src/app/admin/database/containers/new-database.component.spec.ts +++ b/client/src/app/admin/database/containers/new-database.component.spec.ts @@ -15,7 +15,9 @@ import { MockStore, provideMockStore } from '@ngrx/store/testing'; import { Database } from 'src/app/metamodel/models'; import * as databaseActions from 'src/app/metamodel/actions/database.actions'; import { NewDatabaseComponent } from './new-database.component'; - +import { Component } from '@angular/core'; +@Component({selector: 'app-database-form'}) +class DatabaseForm{} describe('[admin][Database][Containers] NewDatabaseComponent', () => { let component: NewDatabaseComponent; let fixture: ComponentFixture<NewDatabaseComponent>; @@ -24,7 +26,8 @@ describe('[admin][Database][Containers] NewDatabaseComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ declarations: [ - NewDatabaseComponent + NewDatabaseComponent, + DatabaseForm ], imports: [ BrowserAnimationsModule, 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..91c74416de7e5741f66a428732dc8d53d4fa9704 --- /dev/null +++ b/client/src/app/admin/instance/webpage/components/edit-webpage-familly.component.spec.ts @@ -0,0 +1,57 @@ +/** + * 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..921a85bab903dffafdc4684674b506066034ee00 --- /dev/null +++ b/client/src/app/admin/instance/webpage/components/index.spec.ts @@ -0,0 +1,16 @@ +/** + * 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..af9345ce9a8db289475713c071019004890447de --- /dev/null +++ b/client/src/app/admin/instance/webpage/components/webpage-buttons.component.spec.ts @@ -0,0 +1,57 @@ +/** + * 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..380c501d18c244f375c2b86045e1d8497728be35 --- /dev/null +++ b/client/src/app/admin/instance/webpage/components/webpage-card.component.spec.ts @@ -0,0 +1,46 @@ +/** + * 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 { WebpageCardComponent } from './webpage-card.component'; + +@Component({ + selector: 'app-delete-btn', +}) +export class DeleteBtnComponent { } + +describe('[admin][instance][webpage][components]WebpageCardComponent ', () => { + let component: WebpageCardComponent; + let fixture: ComponentFixture<WebpageCardComponent>; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + WebpageCardComponent, + DeleteBtnComponent + ], + 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(); + }); +}); 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..69ca25a3bd1898f2b15811d5f973eefb695be3f7 --- /dev/null +++ b/client/src/app/admin/instance/webpage/components/webpage-family-card.component.spec.ts @@ -0,0 +1,82 @@ +/** + * 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, Pipe, PipeTransform } from '@angular/core'; +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { RouterTestingModule } from '@angular/router/testing'; + +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); + } + +} + +class DummyComponent { } + +@Component({ + selector: 'app-edit-webpage' +}) +class EditWebpageComponent { } + +@Component({ + selector: 'app-delete-btn' +}) +class DeleteBtnComponenent { } + +@Component({ + selector: 'app-webpage-card' +}) +class WebPageComponent { } + +describe('[admin][instance][webpage][components] WebpageFamilyCardComponent ', () => { + let component: WebpageFamilyCardComponent; + let fixture: ComponentFixture<WebpageFamilyCardComponent>; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + WebpageFamilyCardComponent, + MockPipe, + EditWebpageComponent, + DeleteBtnComponenent, + WebPageComponent + ], + imports: [ + BrowserAnimationsModule, + RouterTestingModule.withRoutes([ + { path: 'test', component: DummyComponent } + ]) + ], + }); + 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..09d43a7082fe2538e2e6e86f89a4eb81c7c242fc --- /dev/null +++ b/client/src/app/admin/instance/webpage/components/webpage-family-form.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 { 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; + 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 }) + }); +}); diff --git a/client/src/app/admin/instance/webpage/components/webpage-form.component.spec.ts b/client/src/app/admin/instance/webpage/components/webpage-form.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..f170e45aa20337fcd606d1c1ca6d17b92b72ad48 --- /dev/null +++ b/client/src/app/admin/instance/webpage/components/webpage-form.component.spec.ts @@ -0,0 +1,76 @@ +/** + * 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, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; + +import { Webpage } from 'src/app/metamodel/models'; +import { WebpageFormComponent } from './webpage-form.component'; + +@Component({ selector: 'app-webpage-form-content' }) +class WebpageFormContentComponent { } + +describe('[admin][instance][webpage][components]WebpageFormComponent ', () => { + let component: WebpageFormComponent; + let fixture: ComponentFixture<WebpageFormComponent>; + let spy; + let form = new UntypedFormGroup({ + label: new UntypedFormControl('', [Validators.required]), + icon: new UntypedFormControl(null), + display: new UntypedFormControl('', [Validators.required]), + title: new UntypedFormControl('', [Validators.required]), + content: new UntypedFormControl('', [Validators.required]), + id_webpage_family: new UntypedFormControl('', [Validators.required]) + }); + let webpage: Webpage = { icon: '', content: '', display: 10, id: 0, id_webpage_family: 0, label: '', title: '' }; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + WebpageFormComponent, + WebpageFormContentComponent + ], + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule + ], + }); + fixture = TestBed.createComponent(WebpageFormComponent); + component = fixture.componentInstance; + spy = jest.spyOn(component.onSubmit, 'emit'); + component.webpage = webpage; + component.form = form; + component.idWebpageFamily = 1; + fixture.detectChanges(); + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + + it('should emit with webpage and form.getRawValue()', () => { + component.submit(); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith({ ...component.webpage, ...component.form.getRawValue() }); + + }) + + it('should emit with webpage only', () => { + component.webpage = null; + component.submit(); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith({ ...component.form.getRawValue() }); + }) + + it('should set id_webpage_family form value with idWebpageFamily ', () => { + expect(component.form.controls['id_webpage_family'].value).toEqual(component.idWebpageFamily); + }) +}); diff --git a/client/src/app/admin/instance/webpage/containers/edit-webpage.component.spec.ts b/client/src/app/admin/instance/webpage/containers/edit-webpage.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..257f6a6ae024249300ec6d58c26751d8eee8262a --- /dev/null +++ b/client/src/app/admin/instance/webpage/containers/edit-webpage.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 { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ReactiveFormsModule } from '@angular/forms'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; + +import { MockStore, provideMockStore } from '@ngrx/store/testing'; + +import { Webpage } from 'src/app/metamodel/models'; +import { EditWebpageComponent } from './edit-webpage.component'; +import * as webpageActions from 'src/app/metamodel/actions/webpage.actions'; + +describe('[admin][instance][webpage][containers] EditWebpageComponent ', () => { + let component: EditWebpageComponent; + let fixture: ComponentFixture<EditWebpageComponent>; + let store: MockStore; + let spy; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + EditWebpageComponent + ], + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule + ], + providers: [ + provideMockStore({}), + ] + }); + fixture = TestBed.createComponent(EditWebpageComponent); + component = fixture.componentInstance; + store = TestBed.inject(MockStore); + spy = jest.spyOn(store, 'dispatch'); + fixture.detectChanges(); + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + + it('dispatch webpageActions.editWebPage with the new webpage values', () => { + let webpage: Webpage = { icon: '', content: '', display: 10, id: 0, id_webpage_family: 0, label: '', title: '' }; + component.editWebpage(webpage); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(webpageActions.editWebpage({ webpage })); + }); +}); diff --git a/client/src/app/admin/instance/webpage/containers/new-webpage.component.spec.ts b/client/src/app/admin/instance/webpage/containers/new-webpage.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..44278efd0621ed691ee1e631e8cb886715e4dc8e --- /dev/null +++ b/client/src/app/admin/instance/webpage/containers/new-webpage.component.spec.ts @@ -0,0 +1,70 @@ +/** + * 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 { ActivatedRoute } from '@angular/router'; +import { ReactiveFormsModule } from '@angular/forms'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; + +import { of } from 'rxjs'; +import { MockStore, provideMockStore } from '@ngrx/store/testing'; + +import { Webpage } from 'src/app/metamodel/models'; +import { NewWebpageComponent } from './new-webpage.component'; +import * as webpageActions from 'src/app/metamodel/actions/webpage.actions'; + +describe('[admin][instance][webpage][containers] NewWebpageComponent ', () => { + let component: NewWebpageComponent; + let fixture: ComponentFixture<NewWebpageComponent>; + let store: MockStore; + let spy; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + NewWebpageComponent + ], + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule + ], + providers: [ + { + provide: ActivatedRoute, + useValue: { + queryParamMap: of([{ id_webpage_family: 1 }]), + }, + }, + provideMockStore({}), + ] + }); + fixture = TestBed.createComponent(NewWebpageComponent); + component = fixture.componentInstance; + store = TestBed.inject(MockStore); + spy = jest.spyOn(store, 'dispatch'); + fixture.detectChanges(); + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + + it('dispatch webpageActions.addWebPage with the new webpage values', () => { + let webpage: Webpage = { icon: '', content: '', display: 10, id: 0, id_webpage_family: 0, label: '', title: '' }; + component.addNewWebpage(webpage); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(webpageActions.addWebpage({ webpage })); + }); + + it('idWbPageFamily should be 1', () => { + component.idWebpageFamily.subscribe(value => { + //expect(value).toEqual(1); + }) + }) +}); diff --git a/client/src/app/admin/instance/webpage/containers/webpage-list.component.spec.ts b/client/src/app/admin/instance/webpage/containers/webpage-list.component.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..2fa3c696c419ea19ae29f087e4e1f028bf7710bb --- /dev/null +++ b/client/src/app/admin/instance/webpage/containers/webpage-list.component.spec.ts @@ -0,0 +1,96 @@ +/** + * 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 { RouterTestingModule } from '@angular/router/testing'; +import { Component } from '@angular/core'; +import { ReactiveFormsModule } from '@angular/forms'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; + +import { MockStore, provideMockStore } from '@ngrx/store/testing'; + +import { WebpageListComponent } from './webpage-list.component'; +import { Webpage, WebpageFamily } from 'src/app/metamodel/models'; +import * as webpageFamilyActions from 'src/app/metamodel/actions/webpage-family.actions'; +import * as webpageActions from 'src/app/metamodel/actions/webpage.actions'; + +@Component({ + selector: 'app-webpage-buttons', +}) +class WebpageButtonsComponent { } + +@Component({ + selector: 'app-webpage-card' +}) +class WebpageCardComponent { } + +class DummyComponent { } + +describe('[admin][instance][webpage][containers] WebpageListComponent ', () => { + let component: WebpageListComponent; + let fixture: ComponentFixture<WebpageListComponent>; + let store: MockStore; + let spy; + let webpageFamily: WebpageFamily = { icon: 'test', id: 0, label: 'test', display: 10}; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + WebpageListComponent, + WebpageButtonsComponent, + WebpageCardComponent + ], + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule, + RouterTestingModule.withRoutes([ + { path: 'settings/:collection/edit/:item', component: DummyComponent } + ]) + ], + providers: [ + provideMockStore({}), + ] + }); + fixture = TestBed.createComponent(WebpageListComponent); + component = fixture.componentInstance; + store = TestBed.inject(MockStore); + spy = jest.spyOn(store, 'dispatch'); + fixture.detectChanges(); + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + + it('dispatch webpageFamilyActions.addWebpageFamily with the new webpage values', () => { + component.addWebpageFamily(webpageFamily); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(webpageFamilyActions.addWebpageFamily({webpageFamily})); + }); + + it('dispatch webpageFamilyActions.editWebpageFamily with the new webpage values', () => { + component.editWebpageFamily(webpageFamily); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(webpageFamilyActions.editWebpageFamily({webpageFamily})); + }); + + it('dispatch webpageFamilyActions.deleteWebpageFamily', () => { + + component.deleteWebpageFamily(webpageFamily); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(webpageFamilyActions.deleteWebpageFamily({webpageFamily})); + }); + + it('dispatch webpageFamilyActions.deleteWebpage', () => { + let webpage: Webpage = { icon: '', content: '', display: 10, id: 0, id_webpage_family: 0, label: '', title: '' }; + component.deleteWebpage(webpage); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(webpageActions.deleteWebpage({webpage})); + }); +}); diff --git a/client/src/app/admin/instance/webpage/edit-webpage-title.resolver.spec.ts b/client/src/app/admin/instance/webpage/edit-webpage-title.resolver.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..7db89ec783db26513a64213810f0c671bcce48aa --- /dev/null +++ b/client/src/app/admin/instance/webpage/edit-webpage-title.resolver.spec.ts @@ -0,0 +1,69 @@ +/** + * 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 { TestBed } from '@angular/core/testing'; + +import { MockStore, provideMockStore } from '@ngrx/store/testing'; +import { cold, hot } from 'jasmine-marbles'; + +import { EditWebpageTitleResolver } from './edit-webpage-title.resolver'; +import * as webpageSelector from 'src/app/metamodel/selectors/webpage.selector'; +import * as instanceSelector from 'src/app/metamodel/selectors/instance.selector'; +import { Instance, Webpage } from 'src/app/metamodel/models'; + +describe('[Webpage] EditWebpageTitleResolver', () => { + let editWebpageTitleResolver: EditWebpageTitleResolver; + let store: MockStore; + let mockWebPageSelectorWebPageListIsLoaded; + let mockWebPageSelectorInstanceByRouteName; + let instanceSelectorSelectWebpageByRouteId + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [], + providers: [ + EditWebpageTitleResolver, + provideMockStore({}), + ] + }) + let webpage: Webpage = { icon: '', content: '', display: 10, id: 0, id_webpage_family: 0, label: 'webpage_test_label', title: '' }; + let instance: Instance; + instance = { ...instance, label: 'instance_test_label' } + + store = TestBed.inject(MockStore); + + editWebpageTitleResolver = TestBed.inject(EditWebpageTitleResolver); + mockWebPageSelectorWebPageListIsLoaded = store.overrideSelector(webpageSelector.selectWebpageListIsLoaded, false); + mockWebPageSelectorInstanceByRouteName = store.overrideSelector(instanceSelector.selectInstanceByRouteName, instance); + instanceSelectorSelectWebpageByRouteId = store.overrideSelector(webpageSelector.selectWebpageByRouteId, webpage); + + }); + + it('should be created', () => { + expect(editWebpageTitleResolver).toBeTruthy(); + }); + + it('shou dispatch databaseActions loadDatabaseList action and return databaseListIsLoaded ', () => { + const expected = cold('a', { a: [] }); + let spy = jest.spyOn(store, 'dispatch'); + let result = hot('a', { a: editWebpageTitleResolver.resolve(null, null) }); + + expect(result).toBeObservable(expected); + expect(spy).toHaveBeenCalledTimes(1); + }); + + it('should return label ', () => { + mockWebPageSelectorWebPageListIsLoaded = store.overrideSelector(webpageSelector.selectWebpageListIsLoaded, true); + + let spy = jest.spyOn(store, 'dispatch'); + let result = editWebpageTitleResolver.resolve(null, null); + const expected = cold('a', { a: "instance_test_label - Edit webpage webpage_test_label" }); + expect(result).toBeObservable(expected); + }); +}); diff --git a/client/src/app/admin/instance/webpage/webpage-title.resolver.spec.ts b/client/src/app/admin/instance/webpage/webpage-title.resolver.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..13bbcd480181f4657fa5b39cd1aa0b6a449b43bb --- /dev/null +++ b/client/src/app/admin/instance/webpage/webpage-title.resolver.spec.ts @@ -0,0 +1,64 @@ +/** + * 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 { TestBed } from '@angular/core/testing'; +import { ActivatedRouteSnapshot } from '@angular/router'; + +import { MockStore, provideMockStore } from '@ngrx/store/testing'; +import { cold} from 'jasmine-marbles'; + +import * as instanceSelector from 'src/app/metamodel/selectors/instance.selector'; +import { Instance} from 'src/app/metamodel/models'; +import { WebpageTitleResolver } from './webpage-title.resolver'; +import { WebpageListComponent } from './containers/webpage-list.component'; + +describe('[Webpage] WebpageTitleResolver', () => { + let webpageTitleResolver: WebpageTitleResolver; + let store: MockStore; + let component; + let instance: Instance; + let mockWebPageSelectorInstanceByRouteName; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [], + declarations: [WebpageListComponent], + providers: [ + WebpageTitleResolver, + provideMockStore({}), + ] + }) + instance = { ...instance, label: 'instance_test_label', } + store = TestBed.inject(MockStore); + webpageTitleResolver = TestBed.inject(WebpageTitleResolver); + mockWebPageSelectorInstanceByRouteName = store.overrideSelector(instanceSelector.selectInstanceByRouteName, instance); + }); + + it('should be created', () => { + expect(webpageTitleResolver).toBeTruthy(); + }); + + it('shoud return nstance_test_label - Webpages list on resolve call', () => { + const expected = cold('a', { a: instance.label + " - Webpages list" }); + let route: ActivatedRouteSnapshot; + component = { name: 'WebpageListComponent' } + route = { ...route, component: component, children: [], root: null, parent: null, firstChild: null, pathFromRoot: null, paramMap: null, queryParamMap: null }; + let result = webpageTitleResolver.resolve(route, null); + expect(result).toBeObservable(expected); + }); + + it('shoud return nstance_test_label - New webpage on resolve call', () => { + const expected = cold('a', { a: instance.label + " - New webpage" }); + let route: ActivatedRouteSnapshot; + component = { name: 'test' } + route = { ...route, component: component, children: [], root: null, parent: null, firstChild: null, pathFromRoot: null, paramMap: null, queryParamMap: null }; + let result = webpageTitleResolver.resolve(route, null); + expect(result).toBeObservable(expected); + }); +}); diff --git a/client/src/app/admin/instance/webpage/webpage.module.spec.ts b/client/src/app/admin/instance/webpage/webpage.module.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..ca05d8db559a69308141180f903d0f614f3c5cce --- /dev/null +++ b/client/src/app/admin/instance/webpage/webpage.module.spec.ts @@ -0,0 +1,16 @@ +/** + * 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 { WebpageModule } from './webpage.module'; + +describe('[Webpage] WebModule', () => { + it('Test WebPage module', () => { + expect(WebpageModule.name).toEqual('WebpageModule'); + }); +});