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 0000000000000000000000000000000000000000..9852dc65ea0c7744a2dcfd31346349a1d0d28dd6 --- /dev/null +++ b/client/src/app/admin/database/components/database-form.component.spec.ts @@ -0,0 +1,52 @@ +/** + * 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 0000000000000000000000000000000000000000..040fbcb0fdf6f0d9230d36366263a90af318fe3d --- /dev/null +++ b/client/src/app/admin/database/components/database-table.component.spec.ts @@ -0,0 +1,36 @@ +/** + * 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(); + }); +}); 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 0000000000000000000000000000000000000000..d347c47937d5fe01a98d7ddbb19396e77a8cea8a --- /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 0000000000000000000000000000000000000000..1123335033fa5990f79c384fad57ade9cdbd93d2 --- /dev/null +++ b/client/src/app/admin/database/containers/database-list.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 * as databaseActions from 'src/app/metamodel/actions/database.actions'; +import { DatabaseListComponent } from './database-list.component'; + +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})); + }); +}) 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 0000000000000000000000000000000000000000..3011493af8b4805acd8eed82c8d372237b4bb04b --- /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 * as databaseActions from 'src/app/metamodel/actions/database.actions'; +import { Database } from 'src/app/metamodel/models'; +import { EditDatabaseComponent } from './edit-database.component'; + +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})); + }); +}) 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 0000000000000000000000000000000000000000..43ebf1501f219e080f31bee0878eb416d646ebd8 --- /dev/null +++ b/client/src/app/admin/database/containers/new-database.component.spec.ts @@ -0,0 +1,52 @@ +/** + * 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 * as databaseActions from 'src/app/metamodel/actions/database.actions'; +import { NewDatabaseComponent } from './new-database.component'; + +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})); + }); +}) 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 0000000000000000000000000000000000000000..15b5be5ee2a5531e67ed4300d5ea104159547cd4 --- /dev/null +++ b/client/src/app/admin/database/database-title.resolver.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 { TestBed } from '@angular/core/testing'; +import { MockStore, provideMockStore } from '@ngrx/store/testing'; + +import { cold, hot } from 'jasmine-marbles'; + +import * as databaseActions from 'src/app/metamodel/actions/database.actions'; +import * as databaseSelector from 'src/app/metamodel/selectors/database.selector'; +import { Database } from 'src/app/metamodel/models'; +import { DatabaseTitleResolver } from './database-title.resolver'; + +describe('[Database] DatabaseTitleResolver', () => { + let databaseTitleResolver : DatabaseTitleResolver; + let store: MockStore; + let mockDatabaseSelectorDatabaseListIsLoaded; + let mockDatabaseSelectorDatabaseByRouteId; + + 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 0000000000000000000000000000000000000000..b76b705946954aad41554e9c21309e841cd7736d --- /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'); + }); +});