Commit 0f06f5b5 authored by Tifenn Guillas's avatar Tifenn Guillas
Browse files

Merge branch 'tests-integration' into 'develop'

Tests integration

See merge request !61
parents c68f99c9 c92189a6
Pipeline #1588 passed with stages
in 26 minutes and 24 seconds
......@@ -35,7 +35,7 @@ test:
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
- apt-get update
- apt-get install -y google-chrome-stable
- ng test
- ng test --no-watch
cache:
paths:
- dist
......
......@@ -39,12 +39,7 @@ stop:
restart: stop start
test:
rm -rf ./coverage
@docker build -t anis-node conf-dev && docker run --init -it --rm --user $(UID):$(GID) \
--name anis-client \
-p 9876:9876 \
-v $(CURDIR):/project -d \
-w /project anis-node ng test --code-coverage
@docker exec -ti anis-client ng test --no-watch
ng-build:
@docker build -t anis-node conf-dev && docker run --init -it --rm --user $(UID):$(GID) \
......
......@@ -81,6 +81,7 @@
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"codeCoverageExclude": ["node_modules/**", ""],
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
......
......@@ -32,6 +32,7 @@ module.exports = function (config) {
flags: ['--no-sandbox'],
}
},
singleRun: true,
autoWatch: true,
singleRun: false
});
};
<nav class="navbar navbar-light bg-light navbar-expand-md fixed-top border-bottom">
<!-- Logo -->
<a href="/" class="navbar-brand">
<img src="../assets/cesam_anis80.png" alt="CeSAM logo"/>
<img src="../assets/cesam_anis80.png" alt="CeSAM logo" />
</a>
<!-- Right Navigation -->
......@@ -18,10 +18,12 @@
</a>
</li>
</ul>
<button *ngIf="!isAuthenticated" class="btn btn-outline-success my-2 my-sm-0" routerLink="/login">
<button *ngIf="!isAuthenticated" class="btn btn-outline-success my-2 my-sm-0"
id="button-sign-in"
routerLink="/login">
Sign In / Register
</button>
<span *ngIf="isAuthenticated" dropdown>
<span *ngIf="isAuthenticated" id="dropdown-menu" dropdown>
<button id="button-basic" dropdownToggle type="button" class="btn btn-light" aria-controls="dropdown-basic">
<span class="fa-stack theme-color">
<span class="fas fa-circle fa-2x"></span>
......@@ -32,7 +34,7 @@
</button>
<ul id="basic-link-dropdown" *dropdownMenu class="dropdown-menu dropdown-menu-right dropdown-up" role="menu"
aria-labelledby="basic-link">
<li role="menuitem">
<li id="li-email" role="menuitem">
<span class="dropdown-item font-italic">{{ loginToken.email }}</span>
</li>
<li class="divider dropdown-divider"></li>
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NavComponent } from './nav.component';
describe('Component: NavComponent', () => {
let component: NavComponent;
let fixture: ComponentFixture<NavComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [NavComponent]
});
fixture = TestBed.createComponent(NavComponent);
component = fixture.componentInstance;
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
it('should display the Sign In button if no user logged in', () => {
component.isAuthenticated = false;
fixture.detectChanges();
const template = fixture.nativeElement;
expect(template.querySelector('#button-sign-in')).toBeTruthy();
});
it('should not display the dropdown menu if no user logged in', () => {
component.isAuthenticated = false;
fixture.detectChanges();
const template = fixture.nativeElement;
expect(template.querySelector('#dropdown-menu')).toBeFalsy();
});
it('should display the dropdown menu if user logged in', () => {
component.isAuthenticated = true;
fixture.detectChanges();
const template = fixture.nativeElement;
expect(template.querySelector('#dropdown-menu')).toBeTruthy();
});
it('should not display the Sign In button if user logged in', () => {
component.isAuthenticated = true;
fixture.detectChanges();
const template = fixture.nativeElement;
expect(template.querySelector('#button-sign-in')).toBeFalsy();
});
});
......@@ -3,12 +3,12 @@ import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from
import { LoginToken } from '../../login/store/model';
@Component({
selector: 'app-anis-nav',
templateUrl: 'anis-nav.component.html',
styleUrls: [ 'anis-nav.component.css' ],
selector: 'app-nav',
templateUrl: 'nav.component.html',
styleUrls: [ 'nav.component.css' ],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AnisNavComponent {
export class NavComponent {
@Input() isAuthenticated: boolean;
@Input() loginToken: LoginToken;
@Output() logout: EventEmitter<{}> = new EventEmitter();
......
<header>
<app-anis-nav [isAuthenticated]="isAuthenticated | async" [loginToken]="loginToken | async" (logout)="logout()">
</app-anis-nav>
<app-nav [isAuthenticated]="isAuthenticated | async" [loginToken]="loginToken | async" (logout)="logout()">
</app-nav>
</header>
<main role="main" class="container-fluid pb-4">
<router-outlet></router-outlet>
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NotFoundPageComponent } from './not-found-page.component';
describe('Component: NotFoundPageComponent', () => {
let component: NotFoundPageComponent;
let fixture: ComponentFixture<NotFoundPageComponent>;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [NotFoundPageComponent]
});
fixture = TestBed.createComponent(NotFoundPageComponent);
component = fixture.componentInstance;
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
});
......@@ -6,13 +6,13 @@ import { CollapseModule, BsDropdownModule } from 'ngx-bootstrap';
import { AppComponent } from './containers/app.component';
import { NotFoundPageComponent } from './containers/not-found-page.component';
import { AnisNavComponent } from './components/anis-nav.component';
import { NavComponent } from './components/nav.component';
import { throwIfAlreadyLoaded } from './module-import-guard';
export const COMPONENTS = [
AppComponent,
NotFoundPageComponent,
AnisNavComponent
NavComponent
];
@NgModule({
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ObjectDisplayComponent } from './object-display.component';
describe('Component: ObjectDisplayComponent', () => {
it('#getAttributesVisible() should filter and sort #attributeList', () => {
const component = new ObjectDisplayComponent();
component.attributeList = [
{
id: 1,
name: 'id',
table_name: 'obs_cat',
label: 'id',
form_label: 'id',
description: null,
output_display: 10,
criteria_display: 10,
search_flag: 'ID',
search_type: 'between',
type: 'integer',
operator: 'eq',
min: null,
max: null,
placeholder_min: null,
placeholder_max: null,
uri_action: null,
renderer: 'detail-btn',
display_detail: 10,
selected: true,
order_by: false,
order_display: 10,
detail: false,
renderer_detail: null,
options: null,
vo_utype: null,
vo_ucd: null,
vo_unit: null,
vo_description: null,
vo_datatype: null,
vo_size: 0,
id_criteria_family: 1,
id_output_category: 1
},
{
id: 2,
name: 'ra',
table_name: 'obs_cat',
label: 'ra',
form_label: 'ra',
description: null,
output_display: 20,
criteria_display: 20,
search_flag: null,
search_type: 'between',
type: 'decimal',
operator: null,
min: null,
max: null,
placeholder_min: null,
placeholder_max: null,
uri_action: null,
renderer: null,
display_detail: 20,
selected: true,
order_by: false,
order_display: 20,
detail: true,
renderer_detail: null,
options: null,
vo_utype: null,
vo_ucd: null,
vo_unit: null,
vo_description: null,
vo_datatype: null,
vo_size: 0,
id_criteria_family: 1,
id_output_category: 1
},
{
id: 3,
name: 'dec',
table_name: 'obs_cat',
label: 'dec',
form_label: 'dec',
description: null,
output_display: 30,
criteria_display: 30,
search_flag: null,
search_type: 'between',
type: 'decimal',
operator: null,
min: null,
max: null,
placeholder_min: null,
placeholder_max: null,
uri_action: null,
renderer: null,
display_detail: 10,
selected: true,
order_by: false,
order_display: 30,
detail: true,
renderer_detail: null,
options: null,
vo_utype: null,
vo_ucd: null,
vo_unit: null,
vo_description: null,
vo_datatype: null,
vo_size: 0,
id_criteria_family: 1,
id_output_category: 1
}
];
const expectedAttributeList = [
{
id: 3,
name: 'dec',
table_name: 'obs_cat',
label: 'dec',
form_label: 'dec',
description: null,
output_display: 30,
criteria_display: 30,
search_flag: null,
search_type: 'between',
type: 'decimal',
operator: null,
min: null,
max: null,
placeholder_min: null,
placeholder_max: null,
uri_action: null,
renderer: null,
display_detail: 10,
selected: true,
order_by: false,
order_display: 30,
detail: true,
renderer_detail: null,
options: null,
vo_utype: null,
vo_ucd: null,
vo_unit: null,
vo_description: null,
vo_datatype: null,
vo_size: 0,
id_criteria_family: 1,
id_output_category: 1
},
{
id: 2,
name: 'ra',
table_name: 'obs_cat',
label: 'ra',
form_label: 'ra',
description: null,
output_display: 20,
criteria_display: 20,
search_flag: null,
search_type: 'between',
type: 'decimal',
operator: null,
min: null,
max: null,
placeholder_min: null,
placeholder_max: null,
uri_action: null,
renderer: null,
display_detail: 20,
selected: true,
order_by: false,
order_display: 20,
detail: true,
renderer_detail: null,
options: null,
vo_utype: null,
vo_ucd: null,
vo_unit: null,
vo_description: null,
vo_datatype: null,
vo_size: 0,
id_criteria_family: 1,
id_output_category: 1
}
];
const filteredAttributeList = component.getAttributesVisible();
expect(filteredAttributeList).toEqual(expectedAttributeList);
});
});
<div class="row text-center mb-5">
<div class="col">
<h1>Object detail</h1>
<div class="mx-5 px-5">
<div class="row text-center mb-5">
<div class="col">
<h1>Object detail</h1>
</div>
</div>
</div>
<div *ngIf="objectIsLoading | async" class="row justify-content-center mt-5">
<span class="fas fa-circle-notch fa-spin fa-3x"></span>
<span class="sr-only">Loading...</span>
</div>
<div *ngIf="objectIsLoaded | async">
<app-object-display [attributeList]="attributeList | async" [object]="object | async"></app-object-display>
</div>
<div *ngIf="!(pristine | async)" class="row mt-5 justify-content-between">
<div class="col">
<button (click)="goBackToResult()" class="btn btn-outline-secondary">
<span class="fa fa-backward"></span> Back to search results
</button>
<div *ngIf="objectIsLoading | async" id="div-spinner" class="row justify-content-center mt-5">
<span class="fas fa-circle-notch fa-spin fa-3x"></span>
<span class="sr-only">Loading...</span>
</div>
<div *ngIf="objectIsLoaded | async">
<app-object-display [attributeList]="attributeList | async" [object]="object | async"></app-object-display>
</div>
<div *ngIf="!(pristine | async)" class="row mt-5 justify-content-between">
<div class="col">
<button (click)="goBackToResult()" class="btn btn-outline-secondary">
<span class="fa fa-backward"></span> Back to search results
</button>
</div>
</div>
</div>
\ No newline at end of file
......@@ -90,7 +90,6 @@ export class DetailEffects {
const objectSelected = state.router.state.params.objectSelected;
const attributes = state.detail.attributeList;
const attributeCriterionId = attributes.find(a => a.search_flag === 'ID');
console.log(attributes);
const attributesOutputList = attributes.filter(a => a.detail).map(a => a.id);
return this.detailService.retrieveObject(datasetName, attributeCriterionId.id, objectSelected, attributesOutputList).pipe(
map((object: any[]) => new detailActions.RetrieveObjectSuccessAction(object[0])),
......
......@@ -2,24 +2,19 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AccountBenefitsComponent } from './account-benefits.component';
describe('AccountBenefitsComponent', () => {
let component: AccountBenefitsComponent;
let fixture: ComponentFixture<AccountBenefitsComponent>;
describe('Component: AccountBenefitsComponent', () => {
let component: AccountBenefitsComponent;
let fixture: ComponentFixture<AccountBenefitsComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AccountBenefitsComponent ]
})
.compileComponents();
}));
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [AccountBenefitsComponent]
});
fixture = TestBed.createComponent(AccountBenefitsComponent);
component = fixture.componentInstance;
});
beforeEach(() => {
fixture = TestBed.createComponent(AccountBenefitsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should create the component', () => {
expect(component).toBeTruthy();
});
});
// import { async, ComponentFixture, TestBed } from '@angular/core/testing';
// import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
// import { HttpClient, HttpResponse } from '@angular/common/http';
// import { SearchService } from './search.service';
// import { SearchMeta } from './model';
// describe('SearchService', () => {
// let searchService: SearchService;
// let httpClient: HttpClient;
// let httpTestingController: HttpTestingController;
// beforeEach(() => {
// TestBed.configureTestingModule({
// // Import the HttpClient mocking services
// imports: [HttpClientTestingModule],
// // Provide the service-under-test and its dependencies
// providers: [SearchService]
// });
// });
// // Inject the http, test controller, and service-under-test
// // as they will be referenced by each test.
// httpClient = TestBed.get(HttpClient);
// httpTestingController = TestBed.get(HttpTestingController);
// searchService = TestBed.get(SearchService);
// afterEach(() => {
// // After every test, assert that there are no more pending requests.
// httpTestingController.verify();
// });
// /// SeroService method tests begin ///
// describe('#getMeta', () => {
// let query = 'query';
// let expectedMeta: SearchMeta;
// beforeEach(() => {
// searchService = TestBed.get(SearchService);
// query = 'query';
// expectedMeta = {
// dataset_selected: 'obs_cat',
// attributes_selected: [
// { name: 'id', label: 'ID' },
// { name: 'ra', label: 'RA' },
// { name: 'dec', label: 'DEC' }
// ],
// total_items: 10
// };
// });
// // it('should return expected meta (called once)', () => {
// // searchService.retrieveMeta(query).subscribe(
// // meta => expect(meta).toEqual(expectedMeta, 'should return expected meta'),
// // fail
// // );
// // SearchService should have made one request to GET meta from expected URL
// // const url = searchService.API_PATH + '/search/' + searchService.instanceName + '/meta/' + query;
// // const req = httpTestingController.expectOne(url);
// // expect(req.request.method).toEqual('GET');
// // Respond with the mock meta
// // req.flush(expectedMeta);
// // });
// });
// });
......@@ -6,8 +6,8 @@ import { environment } from '../../../environments/environment';
@Injectable()
export class SearchService {
private API_PATH: string = environment.apiUrl;
private instanceName: string = environment.instanceName;
API_PATH: string = environment.apiUrl;
instanceName: string = environment.instanceName;
constructor(private http: HttpClient) { }
......
......@@ -2,24 +2,19 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HomeComponent } from './home.component';
describe('HomeComponent', () => {
let component: HomeComponent;
let fixture: ComponentFixture<HomeComponent>;
describe('Component: HomeComponent', () => {
let component: HomeComponent;
let fixture: ComponentFixture<HomeComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ HomeComponent ]
})
.compileComponents();
}));
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [HomeComponent]
});
fixture = TestBed.createComponent(HomeComponent);
component = fixture.componentInstance;
});
beforeEach(() => {
fixture = TestBed.createComponent(HomeComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should create the component', () => {