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/webpage-card.component.spec.ts b/client/src/app/admin/instance/webpage/components/webpage-card.component.spec.ts index eedb83c0d193b78f77328647aab44ef359a9f06e..2b28f4854e9fc07f0d95ab01819c0b8272b68754 100644 --- 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 @@ -7,11 +7,18 @@ * file that was distributed with this source code. */ - import { ComponentFixture, TestBed } from '@angular/core/testing'; + import { Component, EventEmitter, Input, Output } 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>; @@ -20,6 +27,7 @@ TestBed.configureTestingModule({ declarations: [ WebpageCardComponent, + DeleteBtnComponent ], imports: [ BrowserAnimationsModule, 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..613188689f13151af5b6443449ec56814ddc035b --- /dev/null +++ b/client/src/app/admin/instance/webpage/components/webpage-form.component.spec.ts @@ -0,0 +1,78 @@ +/** + * 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..a24d12705f4591f67cc8ddc0a84f0e5121480f8f --- /dev/null +++ b/client/src/app/admin/instance/webpage/containers/edit-webpage.component.spec.ts @@ -0,0 +1,58 @@ +/** + * 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 { 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..48ab8f6e222a1616ab768a37c9c8547e6b10375c --- /dev/null +++ b/client/src/app/admin/instance/webpage/containers/new-webpage.component.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 { ComponentFixture, TestBed } from '@angular/core/testing'; +import { ReactiveFormsModule, UntypedFormControl, UntypedFormGroup, Validators } 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 { NewWebpageComponent } from './new-webpage.component'; +import * as webpageActions from 'src/app/metamodel/actions/webpage.actions'; +import { ActivatedRoute } from '@angular/router'; +import { from, of } from 'rxjs'; + +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: 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', () => { + fixture.detectChanges(); + 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 })); + + }); + + +}); 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..59aef0994593514bad0e84c385eba077c56f8757 --- /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 { ReactiveFormsModule, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { MockStore, provideMockStore } from '@ngrx/store/testing'; +import { Webpage, WebpageFamily } from 'src/app/metamodel/models'; +import * as webpageFamilyActions from 'src/app/metamodel/actions/webpage-family.actions'; +import { WebpageListComponent } from './webpage-list.component'; +import { Component } from '@angular/core'; +import { RouterTestingModule } from '@angular/router/testing'; +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 + ], + 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..44632572078a2f2900933ac9f4abe5b570b9b9ab --- /dev/null +++ b/client/src/app/admin/instance/webpage/edit-webpage-title.resolver.spec.ts @@ -0,0 +1,66 @@ +/** + * 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.module.spec.ts b/client/src/app/admin/instance/webpage/webpage.module.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..fec7224377ba5ec6abb961e5714418256588b27a --- /dev/null +++ b/client/src/app/admin/instance/webpage/webpage.module.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 { WebpageModule } from './webpage.module'; + + describe('[Webpage] DatabaseModule', () => { + it('Test WebPage module', () => { + expect(WebpageModule.name).toEqual('WebpageModule'); + }); + }); + \ No newline at end of file