Commit 3efdd5ce authored by Vitali Stupin's avatar Vitali Stupin

Fixing tests

parent 12727c72
......@@ -8667,33 +8667,6 @@
}
}
},
"istanbul-lib-source-maps": {
"version": "3.0.6",
"resolved": "https://registry.npmjs.org/istanbul-lib-source-maps/-/istanbul-lib-source-maps-3.0.6.tgz",
"integrity": "sha512-R47KzMtDJH6X4/YW9XTx+jrLnZnscW4VpNN+1PViSYTejLVPWv7oov+Duf8YQSPyVRUvueQqz1TcsC6mooZTXw==",
"dev": true,
"requires": {
"debug": "^4.1.1",
"istanbul-lib-coverage": "^2.0.5",
"make-dir": "^2.1.0",
"rimraf": "^2.6.3",
"source-map": "^0.6.1"
},
"dependencies": {
"istanbul-lib-coverage": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.5.tgz",
"integrity": "sha512-8aXznuEPCJvGnMSRft4udDRDtb1V3pkQkMMI5LI+6HuQz5oQ4J2UFn1H82raA3qJtyOLkkwVqICBQkjnGtn5mA==",
"dev": true
},
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"dev": true
}
}
},
"istanbul-reports": {
"version": "3.0.2",
"resolved": "https://nexus.ria.ee/repository/npm-public/istanbul-reports/-/istanbul-reports-3.0.2.tgz",
......@@ -9112,17 +9085,37 @@
"which": "^1.2.1"
}
},
"karma-coverage-istanbul-reporter": {
"version": "3.0.3",
"resolved": "https://nexus.ria.ee/repository/npm-public/karma-coverage-istanbul-reporter/-/karma-coverage-istanbul-reporter-3.0.3.tgz",
"integrity": "sha512-wE4VFhG/QZv2Y4CdAYWDbMmcAHeS926ZIji4z+FkB2aF/EposRb6DP6G5ncT/wXhqUfAb/d7kZrNKPonbvsATw==",
"karma-coverage": {
"version": "2.0.3",
"resolved": "https://nexus.ria.ee/repository/npm-public/karma-coverage/-/karma-coverage-2.0.3.tgz",
"integrity": "sha512-atDvLQqvPcLxhED0cmXYdsPMCQuh6Asa9FMZW1bhNqlVEhJoB9qyZ2BY1gu7D/rr5GLGb5QzYO4siQskxaWP/g==",
"dev": true,
"requires": {
"istanbul-lib-coverage": "^3.0.0",
"istanbul-lib-instrument": "^4.0.1",
"istanbul-lib-report": "^3.0.0",
"istanbul-lib-source-maps": "^3.0.6",
"istanbul-reports": "^3.0.2",
"istanbul-lib-source-maps": "^4.0.0",
"istanbul-reports": "^3.0.0",
"minimatch": "^3.0.4"
},
"dependencies": {
"istanbul-lib-source-maps": {
"version": "4.0.0",
"resolved": "https://nexus.ria.ee/repository/npm-public/istanbul-lib-source-maps/-/istanbul-lib-source-maps-4.0.0.tgz",
"integrity": "sha512-c16LpFRkR8vQXyHZ5nLpY35JZtzj1PQY1iZmesUbf1FZHbIupcWfjgOXBY9YHkLEQ6puz1u4Dgj6qmU/DisrZg==",
"dev": true,
"requires": {
"debug": "^4.1.1",
"istanbul-lib-coverage": "^3.0.0",
"source-map": "^0.6.1"
}
},
"source-map": {
"version": "0.6.1",
"resolved": "https://nexus.ria.ee/repository/npm-public/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
"dev": true
}
}
},
"karma-jasmine": {
......
import { AppModule, HttpLoaderFactory } from './app.module';
import { AppModule, httpLoaderFactory } from './app.module';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { AppConfig } from './app.config';
import { TestBed } from '@angular/core/testing';
......@@ -19,7 +19,7 @@ describe('AppModule', () => {
});
it('HttpLoaderFactory should work', () => {
expect(HttpLoaderFactory(httpClientSpy as any) instanceof TranslateHttpLoader).toBeTruthy();
expect(httpLoaderFactory(httpClientSpy as any) instanceof TranslateHttpLoader).toBeTruthy();
});
it('AppConfig should be initialized', async () => {
......@@ -29,7 +29,7 @@ describe('AppModule', () => {
{ provide: AppConfig, useValue: appConfigSpy }
]
});
expect(TestBed.get(AppConfig)).toBeTruthy();
expect(TestBed.inject(AppConfig)).toBeTruthy();
expect(appConfigSpy.load).toHaveBeenCalledTimes(1);
});
});
......@@ -15,6 +15,9 @@ import { APP_INITIALIZER } from '@angular/core';
import { AppConfig } from './app.config';
import { MessagesComponent } from './messages/messages.component';
// Providing path as a workaround for ngx-translate bug with --base-href option
export const httpLoaderFactory = (http: HttpClient) => new TranslateHttpLoader(http, './assets/i18n/');
@NgModule({
declarations: [
AppComponent,
......@@ -33,8 +36,7 @@ import { MessagesComponent } from './messages/messages.component';
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
// Providing path as a workaround for ngx-translate bug with --base-href option
useFactory: (http: HttpClient) => new TranslateHttpLoader(http, './assets/i18n/'),
useFactory: httpLoaderFactory,
deps: [HttpClient]
}
})
......
......@@ -35,7 +35,7 @@ describe('HeaderComponent', () => {
});
it('should set language', () => {
const languagesService: LanguagesService = TestBed.get(LanguagesService);
const languagesService: LanguagesService = TestBed.inject(LanguagesService);
spyOn(languagesService, 'setLang').and.returnValue(null);
component.setLang('xxx');
expect(languagesService.setLang).toHaveBeenCalledWith('xxx');
......
......@@ -17,30 +17,30 @@ describe('LanguagesService', () => {
}));
it('should be created', () => {
const service: LanguagesService = TestBed.get(LanguagesService);
const service: LanguagesService = TestBed.inject(LanguagesService);
expect(service).toBeTruthy();
});
it('should set default lang with empty localStorage', () => {
const translateService: TranslateService = TestBed.get(TranslateService);
const translateService: TranslateService = TestBed.inject(TranslateService);
spyOn(translateService, 'setDefaultLang');
spyOn(window.localStorage, 'getItem').and.returnValue(undefined);
TestBed.get(LanguagesService);
TestBed.inject(LanguagesService);
expect(translateService.setDefaultLang).toHaveBeenCalledWith('est');
});
it('should set default lang from localStorage', () => {
const translateService: TranslateService = TestBed.get(TranslateService);
const translateService: TranslateService = TestBed.inject(TranslateService);
spyOn(translateService, 'setDefaultLang');
spyOn(window.localStorage, 'getItem').and.returnValue('ENG');
TestBed.get(LanguagesService);
TestBed.inject(LanguagesService);
expect(translateService.setDefaultLang).toHaveBeenCalledWith('eng');
});
it('should set language', () => {
const translateService: TranslateService = TestBed.get(TranslateService);
const translateService: TranslateService = TestBed.inject(TranslateService);
spyOn(translateService, 'use');
const service = TestBed.get(LanguagesService);
const service = TestBed.inject(LanguagesService);
service.setLang('ENG');
expect(translateService.use).toHaveBeenCalledWith('eng');
});
......
......@@ -28,7 +28,7 @@ describe('SearchComponent', () => {
}));
beforeEach(() => {
subsystemsService = TestBed.get(SubsystemsService);
subsystemsService = TestBed.inject(SubsystemsService);
spyOn(subsystemsService, 'getLimits').and.returnValue({10: 10, 20: 20});
spyOn(subsystemsService, 'setNonEmpty').and.returnValue(null);
spyOn(subsystemsService, 'setLimit').and.returnValue(null);
......
......@@ -7,7 +7,7 @@ import { SubsystemsService } from '../../subsystems.service';
})
export class SearchComponent implements OnInit {
limit: string;
limits: Map<string, number>;
limits: Record<string, number>;
nonEmpty: boolean;
filter: string;
......
......@@ -38,7 +38,7 @@ describe('SubsystemItemComponent', () => {
}));
beforeEach(() => {
subsystemsService = TestBed.get(SubsystemsService);
subsystemsService = TestBed.inject(SubsystemsService);
spyOn(subsystemsService, 'getApiUrlBase').and.returnValue(null);
fixture = TestBed.createComponent(SubsystemItemComponent);
......@@ -99,7 +99,8 @@ describe('SubsystemItemComponent', () => {
});
it('should go to detail view', () => {
const spy = TestBed.get(Router).navigateByUrl;
const injected = TestBed.inject(Router) as jasmine.SpyObj<Router>;
const spy = injected.navigateByUrl;
component.showDetail();
expect(spy).toHaveBeenCalledWith('/INST/CLASS/CODE/SUB');
......
......@@ -63,13 +63,13 @@ describe('SubsystemListComponent', () => {
}));
beforeEach(() => {
subsystemsService = TestBed.get(SubsystemsService);
subsystemsService = TestBed.inject(SubsystemsService);
getInstanceSpy = spyOn(subsystemsService, 'getInstance').and.returnValue('INST');
getInstancesSpy = spyOn(subsystemsService, 'getInstances').and.returnValue(['INST']);
spyOn(TestBed.get(ViewportScroller), 'scrollToPosition');
spyOn(TestBed.inject(ViewportScroller), 'scrollToPosition');
spyOn(subsystemsService, 'setInstance').and.returnValue(null);
spyOn(subsystemsService, 'getDefaultInstance').and.returnValue('DEFINST');
spyOn(TestBed.get(SubsystemsService), 'getApiUrlBase').and.returnValue('base');
spyOn(TestBed.inject(SubsystemsService), 'getApiUrlBase').and.returnValue('base');
});
it('should create', () => {
......@@ -84,7 +84,7 @@ describe('SubsystemListComponent', () => {
fixture = TestBed.createComponent(SubsystemListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
expect(TestBed.get(Router).navigateByUrl).toHaveBeenCalledWith('/DEFINST', Object({ replaceUrl: true }));
expect(TestBed.inject(Router).navigateByUrl).toHaveBeenCalledWith('/DEFINST', Object({ replaceUrl: true }));
});
it('should detect when instance is not selected', () => {
......@@ -108,14 +108,15 @@ describe('SubsystemListComponent', () => {
fixture = TestBed.createComponent(SubsystemListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
expect(TestBed.get(ViewportScroller).scrollToPosition).toHaveBeenCalledWith([11, 12]);
expect(TestBed.inject(ViewportScroller).scrollToPosition).toHaveBeenCalledWith([11, 12]);
});
it('switchInstance should work', () => {
fixture = TestBed.createComponent(SubsystemListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
const spy = TestBed.get(Router).navigateByUrl;
const injected = TestBed.inject(Router) as jasmine.SpyObj<Router>;
const spy = injected.navigateByUrl;
component.switchInstance('NEWINST');
expect(spy).toHaveBeenCalledWith('/NEWINST');
......@@ -137,7 +138,8 @@ describe('SubsystemListComponent', () => {
fixture = TestBed.createComponent(SubsystemListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
const spy = TestBed.get(ViewportScroller).scrollToPosition;
const injected = TestBed.inject(ViewportScroller) as jasmine.SpyObj<ViewportScroller>;
const spy = injected.scrollToPosition;
spy.calls.reset();
component.scrollToTop();
expect(spy).toHaveBeenCalledWith([0, 0]);
......@@ -150,13 +152,13 @@ describe('SubsystemListComponent', () => {
subsystemsService.filteredSubsystemsSubject.next([new Subsystem(), new Subsystem()]);
const getLimitSpy = spyOn(subsystemsService, 'getLimit').and.returnValue(['all']);
const getLimitSpy = spyOn(subsystemsService, 'getLimit').and.returnValue('all');
expect(component.isPartialList()).toBeFalsy();
getLimitSpy.and.returnValue(['2']);
getLimitSpy.and.returnValue('2');
expect(component.isPartialList()).toBeTruthy();
getLimitSpy.and.returnValue(['3']);
getLimitSpy.and.returnValue('3');
expect(component.isPartialList()).toBeFalsy();
});
......@@ -165,7 +167,7 @@ describe('SubsystemListComponent', () => {
component = fixture.componentInstance;
fixture.detectChanges();
component.setInstanceVersion();
expect(TestBed.get(Router).navigateByUrl).toHaveBeenCalledWith('/INST');
expect(TestBed.inject(Router).navigateByUrl).toHaveBeenCalledWith('/INST');
});
it('setMaxLimit should work', () => {
......@@ -177,6 +179,14 @@ describe('SubsystemListComponent', () => {
component.setMaxLimit();
expect(component.search.setLimit).toHaveBeenCalledWith('all');
});
it('isIE should work', () => {
fixture = TestBed.createComponent(SubsystemListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
spyOnProperty(window.navigator, 'userAgent').and.returnValue('...MSIE 10...');
expect(component.isIE()).toBeTrue();
});
});
describe('SubsystemListComponent (with instance version)', () => {
......@@ -222,13 +232,13 @@ describe('SubsystemListComponent (with instance version)', () => {
}));
beforeEach(() => {
subsystemsService = TestBed.get(SubsystemsService);
subsystemsService = TestBed.inject(SubsystemsService);
getInstanceSpy = spyOn(subsystemsService, 'getInstance').and.returnValue('INST');
getInstancesSpy = spyOn(subsystemsService, 'getInstances').and.returnValue(['INST']);
spyOn(TestBed.get(ViewportScroller), 'scrollToPosition');
spyOn(TestBed.inject(ViewportScroller), 'scrollToPosition');
spyOn(subsystemsService, 'setInstance').and.returnValue(null);
spyOn(subsystemsService, 'getDefaultInstance').and.returnValue('DEFINST');
spyOn(TestBed.get(SubsystemsService), 'getApiUrlBase').and.returnValue('base');
spyOn(TestBed.inject(SubsystemsService), 'getApiUrlBase').and.returnValue('base');
});
it('should create', () => {
......@@ -244,7 +254,7 @@ describe('SubsystemListComponent (with instance version)', () => {
component = fixture.componentInstance;
fixture.detectChanges();
component.setInstanceVersion();
expect(TestBed.get(Router).navigateByUrl).toHaveBeenCalledWith('/INST?at=12345');
expect(TestBed.inject(Router).navigateByUrl).toHaveBeenCalledWith('/INST?at=12345');
});
it('switchInstance should reset instance version when instance does not change', () => {
......@@ -253,7 +263,7 @@ describe('SubsystemListComponent (with instance version)', () => {
fixture.detectChanges();
component.instanceVersion = 'test';
component.switchInstance('INST');
expect(TestBed.get(Router).navigateByUrl).toHaveBeenCalledWith('/INST');
expect(TestBed.inject(Router).navigateByUrl).toHaveBeenCalledWith('/INST');
expect(component.instanceVersion).toBe('');
});
});
......@@ -56,12 +56,12 @@ describe('SubsystemComponent', () => {
}));
beforeEach(() => {
subsystemsService = TestBed.get(SubsystemsService);
subsystemsService = TestBed.inject(SubsystemsService);
getInstanceSpy = spyOn(subsystemsService, 'getInstance').and.returnValue('INST');
getInstancesSpy = spyOn(subsystemsService, 'getInstances').and.returnValue(['INST']);
spyOn(TestBed.get(ViewportScroller), 'scrollToPosition');
spyOn(TestBed.inject(ViewportScroller), 'scrollToPosition');
spyOn(subsystemsService, 'setInstance').and.returnValue(null);
spyOn(TestBed.get(SubsystemsService), 'getApiUrlBase').and.returnValue('base');
spyOn(TestBed.inject(SubsystemsService), 'getApiUrlBase').and.returnValue('base');
subsystemsService.subsystemsSubject = new BehaviorSubject([
{
memberClass: '',
......@@ -133,7 +133,7 @@ describe('SubsystemComponent', () => {
fixture = TestBed.createComponent(SubsystemComponent);
component = fixture.componentInstance;
fixture.detectChanges();
expect(TestBed.get(ViewportScroller).scrollToPosition).toHaveBeenCalledWith([11, 12]);
expect(TestBed.inject(ViewportScroller).scrollToPosition).toHaveBeenCalledWith([11, 12]);
});
it('getApiUrlBase should work', () => {
......@@ -149,7 +149,7 @@ describe('SubsystemComponent', () => {
component = fixture.componentInstance;
fixture.detectChanges();
component.goToList();
expect(TestBed.get(Router).navigateByUrl).toHaveBeenCalledWith('/INST');
expect(TestBed.inject(Router).navigateByUrl).toHaveBeenCalledWith('/INST');
});
it('should receive service warnings', () => {
......@@ -164,14 +164,14 @@ describe('SubsystemComponent', () => {
fixture = TestBed.createComponent(SubsystemComponent);
component = fixture.componentInstance;
fixture.detectChanges();
const spy = TestBed.get(ViewportScroller).scrollToPosition;
const injected = TestBed.inject(ViewportScroller) as jasmine.SpyObj<ViewportScroller>;
const spy = injected.scrollToPosition;
spy.calls.reset();
component.scrollToTop();
expect(spy).toHaveBeenCalledWith([0, 0]);
});
});
describe('SubsystemComponent (with instance version)', () => {
let component: SubsystemComponent;
let fixture: ComponentFixture<SubsystemComponent>;
......@@ -215,12 +215,12 @@ describe('SubsystemComponent (with instance version)', () => {
}));
beforeEach(() => {
subsystemsService = TestBed.get(SubsystemsService);
subsystemsService = TestBed.inject(SubsystemsService);
getInstanceSpy = spyOn(subsystemsService, 'getInstance').and.returnValue('INST');
getInstancesSpy = spyOn(subsystemsService, 'getInstances').and.returnValue(['INST']);
spyOn(TestBed.get(ViewportScroller), 'scrollToPosition');
spyOn(TestBed.inject(ViewportScroller), 'scrollToPosition');
spyOn(subsystemsService, 'setInstance').and.returnValue(null);
spyOn(TestBed.get(SubsystemsService), 'getApiUrlBase').and.returnValue('base');
spyOn(TestBed.inject(SubsystemsService), 'getApiUrlBase').and.returnValue('base');
subsystemsService.subsystemsSubject = new BehaviorSubject([
{
memberClass: '',
......@@ -241,6 +241,6 @@ describe('SubsystemComponent (with instance version)', () => {
component = fixture.componentInstance;
fixture.detectChanges();
component.goToList();
expect(TestBed.get(Router).navigateByUrl).toHaveBeenCalledWith('/INST?at=12345');
expect(TestBed.inject(Router).navigateByUrl).toHaveBeenCalledWith('/INST?at=12345');
});
});
......@@ -116,7 +116,7 @@ export class SubsystemsService {
return this.limit.toString();
}
getLimits(): Map<string, number> {
getLimits(): Record<string, number> {
return this.config.getConfig('LIMITS');
}
......
......@@ -15,18 +15,17 @@ module.exports = function (config) {
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('karma-coverage'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../coverage/xtss-catalogue'),
reports: ['html', 'lcovonly', 'text-summary'],
fixWebpackSourcePaths: true
coverageReporter: {
type : 'html',
dir : '../coverage/xtss-catalogue'
},
reporters: ['progress', 'kjhtml'],
reporters: ['progress', 'kjhtml', 'coverage'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
......
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