mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-22 09:32:41 +00:00
test: clean up async behaviour
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
|
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
|
||||||
import {TestBed, waitForAsync} from '@angular/core/testing';
|
import {TestBed} from '@angular/core/testing';
|
||||||
|
|
||||||
import {Platform} from '@ionic/angular';
|
import {Platform} from '@ionic/angular';
|
||||||
|
|
||||||
@@ -43,8 +43,7 @@ describe('AppComponent', () => {
|
|||||||
let platformIsSpy;
|
let platformIsSpy;
|
||||||
let storageProvider: jasmine.SpyObj<StorageProvider>;
|
let storageProvider: jasmine.SpyObj<StorageProvider>;
|
||||||
|
|
||||||
beforeEach(
|
beforeEach(() => {
|
||||||
waitForAsync(() => {
|
|
||||||
platformReadySpy = Promise.resolve();
|
platformReadySpy = Promise.resolve();
|
||||||
platformIsSpy = Promise.resolve();
|
platformIsSpy = Promise.resolve();
|
||||||
platformSpy = jasmine.createSpyObj('Platform', {
|
platformSpy = jasmine.createSpyObj('Platform', {
|
||||||
@@ -71,9 +70,7 @@ describe('AppComponent', () => {
|
|||||||
'init',
|
'init',
|
||||||
'getAnyValue',
|
'getAnyValue',
|
||||||
]);
|
]);
|
||||||
configProvider.getAnyValue = jasmine
|
configProvider.getAnyValue = jasmine.createSpy().and.callFake(function () {
|
||||||
.createSpy()
|
|
||||||
.and.callFake(function () {
|
|
||||||
return sampleAuthConfiguration;
|
return sampleAuthConfiguration;
|
||||||
});
|
});
|
||||||
ngxLogger = jasmine.createSpyObj('NGXLogger', ['log', 'error', 'warn']);
|
ngxLogger = jasmine.createSpyObj('NGXLogger', ['log', 'error', 'warn']);
|
||||||
@@ -103,8 +100,7 @@ describe('AppComponent', () => {
|
|||||||
],
|
],
|
||||||
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
it('should create the app', () => {
|
it('should create the app', () => {
|
||||||
const fixture = TestBed.createComponent(AppComponent);
|
const fixture = TestBed.createComponent(AppComponent);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import {CUSTOM_ELEMENTS_SCHEMA, DebugElement} from '@angular/core';
|
import {CUSTOM_ELEMENTS_SCHEMA, DebugElement} from '@angular/core';
|
||||||
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
|
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||||
import {ActivatedRoute, RouterModule} from '@angular/router';
|
import {ActivatedRoute, RouterModule} from '@angular/router';
|
||||||
import {IonRefresher, IonTitle} from '@ionic/angular';
|
import {IonRefresher, IonTitle} from '@ionic/angular';
|
||||||
import {
|
import {
|
||||||
@@ -71,8 +71,7 @@ describe('DataDetailComponent', () => {
|
|||||||
'search',
|
'search',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
beforeEach(
|
beforeEach(() => {
|
||||||
waitForAsync(() => {
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
RouterModule.forRoot([], {relativeLinkResolution: 'legacy'}),
|
RouterModule.forRoot([], {relativeLinkResolution: 'legacy'}),
|
||||||
@@ -94,10 +93,9 @@ describe('DataDetailComponent', () => {
|
|||||||
],
|
],
|
||||||
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(() => {
|
||||||
dataProvider = TestBed.get(DataProvider);
|
dataProvider = TestBed.get(DataProvider);
|
||||||
translateService = TestBed.get(TranslateService);
|
translateService = TestBed.get(TranslateService);
|
||||||
refresher = jasmine.createSpyObj('refresher', ['complete']);
|
refresher = jasmine.createSpyObj('refresher', ['complete']);
|
||||||
@@ -105,7 +103,7 @@ describe('DataDetailComponent', () => {
|
|||||||
Promise.resolve(sampleThing),
|
Promise.resolve(sampleThing),
|
||||||
);
|
);
|
||||||
spyOn(DataDetailComponent.prototype, 'getItem').and.callThrough();
|
spyOn(DataDetailComponent.prototype, 'getItem').and.callThrough();
|
||||||
fixture = await TestBed.createComponent(DataDetailComponent);
|
fixture = TestBed.createComponent(DataDetailComponent);
|
||||||
comp = fixture.componentInstance;
|
comp = fixture.componentInstance;
|
||||||
detailPage = fixture.debugElement;
|
detailPage = fixture.debugElement;
|
||||||
translateService.use('foo');
|
translateService.use('foo');
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
|
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||||
|
|
||||||
import {DataListComponent} from './data-list.component';
|
import {DataListComponent} from './data-list.component';
|
||||||
import {TranslateModule} from '@ngx-translate/core';
|
import {TranslateModule} from '@ngx-translate/core';
|
||||||
@@ -10,8 +10,7 @@ describe('DataListComponent', () => {
|
|||||||
let fixture: ComponentFixture<DataListComponent>;
|
let fixture: ComponentFixture<DataListComponent>;
|
||||||
let configProviderMock: jasmine.SpyObj<ConfigProvider>;
|
let configProviderMock: jasmine.SpyObj<ConfigProvider>;
|
||||||
|
|
||||||
beforeEach(
|
beforeEach(() => {
|
||||||
waitForAsync(() => {
|
|
||||||
configProviderMock = jasmine.createSpyObj('ConfigProvider', {
|
configProviderMock = jasmine.createSpyObj('ConfigProvider', {
|
||||||
getValue: () => {
|
getValue: () => {
|
||||||
return {lat: 123, lng: 123};
|
return {lat: 123, lng: 123};
|
||||||
@@ -23,8 +22,7 @@ describe('DataListComponent', () => {
|
|||||||
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
||||||
providers: [{provide: ConfigProvider, useValue: configProviderMock}],
|
providers: [{provide: ConfigProvider, useValue: configProviderMock}],
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = TestBed.createComponent(DataListComponent);
|
fixture = TestBed.createComponent(DataListComponent);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
|
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
|
||||||
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
|
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||||
import {ActivatedRoute, RouterModule} from '@angular/router';
|
import {ActivatedRoute, RouterModule} from '@angular/router';
|
||||||
import {IonRefresher} from '@ionic/angular';
|
import {IonRefresher} from '@ionic/angular';
|
||||||
import {
|
import {
|
||||||
@@ -72,8 +72,7 @@ describe('DaiaAvailabilityComponent', () => {
|
|||||||
'search',
|
'search',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
beforeEach(
|
beforeEach(() => {
|
||||||
waitForAsync(() => {
|
|
||||||
configProviderMock = jasmine.createSpyObj('ConfigProvider', [
|
configProviderMock = jasmine.createSpyObj('ConfigProvider', [
|
||||||
'init',
|
'init',
|
||||||
'getValue',
|
'getValue',
|
||||||
@@ -107,8 +106,7 @@ describe('DaiaAvailabilityComponent', () => {
|
|||||||
],
|
],
|
||||||
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
dataProvider = TestBed.get(DaiaDataProvider);
|
dataProvider = TestBed.get(DaiaDataProvider);
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-non-null-assertion,@typescript-eslint/no-explicit-any */
|
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2018, 2019 StApps
|
* Copyright (C) 2018, 2019 StApps
|
||||||
* This program is free software: you can redistribute it and/or modify it
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
@@ -13,8 +12,9 @@
|
|||||||
* You should have received a copy of the GNU General Public License along with
|
* You should have received a copy of the GNU General Public License along with
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
/* eslint-disable @typescript-eslint/no-non-null-assertion,@typescript-eslint/no-explicit-any */
|
||||||
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
|
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
|
||||||
import {ComponentFixture, TestBed, waitForAsync} from '@angular/core/testing';
|
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||||
import {ActivatedRoute, RouterModule} from '@angular/router';
|
import {ActivatedRoute, RouterModule} from '@angular/router';
|
||||||
import {IonRefresher} from '@ionic/angular';
|
import {IonRefresher} from '@ionic/angular';
|
||||||
import {
|
import {
|
||||||
@@ -69,8 +69,7 @@ describe('HebisDetailComponent', () => {
|
|||||||
'search',
|
'search',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
beforeEach(
|
beforeEach(() => {
|
||||||
waitForAsync(() => {
|
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
RouterModule.forRoot([], {relativeLinkResolution: 'legacy'}),
|
RouterModule.forRoot([], {relativeLinkResolution: 'legacy'}),
|
||||||
@@ -92,10 +91,9 @@ describe('HebisDetailComponent', () => {
|
|||||||
],
|
],
|
||||||
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(() => {
|
||||||
dataProvider = TestBed.get(HebisDataProvider);
|
dataProvider = TestBed.get(HebisDataProvider);
|
||||||
translateService = TestBed.get(TranslateService);
|
translateService = TestBed.get(TranslateService);
|
||||||
refresher = jasmine.createSpyObj('refresher', ['complete']);
|
refresher = jasmine.createSpyObj('refresher', ['complete']);
|
||||||
@@ -103,7 +101,7 @@ describe('HebisDetailComponent', () => {
|
|||||||
Promise.resolve(sampleThing),
|
Promise.resolve(sampleThing),
|
||||||
);
|
);
|
||||||
spyOn(HebisDetailComponent.prototype, 'getItem').and.callThrough();
|
spyOn(HebisDetailComponent.prototype, 'getItem').and.callThrough();
|
||||||
fixture = await TestBed.createComponent(HebisDetailComponent);
|
fixture = TestBed.createComponent(HebisDetailComponent);
|
||||||
comp = fixture.componentInstance;
|
comp = fixture.componentInstance;
|
||||||
translateService.use('foo');
|
translateService.use('foo');
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License along with
|
* You should have received a copy of the GNU General Public License along with
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
/* eslint-disable @typescript-eslint/no-non-null-assertion,@typescript-eslint/ban-ts-comment */
|
||||||
import {
|
import {
|
||||||
APP_BASE_HREF,
|
APP_BASE_HREF,
|
||||||
CommonModule,
|
CommonModule,
|
||||||
@@ -36,22 +37,21 @@ import {FilterContext, SortContext} from './context-type';
|
|||||||
import {Component} from '@angular/core';
|
import {Component} from '@angular/core';
|
||||||
import {By} from '@angular/platform-browser';
|
import {By} from '@angular/platform-browser';
|
||||||
|
|
||||||
|
// prettier-ignore
|
||||||
@Component({
|
@Component({
|
||||||
template: `
|
template: `<ion-content id="foo"></ion-content
|
||||||
<ion-content id="foo"></ion-content>
|
><stapps-context contentId="foo"></stapps-context>
|
||||||
<stapps-context contentId="foo"></stapps-context>
|
`,
|
||||||
`,
|
|
||||||
})
|
})
|
||||||
class ContextMenuComponentContainer {
|
class ContextMenuContainerComponent {}
|
||||||
}
|
|
||||||
|
|
||||||
describe('ContextMenuComponent', async () => {
|
describe('ContextMenuComponent', async () => {
|
||||||
let fixture: ComponentFixture<ContextMenuComponentContainer>;
|
let fixture: ComponentFixture<ContextMenuContainerComponent>;
|
||||||
let instance: ContextMenuComponent;
|
let instance: ContextMenuComponent;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
declarations: [ContextMenuComponent, ContextMenuComponentContainer],
|
declarations: [ContextMenuComponent, ContextMenuContainerComponent],
|
||||||
providers: [
|
providers: [
|
||||||
ChildrenOutletContexts,
|
ChildrenOutletContexts,
|
||||||
Location,
|
Location,
|
||||||
@@ -70,8 +70,10 @@ describe('ContextMenuComponent', async () => {
|
|||||||
],
|
],
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
|
|
||||||
fixture = TestBed.createComponent(ContextMenuComponentContainer);
|
fixture = TestBed.createComponent(ContextMenuContainerComponent);
|
||||||
instance = fixture.debugElement.query(By.directive(ContextMenuComponent)).componentInstance;
|
instance = fixture.debugElement.query(
|
||||||
|
By.directive(ContextMenuComponent),
|
||||||
|
).componentInstance;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show items in sort context', () => {
|
it('should show items in sort context', () => {
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ describe('ContextMenuService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should update filterQuery', done => {
|
it('should update filterQuery', done => {
|
||||||
service.filterContextChanged$.subscribe(() => {
|
service.filterContextChanged$.subscribe(result => {
|
||||||
service.contextFilterChanged(filterContext);
|
|
||||||
});
|
|
||||||
service.filterQueryChanged$.subscribe(result => {
|
|
||||||
expect(result).toBeDefined();
|
expect(result).toBeDefined();
|
||||||
|
expect(service.contextFilter.options[0].buckets.length).toEqual(
|
||||||
|
filterContext.options[0].buckets.length,
|
||||||
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
service.updateContextFilter(facetsMock);
|
service.updateContextFilter(facetsMock);
|
||||||
@@ -46,10 +46,7 @@ describe('ContextMenuService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should update sortQuery', done => {
|
it('should update sortQuery', done => {
|
||||||
service.sortContextChanged$.subscribe(() => {
|
service.sortContextChanged$.subscribe(result => {
|
||||||
service.contextSortChanged(sortContext);
|
|
||||||
});
|
|
||||||
service.sortQueryChanged$.subscribe(result => {
|
|
||||||
expect(result).toBeDefined();
|
expect(result).toBeDefined();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
|
import {CUSTOM_ELEMENTS_SCHEMA} from '@angular/core';
|
||||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
import {ComponentFixture, TestBed} from '@angular/core/testing';
|
||||||
import {HttpClientTestingModule} from '@angular/common/http/testing';
|
import {HttpClientTestingModule} from '@angular/common/http/testing';
|
||||||
import {RouterTestingModule} from '@angular/router/testing';
|
import {RouterTestingModule} from '@angular/router/testing';
|
||||||
import {AuthModule} from '../../auth/auth.module';
|
import {AuthModule} from '../../auth/auth.module';
|
||||||
@@ -30,7 +30,7 @@ describe('ProfilePage', () => {
|
|||||||
let configProvider: ConfigProvider;
|
let configProvider: ConfigProvider;
|
||||||
let storageProvider: jasmine.SpyObj<StorageProvider>;
|
let storageProvider: jasmine.SpyObj<StorageProvider>;
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(() => {
|
||||||
configProvider = jasmine.createSpyObj('ConfigProvider', [
|
configProvider = jasmine.createSpyObj('ConfigProvider', [
|
||||||
'init',
|
'init',
|
||||||
'getAnyValue',
|
'getAnyValue',
|
||||||
@@ -59,7 +59,7 @@ describe('ProfilePage', () => {
|
|||||||
],
|
],
|
||||||
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
}));
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = TestBed.createComponent(ProfilePageComponent);
|
fixture = TestBed.createComponent(ProfilePageComponent);
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/ban-ts-comment */
|
||||||
import {TestBed} from '@angular/core/testing';
|
import {TestBed} from '@angular/core/testing';
|
||||||
import {Storage} from '@ionic/storage-angular';
|
import {Storage} from '@ionic/storage-angular';
|
||||||
import {StorageModule} from './storage.module';
|
import {StorageModule} from './storage.module';
|
||||||
@@ -52,7 +52,7 @@ describe('StorageProvider', () => {
|
|||||||
|
|
||||||
it('should call ready method of storage on init', async () => {
|
it('should call ready method of storage on init', async () => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
spyOn(storage, 'create').and.callFake(() => Promise.resolve(undefined));
|
spyOn(storage, 'create').and.callFake(() => Promise.resolve());
|
||||||
await storageProvider.init();
|
await storageProvider.init();
|
||||||
|
|
||||||
expect(storage.create).toHaveBeenCalled();
|
expect(storage.create).toHaveBeenCalled();
|
||||||
@@ -69,9 +69,9 @@ describe('StorageProvider', () => {
|
|||||||
spyOn(storage, 'get').and.callFake(() => Promise.resolve());
|
spyOn(storage, 'get').and.callFake(() => Promise.resolve());
|
||||||
try {
|
try {
|
||||||
await storageProvider.get('some-uid');
|
await storageProvider.get('some-uid');
|
||||||
}
|
} catch {
|
||||||
// if not caught, causes issues and tests fail
|
// if not caught, causes issues and tests fail
|
||||||
catch {}
|
}
|
||||||
|
|
||||||
expect(storage.get).toHaveBeenCalledWith('some-uid');
|
expect(storage.get).toHaveBeenCalledWith('some-uid');
|
||||||
});
|
});
|
||||||
@@ -144,7 +144,9 @@ describe('StorageProvider', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should delete one or more entries from the storage', async () => {
|
it('should delete one or more entries from the storage', async () => {
|
||||||
const storageRemoveSpy = spyOn(storage, 'remove').and.callFake(() => Promise.resolve());
|
const storageRemoveSpy = spyOn(storage, 'remove').and.callFake(() =>
|
||||||
|
Promise.resolve(),
|
||||||
|
);
|
||||||
|
|
||||||
await storageProvider.delete('bar');
|
await storageProvider.delete('bar');
|
||||||
expect(storage.remove).toHaveBeenCalledTimes(1);
|
expect(storage.remove).toHaveBeenCalledTimes(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user