Skip to content
Snippets Groups Projects
Commit 451d2688 authored by Angapay Divin's avatar Angapay Divin
Browse files

add test for admin/database

parent acdd62c6
No related branches found
No related tags found
2 merge requests!72Develop,!59Resolve "Tests client: Tester le module database de la partie admin"
/**
* 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);
});
});
/**
* 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
/**
* 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);
});
});
/**
* 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
/**
* 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
/**
* 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
/**
* 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
/**
* 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');
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment