Commit 77a91d8e authored by Vitali Stupin's avatar Vitali Stupin
Browse files

Fixing tests

parent dd2608b6
import { TestBed, async } from '@angular/core/testing';
import {RouterTestingModule} from '@angular/router/testing'
import { AppComponent } from './app.component';
describe('AppComponent', () => {
......@@ -7,6 +8,9 @@ describe('AppComponent', () => {
declarations: [
AppComponent
],
imports: [
RouterTestingModule
]
}).compileComponents();
}));
......@@ -15,17 +19,4 @@ describe('AppComponent', () => {
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
});
it(`should have as title 'methods'`, () => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('methods');
});
it('should render title in a h1 tag', () => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('Welcome to methods!');
});
});
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import {TranslateLoader, TranslateModule} from '@ngx-translate/core';
import {TranslateHttpLoader} from '@ngx-translate/http-loader';
import {HttpClient, HttpClientModule} from '@angular/common/http';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
import { SubsystemListComponent } from './subsystem-list/subsystem-list.component';
import { SearchComponent } from './subsystem-list/search/search.component';
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { HeaderComponent } from './header.component';
import { HttpClientModule } from '@angular/common/http';
describe('HeaderComponent', () => {
let component: HeaderComponent;
......@@ -8,7 +9,11 @@ describe('HeaderComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ HeaderComponent ]
declarations: [ HeaderComponent ],
imports: [
TranslateModule.forRoot(),
HttpClientModule
]
})
.compileComponents();
}));
......
import { TestBed } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { LanguagesService } from './languages.service';
describe('LanguagesService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
beforeEach(() => TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot()
]
}));
it('should be created', () => {
const service: LanguagesService = TestBed.get(LanguagesService);
......
......@@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import {TranslateService} from "@ngx-translate/core";
import { Title } from '@angular/platform-browser';
import { Subscription } from 'rxjs';
import { take } from 'rxjs/operators';
const LANGUAGES = {
'EST': 'est',
......@@ -27,9 +28,8 @@ export class LanguagesService {
updateTitle(): void {
// Not subscribing if subscription already in progress
if (!this.translateSubscription || this.translateSubscription.closed) {
this.translateSubscription = this.translate.get('index.title').subscribe((res: string) => {
this.translateSubscription = this.translate.get('index.title').pipe(take(1)).subscribe((res: string) => {
this.title.setTitle(res)
this.translateSubscription.unsubscribe()
});
}
}
......
import { TestBed } from '@angular/core/testing';
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { MethodsService } from './methods.service';
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { HttpLoaderFactory } from './app.module';
describe('MethodsService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
beforeEach(() => TestBed.configureTestingModule({
imports: [
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient]
}
}),
HttpClientModule
]
}));
it('should be created', () => {
const service: MethodsService = TestBed.get(MethodsService);
expect(service).toBeTruthy();
});
});
});
\ No newline at end of file
......@@ -84,6 +84,7 @@ export class MethodsService {
return filtered.slice(this.offset, this.limit);
}
// TODO: move that to Class constructor?
private setFullNames() {
for (let i in this.subsystems) {
this.subsystems[i].fullSubsystemName = this.subsystems[i].xRoadInstance
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { HttpClientModule } from '@angular/common/http';
import { FormsModule } from '@angular/forms';
import { SearchComponent } from './search.component';
describe('SearchComponent', () => {
......@@ -8,7 +10,12 @@ describe('SearchComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SearchComponent ]
declarations: [ SearchComponent ],
imports: [
FormsModule,
TranslateModule.forRoot(),
HttpClientModule
]
})
.compileComponents();
}));
......@@ -22,4 +29,4 @@ describe('SearchComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
});
});
\ No newline at end of file
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { HttpClientModule } from '@angular/common/http';
import { SubsystemItemComponent } from './subsystem-item.component';
import { RouterTestingModule } from '@angular/router/testing';
describe('SubsystemItemComponent', () => {
let component: SubsystemItemComponent;
......@@ -8,7 +10,14 @@ describe('SubsystemItemComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SubsystemItemComponent ]
declarations: [
SubsystemItemComponent
],
imports: [
TranslateModule.forRoot(),
HttpClientModule,
RouterTestingModule
]
})
.compileComponents();
}));
......@@ -16,10 +25,21 @@ describe('SubsystemItemComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(SubsystemItemComponent);
component = fixture.componentInstance;
component.subsystem = {
xRoadInstance: "XRD",
memberClass: "CLASS",
memberCode: "CODE",
subsystemCode: "SUB",
subsystemStatus: "OK",
fullSubsystemName: "XRD/CLASS/CODE/SUB",
methods: []
}
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
});
\ No newline at end of file
......@@ -38,7 +38,6 @@ export class SubsystemItemComponent implements OnInit {
}
showDetail() {
//this.router.navigateByUrl('/subsystem/' + encodeURIComponent(this.subsystem.fullSubsystemName))
this.router.navigateByUrl(
'/' + this.subsystem.xRoadInstance
+ '/' + this.subsystem.memberClass
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { HttpClientModule } from '@angular/common/http';
import { RouterTestingModule } from '@angular/router/testing'
import { SubsystemListComponent } from './subsystem-list.component';
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { ViewportScroller } from '@angular/common';
import { Subsystem } from '../subsystem';
import { ActivatedRoute } from '@angular/router';
import { of } from 'rxjs';
@Component({selector: 'app-header', template: ''})
class HeaderStubComponent {}
@Component({selector: 'app-search', template: ''})
class SearchStubComponent {}
@Component({selector: 'app-subsystem-item', template: ''})
class SubsystemItemStubComponent {
@Input() subsystem: Subsystem
}
describe('SubsystemListComponent', () => {
let component: SubsystemListComponent;
......@@ -8,12 +24,26 @@ describe('SubsystemListComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SubsystemListComponent ]
declarations: [
SubsystemListComponent,
HeaderStubComponent,
SearchStubComponent,
SubsystemItemStubComponent
],
imports: [
TranslateModule.forRoot(),
HttpClientModule,
RouterTestingModule
]
})
.compileComponents();
}));
beforeEach(() => {
// Mocks and spies
TestBed.get(ActivatedRoute).params = of({
"instance": "EE"
})
fixture = TestBed.createComponent(SubsystemListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
......@@ -22,4 +52,4 @@ describe('SubsystemListComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
});
});
\ No newline at end of file
......@@ -14,7 +14,7 @@ import { filter } from 'rxjs/operators';
export class SubsystemListComponent implements OnInit, OnDestroy {
subsystems: Subsystem[]
message: string = ''
scrollPosition: [number, number]
scrollPosition: [number, number] = [0, 0]
routerScrollSubscription: Subscription
routeSubscription: Subscription
updatedSubscription: Subscription
......@@ -74,6 +74,10 @@ export class SubsystemListComponent implements OnInit, OnDestroy {
ngAfterViewInit() {
// Restoring scroll position
this.viewportScroller.scrollToPosition(this.scrollPosition);
// TODO: what if this.scrollPosition is not ready yet?
/*this.routerScrollSubscription.add(() => {
this.viewportScroller.scrollToPosition(this.scrollPosition);
})*/
}
ngOnDestroy() {
......
import { Method } from './method';
// TODO: use two classes for parsing of json and for use by application
export class Subsystem {
memberClass: string;
subsystemCode: string;
......
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TranslateModule } from '@ngx-translate/core';
import { Component } from '@angular/core';
import { SubsystemComponent } from './subsystem.component';
import { RouterTestingModule } from '@angular/router/testing';
import { HttpClientModule } from '@angular/common/http';
//import { ViewportScroller } from '@angular/common';
//import { MethodsService } from '../methods.service';
import { ActivatedRoute } from '@angular/router';
import { of } from 'rxjs';
@Component({selector: 'app-header', template: ''})
class HeaderStubComponent {}
describe('SubsystemComponent', () => {
let component: SubsystemComponent;
......@@ -8,18 +18,46 @@ describe('SubsystemComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SubsystemComponent ]
declarations: [
SubsystemComponent,
HeaderStubComponent
],
imports: [
TranslateModule.forRoot(),
HttpClientModule,
RouterTestingModule
]/*,
providers: [
MethodsService
]*/
})
.compileComponents();
}));
beforeEach(() => {
// Mocks and spies
TestBed.get(ActivatedRoute).params = of({
"instance": "EE",
"class": "CLASS",
"member": "MEMBER",
"subsystem": "SYSTEM"
})
//spyOn(TestBed.get(ViewportScroller), "scrollToPosition").and.callFake(() => {});
fixture = TestBed.createComponent(SubsystemComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
/*afterEach(() => {
TestBed.resetTestEnvironment()
});*/
it('should create', () => {
expect(component).toBeTruthy();
});
/*it('scrollToPosition was called', async(() => {
expect(TestBed.get(ViewportScroller).scrollToPosition).toHaveBeenCalledWith([0, 0])
}));*/
});
......@@ -4,7 +4,7 @@ import { Subsystem } from '../subsystem';
import { ActivatedRoute, Router, Scroll } from '@angular/router';
import { Subscription } from 'rxjs';
import { ViewportScroller } from '@angular/common';
import { filter } from 'rxjs/operators';
import { filter, take } from 'rxjs/operators';
@Component({
selector: 'app-subsystem',
......@@ -15,7 +15,7 @@ export class SubsystemComponent implements OnInit, OnDestroy {
subsystem: Subsystem
subsystemId: string
message: string = ''
scrollPosition: [number, number]
scrollPosition: [number, number] = [0, 0]
routerScrollSubscription: Subscription
routeSubscription: Subscription
updatedSubscription: Subscription
......@@ -29,7 +29,8 @@ export class SubsystemComponent implements OnInit, OnDestroy {
) {
// Geting previous scroll position
this.routerScrollSubscription = this.router.events.pipe(
filter(e => e instanceof Scroll)
filter(e => e instanceof Scroll),
take(1)
).subscribe(e => {
if ((e as Scroll).position) {
this.scrollPosition = (e as Scroll).position;
......@@ -86,6 +87,10 @@ export class SubsystemComponent implements OnInit, OnDestroy {
ngAfterViewInit() {
// Restoring scroll position
this.viewportScroller.scrollToPosition(this.scrollPosition);
// TODO: what if this.scrollPosition is not ready yet?
/*this.routerScrollSubscription.add(() => {
this.viewportScroller.scrollToPosition(this.scrollPosition);
})*/
}
ngOnDestroy() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment