From 451d26880c0315c4f1c6d046b2a9a78b04811c17 Mon Sep 17 00:00:00 2001 From: Angapay Divin <divin.angapay@lam.fr> Date: Mon, 19 Sep 2022 11:30:21 +0200 Subject: [PATCH] add test for admin/database --- .../database-form.component.spec.ts | 53 +++++++++++++++ .../database-table.component.spec.ts | 39 +++++++++++ .../admin/database/components/index.spec.ts | 16 +++++ .../database-list.component.spec.ts | 50 ++++++++++++++ .../database/containers/edit-database.spec.ts | 53 +++++++++++++++ .../containers/new-database.component.spec.ts | 53 +++++++++++++++ .../database/database-title.resolver.spec.ts | 68 +++++++++++++++++++ .../admin/database/database.module.spec.ts | 16 +++++ 8 files changed, 348 insertions(+) create mode 100644 client/src/app/admin/database/components/database-form.component.spec.ts create mode 100644 client/src/app/admin/database/components/database-table.component.spec.ts create mode 100644 client/src/app/admin/database/components/index.spec.ts create mode 100644 client/src/app/admin/database/containers/database-list.component.spec.ts create mode 100644 client/src/app/admin/database/containers/edit-database.spec.ts create mode 100644 client/src/app/admin/database/containers/new-database.component.spec.ts create mode 100644 client/src/app/admin/database/database-title.resolver.spec.ts create mode 100644 client/src/app/admin/database/database.module.spec.ts diff --git a/client/src/app/admin/database/components/database-form.component.spec.ts b/client/src/app/admin/database/components/database-form.component.spec.ts new file mode 100644 index 00000000..f7e3bf8e --- /dev/null +++ b/client/src/app/admin/database/components/database-form.component.spec.ts @@ -0,0 +1,53 @@ +/** + * 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 { DatabaseFormComponent } from './database-form.component'; + +describe('[admin][Database][Component] databaseFormComponent', () => { + + let component: DatabaseFormComponent; + let fixture: ComponentFixture<DatabaseFormComponent>; + + let spy; + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + DatabaseFormComponent, + ], + imports: [ + BrowserAnimationsModule, + ReactiveFormsModule + ] + }); + fixture = TestBed.createComponent(DatabaseFormComponent); + component = fixture.componentInstance; + component.database= {id: 1, dbhost: 'test',dblogin: 'test@test.fr', dbname:'test',dbpassword: 'test',dbport: 808080, dbtype: '',label:''}; + fixture.detectChanges(); + spy= jest.spyOn(component.onSubmit, 'emit'); + + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + it(`should emit database and form values on subumit`, () => { + component.submit(); + expect(spy).toHaveBeenCalledTimes(1); + + }); + it(`should emit database on subumit`, () => { + component.database= null; + component.submit(); + expect(spy).toHaveBeenCalledTimes(1); + + }); +}); diff --git a/client/src/app/admin/database/components/database-table.component.spec.ts b/client/src/app/admin/database/components/database-table.component.spec.ts new file mode 100644 index 00000000..b17c4a67 --- /dev/null +++ b/client/src/app/admin/database/components/database-table.component.spec.ts @@ -0,0 +1,39 @@ +/** + * 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 { BrowserAnimationsModule } from '@angular/platform-browser/animations'; +import { DatabaseTableComponent } from './database-table.component'; + + describe('[admin][Database][Component] databaseTableComponent', () => { + + + let component: DatabaseTableComponent; + let fixture: ComponentFixture<DatabaseTableComponent>; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + DatabaseTableComponent, + ], + imports: [ + BrowserAnimationsModule, + ] + }); + fixture = TestBed.createComponent(DatabaseTableComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + }); + \ No newline at end of file diff --git a/client/src/app/admin/database/components/index.spec.ts b/client/src/app/admin/database/components/index.spec.ts new file mode 100644 index 00000000..d347c479 --- /dev/null +++ b/client/src/app/admin/database/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][Database][Containers] Index components', () => { + it('Test index components', () => { + expect(dummiesComponents.length).toEqual(2); + }); +}); diff --git a/client/src/app/admin/database/containers/database-list.component.spec.ts b/client/src/app/admin/database/containers/database-list.component.spec.ts new file mode 100644 index 00000000..d43bd936 --- /dev/null +++ b/client/src/app/admin/database/containers/database-list.component.spec.ts @@ -0,0 +1,50 @@ +/** + * 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 { BrowserAnimationsModule } from "@angular/platform-browser/animations"; +import { MockStore, provideMockStore } from "@ngrx/store/testing"; +import { Database } from "src/app/metamodel/models"; +import { DatabaseListComponent } from "./database-list.component" +import * as databaseActions from 'src/app/metamodel/actions/database.actions'; + describe('[admin][Database][Containers] DatabaseListComponent', () => { + let component : DatabaseListComponent; + let fixture : ComponentFixture<DatabaseListComponent>; + let store: MockStore; + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + DatabaseListComponent, + ], + imports: [ + BrowserAnimationsModule, + ], + providers: [ + provideMockStore({}) + ] + }); + fixture = TestBed.createComponent(DatabaseListComponent); + component = fixture.componentInstance; + store = TestBed.inject(MockStore); + fixture.detectChanges(); + + }); + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + + it('#deleteDatabase(database) should dispatch deletedatabase action', () => { + const spy = jest.spyOn(store, 'dispatch'); + let database : Database = {id: 1, dbhost: 'test',dblogin: 'test@test.fr', dbname:'test',dbpassword: 'test',dbport: 808080, dbtype: '',label:''}; + component.deleteDatabase(database); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(databaseActions.deleteDatabase({database})); + }); + + }) \ No newline at end of file diff --git a/client/src/app/admin/database/containers/edit-database.spec.ts b/client/src/app/admin/database/containers/edit-database.spec.ts new file mode 100644 index 00000000..5475d6b2 --- /dev/null +++ b/client/src/app/admin/database/containers/edit-database.spec.ts @@ -0,0 +1,53 @@ +/** + * 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 { BrowserAnimationsModule } from "@angular/platform-browser/animations"; +import { MockStore, provideMockStore } from "@ngrx/store/testing"; +import { EditDatabaseComponent } from "./edit-database.component" +import * as databaseActions from 'src/app/metamodel/actions/database.actions'; +import { Database } from "src/app/metamodel/models"; +describe('[admin][Database][Containers] EditDatabaseComponent', () => { + + let component: EditDatabaseComponent; + let fixture: ComponentFixture<EditDatabaseComponent>; + let store: MockStore; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + EditDatabaseComponent + ], + imports: [ + BrowserAnimationsModule, + ], + providers: [ + provideMockStore({}) + ] + + }) + fixture = TestBed.createComponent(EditDatabaseComponent); + component = fixture.componentInstance; + store = TestBed.inject(MockStore); + fixture.detectChanges(); + + + }); + it('should create component', () => { + + expect(component).toBeTruthy(); + }); + it('#editDatabase(database) should dispatch editdatabase action', () => { + const spy = jest.spyOn(store, 'dispatch'); + let database : Database = {id: 1, dbhost: 'test',dblogin: 'test@test.fr', dbname:'test',dbpassword: 'test',dbport: 808080, dbtype: '',label:''}; + component.editDatabase(database); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(databaseActions.editDatabase({database})); + }); +}) \ No newline at end of file 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 new file mode 100644 index 00000000..a098bc55 --- /dev/null +++ b/client/src/app/admin/database/containers/new-database.component.spec.ts @@ -0,0 +1,53 @@ +/** + * 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 { BrowserAnimationsModule } from "@angular/platform-browser/animations"; +import { MockStore, provideMockStore } from "@ngrx/store/testing"; +import { Database } from "src/app/metamodel/models"; +import { NewDatabaseComponent } from "./new-database.component"; +import * as databaseActions from 'src/app/metamodel/actions/database.actions'; + + describe('[admin][Database][Containers] NewDatabaseComponent', () => { + + let component: NewDatabaseComponent; + let fixture: ComponentFixture<NewDatabaseComponent>; + let store: MockStore; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [ + NewDatabaseComponent + ], + imports: [ + BrowserAnimationsModule, + ], + providers: [ + provideMockStore({}) + ] + + }) + fixture = TestBed.createComponent(NewDatabaseComponent); + component = fixture.componentInstance; + store = TestBed.inject(MockStore); + + + }); + it('should create component', () => { + + expect(component).toBeTruthy(); + }); + it('#addNewDatabase(database) should dispatch addDatabase action', () => { + const spy = jest.spyOn(store, 'dispatch'); + let database : Database = {id: 1, dbhost: 'test',dblogin: 'test@test.fr', dbname:'test',dbpassword: 'test',dbport: 808080, dbtype: '',label:''}; + component.addNewDatabase(database); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(databaseActions.addDatabase({database})); + }); + }) \ No newline at end of file diff --git a/client/src/app/admin/database/database-title.resolver.spec.ts b/client/src/app/admin/database/database-title.resolver.spec.ts new file mode 100644 index 00000000..53d2e308 --- /dev/null +++ b/client/src/app/admin/database/database-title.resolver.spec.ts @@ -0,0 +1,68 @@ +/** + * 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 { Observable, of } from 'rxjs'; +import { MetamodelModule } from 'src/app/metamodel/metamodel.module'; +import { DatabaseTitleResolver } from './database-title.resolver'; +import * as databaseActions from 'src/app/metamodel/actions/database.actions'; +import * as databaseSelector from 'src/app/metamodel/selectors/database.selector'; +import { cold, hot } from 'jasmine-marbles'; +import { Database } from 'src/app/metamodel/models'; + + describe('[Database] DatabaseTitleResolver', () => { + let databaseTitleResolver : DatabaseTitleResolver; + let store: MockStore; + let mockDatabaseSelectorDatabaseListIsLoaded; + let mockDatabaseSelectorDatabaseByRouteId; + let actions = new Observable(); + + let database : Database = {id: 1, dbhost: 'test',dblogin: 'test@test.fr', dbname:'test',dbpassword: 'test',dbport: 808080, dbtype: '',label:'test'}; + + + beforeEach( () =>{ + + TestBed.configureTestingModule({ + imports: [], + providers: [ + DatabaseTitleResolver, + provideMockStore({}), + + + + ] + + }) + + store = TestBed.inject(MockStore); + databaseTitleResolver = TestBed.inject(DatabaseTitleResolver); + mockDatabaseSelectorDatabaseListIsLoaded = store.overrideSelector(databaseSelector.selectDatabaseListIsLoaded, false); + mockDatabaseSelectorDatabaseByRouteId = store.overrideSelector(databaseSelector.selectDatabaseByRouteId, database); + }); + it('should be created', () => { + + expect(databaseTitleResolver).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: databaseTitleResolver.resolve(null,null)}); + + expect(result).toBeObservable(expected); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy).toHaveBeenCalledWith(databaseActions.loadDatabaseList()); + + + }); + + }); + \ No newline at end of file diff --git a/client/src/app/admin/database/database.module.spec.ts b/client/src/app/admin/database/database.module.spec.ts new file mode 100644 index 00000000..e63a32df --- /dev/null +++ b/client/src/app/admin/database/database.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 {DatabaseModule} from './database.module'; + +describe('[Database] DatabaseModule', () => { + it('Test Database module', () => { + expect(DatabaseModule.name).toEqual('DatabaseModule'); + }); +}); -- GitLab