mirror of
https://github.com/ringtools/ringtools-web-v2.git
synced 2025-02-21 22:11:37 +01:00
Fixed tests
This commit is contained in:
parent
c31eef4eee
commit
c313bd4973
18 changed files with 204 additions and 45 deletions
|
@ -25,11 +25,4 @@ describe('AppComponent', () => {
|
|||
const app = fixture.componentInstance;
|
||||
expect(app.title).toEqual('ringtools-web');
|
||||
});
|
||||
|
||||
it('should render title', () => {
|
||||
const fixture = TestBed.createComponent(AppComponent);
|
||||
fixture.detectChanges();
|
||||
const compiled = fixture.nativeElement as HTMLElement;
|
||||
expect(compiled.querySelector('.content span')?.textContent).toContain('ringtools-web app is running!');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,16 +1,26 @@
|
|||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { provideMockStore, MockStore } from '@ngrx/store/testing';
|
||||
import { initialSettingState } from 'src/app/reducers/setting.reducer';
|
||||
|
||||
import { OverviewComponent } from './overview.component';
|
||||
|
||||
describe('OverviewComponent', () => {
|
||||
let component: OverviewComponent;
|
||||
let fixture: ComponentFixture<OverviewComponent>;
|
||||
const initialState = { setting: initialSettingState };
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ OverviewComponent ]
|
||||
declarations: [ OverviewComponent ],
|
||||
imports: [ HttpClientTestingModule ],
|
||||
providers: [
|
||||
provideMockStore({ initialState }),
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
let store: MockStore;
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -1,14 +1,23 @@
|
|||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { provideMockStore } from '@ngrx/store/testing';
|
||||
import { initialSettingState } from 'src/app/reducers/setting.reducer';
|
||||
|
||||
import { RingOnlyComponent } from './ring-only.component';
|
||||
|
||||
describe('RingOnlyComponent', () => {
|
||||
let component: RingOnlyComponent;
|
||||
let fixture: ComponentFixture<RingOnlyComponent>;
|
||||
const initialState = { setting: initialSettingState };
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ RingOnlyComponent ]
|
||||
declarations: [ RingOnlyComponent ],
|
||||
imports: [ RouterTestingModule, HttpClientTestingModule ],
|
||||
providers: [
|
||||
provideMockStore({ initialState }),
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
|
|
@ -1,16 +1,28 @@
|
|||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { MockStore, provideMockStore } from '@ngrx/store/testing';
|
||||
import { initialSettingState } from 'src/app/reducers/setting.reducer';
|
||||
|
||||
import { SettingsComponent } from './settings.component';
|
||||
|
||||
describe('SettingsComponent', () => {
|
||||
let component: SettingsComponent;
|
||||
let fixture: ComponentFixture<SettingsComponent>;
|
||||
let store: MockStore;
|
||||
const initialState = { setting: initialSettingState };
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ SettingsComponent ]
|
||||
declarations: [ SettingsComponent ],
|
||||
imports: [ RouterTestingModule, HttpClientTestingModule ],
|
||||
providers: [
|
||||
provideMockStore({ initialState }),
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
store = TestBed.inject(MockStore);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -1,14 +1,24 @@
|
|||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { provideMockStore } from '@ngrx/store/testing';
|
||||
import { initialSettingState } from 'src/app/reducers/setting.reducer';
|
||||
|
||||
import { VisualComponent } from './visual.component';
|
||||
|
||||
describe('VisualComponent', () => {
|
||||
let component: VisualComponent;
|
||||
let fixture: ComponentFixture<VisualComponent>;
|
||||
const initialState = {
|
||||
setting: initialSettingState
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ VisualComponent ]
|
||||
declarations: [ VisualComponent ],
|
||||
imports: [ HttpClientTestingModule ],
|
||||
providers: [
|
||||
provideMockStore({ initialState }),
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { BaseComponent } from './base.component';
|
||||
import { BaseLayoutComponent } from './base.component';
|
||||
|
||||
describe('BaseComponent', () => {
|
||||
let component: BaseComponent;
|
||||
let fixture: ComponentFixture<BaseComponent>;
|
||||
let component: BaseLayoutComponent;
|
||||
let fixture: ComponentFixture<BaseLayoutComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ BaseComponent ]
|
||||
declarations: [ BaseLayoutComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(BaseComponent);
|
||||
fixture = TestBed.createComponent(BaseLayoutComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
|
|
@ -1,14 +1,22 @@
|
|||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { RouterTestingModule } from '@angular/router/testing';
|
||||
import { provideMockStore, MockStore } from '@ngrx/store/testing';
|
||||
import { initialSettingState } from 'src/app/reducers/setting.reducer';
|
||||
|
||||
import { NavigationComponent } from './navigation.component';
|
||||
|
||||
describe('NavigationComponent', () => {
|
||||
let component: NavigationComponent;
|
||||
let fixture: ComponentFixture<NavigationComponent>;
|
||||
|
||||
const initialState = { setting: initialSettingState };
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ NavigationComponent ]
|
||||
declarations: [ NavigationComponent ],
|
||||
imports: [ RouterTestingModule ],
|
||||
providers: [
|
||||
provideMockStore({ initialState })
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
|
|
@ -1,14 +1,23 @@
|
|||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { provideMockStore } from '@ngrx/store/testing';
|
||||
import { DragulaModule, DragulaService } from 'ng2-dragula';
|
||||
|
||||
import { EditRingOrderComponent } from './edit-ring-order.component';
|
||||
|
||||
describe('EditRingOrderComponent', () => {
|
||||
let component: EditRingOrderComponent;
|
||||
let fixture: ComponentFixture<EditRingOrderComponent>;
|
||||
const initialState = { loggedIn: false };
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ EditRingOrderComponent ]
|
||||
declarations: [ EditRingOrderComponent ],
|
||||
imports: [ DragulaModule, HttpClientTestingModule ],
|
||||
providers: [
|
||||
provideMockStore({ initialState }),
|
||||
DragulaService
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
|
|
@ -1,14 +1,22 @@
|
|||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { provideMockStore } from '@ngrx/store/testing';
|
||||
import { initialSettingState } from 'src/app/reducers/setting.reducer';
|
||||
|
||||
import { FileExporterComponent } from './file-exporter.component';
|
||||
|
||||
describe('FileExporterComponent', () => {
|
||||
let component: FileExporterComponent;
|
||||
let fixture: ComponentFixture<FileExporterComponent>;
|
||||
const initialState = { setting: initialSettingState };
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ FileExporterComponent ]
|
||||
declarations: [ FileExporterComponent ],
|
||||
imports: [ HttpClientTestingModule ],
|
||||
providers: [
|
||||
provideMockStore({ initialState }),
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
|
|
@ -1,14 +1,23 @@
|
|||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { provideMockStore } from '@ngrx/store/testing';
|
||||
import { initialSettingState } from 'src/app/reducers/setting.reducer';
|
||||
import { VisModule } from 'src/app/vis/vis.module';
|
||||
|
||||
import { NodeConnectionsComponent } from './node-connections.component';
|
||||
|
||||
describe('NodeConnectionsComponent', () => {
|
||||
let component: NodeConnectionsComponent;
|
||||
let fixture: ComponentFixture<NodeConnectionsComponent>;
|
||||
const initialState = { setting: initialSettingState };
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ NodeConnectionsComponent ]
|
||||
declarations: [ NodeConnectionsComponent ],
|
||||
imports: [ HttpClientTestingModule, VisModule ],
|
||||
providers: [
|
||||
provideMockStore({ initialState }),
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
|
|
@ -1,14 +1,21 @@
|
|||
import { JsonPipe } from '@angular/common';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { provideMockStore } from '@ngrx/store/testing';
|
||||
|
||||
import { ParticipantTableComponent } from './participant-table.component';
|
||||
|
||||
describe('ParticipantTableComponent', () => {
|
||||
let component: ParticipantTableComponent;
|
||||
let fixture: ComponentFixture<ParticipantTableComponent>;
|
||||
const initialState = { loggedIn: false };
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ ParticipantTableComponent ]
|
||||
declarations: [ ParticipantTableComponent ],
|
||||
providers: [
|
||||
JsonPipe,
|
||||
provideMockStore({ initialState }),
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
|
|
@ -1,14 +1,21 @@
|
|||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { provideMockStore } from '@ngrx/store/testing';
|
||||
import { initialSettingState } from 'src/app/reducers/setting.reducer';
|
||||
|
||||
import { ReorderParticipantsComponent } from './reorder-participants.component';
|
||||
|
||||
describe('ReorderParticipantsComponent', () => {
|
||||
let component: ReorderParticipantsComponent;
|
||||
let fixture: ComponentFixture<ReorderParticipantsComponent>;
|
||||
|
||||
const initialState = {
|
||||
settings: initialSettingState
|
||||
}
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [ ReorderParticipantsComponent ]
|
||||
declarations: [ ReorderParticipantsComponent ],
|
||||
providers: [
|
||||
provideMockStore({ initialState }),
|
||||
]
|
||||
})
|
||||
.compileComponents();
|
||||
});
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
import { reducer, initialState } from './setting.reducer';
|
||||
import { reducer, initialSettingState } from './setting.reducer';
|
||||
|
||||
describe('Setting Reducer', () => {
|
||||
describe('an unknown action', () => {
|
||||
it('should return the previous state', () => {
|
||||
const action = {} as any;
|
||||
|
||||
const result = reducer(initialState, action);
|
||||
const result = reducer(initialSettingState, action);
|
||||
|
||||
expect(result).toBe(initialState);
|
||||
expect(result).toBe(initialSettingState);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -12,7 +12,7 @@ export interface SettingState {
|
|||
ringLeader?: NodeOwner;
|
||||
}
|
||||
|
||||
export const initialState: SettingState = {
|
||||
export const initialSettingState: SettingState = {
|
||||
ringName: 'Unconfigured',
|
||||
viewMode: 'tg',
|
||||
showLogo: false,
|
||||
|
@ -20,7 +20,7 @@ export const initialState: SettingState = {
|
|||
};
|
||||
|
||||
export const settingReducer = createReducer(
|
||||
initialState,
|
||||
initialSettingState,
|
||||
on(SettingActions.setRingName,
|
||||
(state: SettingState, {ringName}) => {
|
||||
return {...state, ringName: ringName }
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { LnDataService } from './ln-data.service';
|
||||
|
@ -6,7 +7,11 @@ describe('LnDataService', () => {
|
|||
let service: LnDataService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
HttpClientTestingModule
|
||||
],
|
||||
});
|
||||
service = TestBed.inject(LnDataService);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,12 +1,23 @@
|
|||
import { TestBed } from '@angular/core/testing';
|
||||
import { provideMockStore } from '@ngrx/store/testing';
|
||||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
|
||||
import { RingDataService } from './ring-data.service';
|
||||
|
||||
describe('RingDataService', () => {
|
||||
let service: RingDataService;
|
||||
|
||||
const initialState = { loggedIn: false };
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
TestBed.configureTestingModule({
|
||||
imports: [
|
||||
HttpClientTestingModule
|
||||
],
|
||||
providers: [
|
||||
provideMockStore({ initialState }),
|
||||
|
||||
]
|
||||
});
|
||||
service = TestBed.inject(RingDataService);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
import { VisNetworkDirective } from './vis-network.directive';
|
||||
|
||||
describe('VisNetworkDirective', () => {
|
||||
it('should create an instance', () => {
|
||||
const directive = new VisNetworkDirective();
|
||||
expect(directive).toBeTruthy();
|
||||
});
|
||||
});
|
|
@ -3,14 +3,83 @@ import { TestBed } from '@angular/core/testing';
|
|||
import { VisNetworkService } from './vis-network.service';
|
||||
|
||||
describe('VisNetworkService', () => {
|
||||
let service: VisNetworkService;
|
||||
let visNetworkService: VisNetworkService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(VisNetworkService);
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
VisNetworkService
|
||||
]
|
||||
});
|
||||
visNetworkService = TestBed.inject(VisNetworkService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
it('returns undefined when network id is unknown', () => {
|
||||
const selection = visNetworkService.getSelection('unknown');
|
||||
expect(selection).toBeUndefined();
|
||||
const selectedNodes = visNetworkService.getSelectedNodes('unknown');
|
||||
expect(selectedNodes).toBeUndefined();
|
||||
const selectedEdges = visNetworkService.getSelectedEdges('unknown');
|
||||
expect(selectedEdges).toBeUndefined();
|
||||
});
|
||||
|
||||
it('throws no error when the network does not exist', () => {
|
||||
visNetworkService.destroy('unknown');
|
||||
});
|
||||
|
||||
it('throws error when network already exists', () => {
|
||||
const dummyElement = document.createElement('div');
|
||||
visNetworkService.create('knownNetwork', dummyElement, { nodes: [], edges: [] });
|
||||
expect(() => visNetworkService.create('knownNetwork', dummyElement, { nodes: [], edges: [] })).toThrowError();
|
||||
});
|
||||
|
||||
it('returns false when network does not exist', () => {
|
||||
expect(visNetworkService.on('unknown', 'click')).toBe(false);
|
||||
expect(visNetworkService.once('unknown', 'click')).toBe(false);
|
||||
visNetworkService.off('unknown', 'click');
|
||||
expect(visNetworkService.isCluster('unknown', 'nodeId')).toBe(false);
|
||||
});
|
||||
|
||||
it('throws error when network does not exist', () => {
|
||||
expect(() => visNetworkService.setData('unknown', { nodes: [], edges: [] })).toThrowError();
|
||||
expect(() => visNetworkService.setOptions('unknown', {})).toThrowError();
|
||||
expect(() => visNetworkService.selectNodes('unknown', [])).toThrowError();
|
||||
expect(() => visNetworkService.selectNodes('unknown', [], false)).toThrowError();
|
||||
expect(() => visNetworkService.setSelection('unknown', { nodes: [], edges: [] })).toThrowError();
|
||||
expect(() => visNetworkService.setSelection('unknown', { nodes: [], edges: [] }, {})).toThrowError();
|
||||
expect(() => visNetworkService.setSelection('unknown', { nodes: [], edges: [] }, { unselectAll: false, highlightEdges: false })).toThrowError();
|
||||
expect(() => visNetworkService.unselectAll('unknown')).toThrowError();
|
||||
expect(() => visNetworkService.fit('unknown')).toThrowError();
|
||||
expect(() => visNetworkService.getScale('unknown')).toThrowError();
|
||||
expect(() => visNetworkService.fit('unknown', { animation: true })).toThrowError();
|
||||
expect(() => visNetworkService.redraw('unknown')).toThrowError();
|
||||
expect(() => visNetworkService.enableEditMode('unknown')).toThrowError();
|
||||
expect(() => visNetworkService.addEdgeMode('unknown')).toThrowError();
|
||||
expect(() => visNetworkService.addNodeMode('unknown')).toThrowError();
|
||||
expect(() => visNetworkService.disableEditMode('unknown')).toThrowError();
|
||||
expect(() => visNetworkService.deleteSelected('unknown')).toThrowError();
|
||||
expect(() => visNetworkService.cluster('unknown')).toThrowError();
|
||||
expect(() => visNetworkService.cluster('unknown', {})).toThrowError();
|
||||
expect(() => visNetworkService.clusterByConnection('unknown', 42, {})).toThrowError();
|
||||
expect(() => visNetworkService.clusterByConnection('unknown', 42)).toThrowError();
|
||||
expect(() => visNetworkService.clusterByHubsize('unknown', 42, {})).toThrowError();
|
||||
expect(() => visNetworkService.clusterByHubsize('unknown', 42)).toThrowError();
|
||||
expect(() => visNetworkService.clusterOutliers('unknown', {})).toThrowError();
|
||||
expect(() => visNetworkService.clusterOutliers('unknown')).toThrowError();
|
||||
expect(() => visNetworkService.findNode('unknown', 42)).toThrowError();
|
||||
expect(() => visNetworkService.getClusteredEdges('unknown', 42)).toThrowError();
|
||||
expect(() => visNetworkService.getBaseEdge('unknown', 42)).toThrowError();
|
||||
expect(() => visNetworkService.updateEdge('unknown', 42)).toThrowError();
|
||||
expect(() => visNetworkService.updateEdge('unknown', 42)).toThrowError();
|
||||
expect(() => visNetworkService.updateClusteredNode('unknown', 42)).toThrowError();
|
||||
expect(() => visNetworkService.updateClusteredNode('unknown', 42, {})).toThrowError();
|
||||
expect(() => visNetworkService.getNodesInCluster('unknown', 42)).toThrowError();
|
||||
expect(() => visNetworkService.openCluster('unknown', 'nodeId')).toThrowError();
|
||||
expect(() => visNetworkService.canvasToDOM('unknown', { x: 1, y: 1 })).toThrowError();
|
||||
expect(() => visNetworkService.DOMtoCanvas('unknown', { x: 1, y: 1 })).toThrowError();
|
||||
});
|
||||
|
||||
it('returns -1 when network does not exist', () => {
|
||||
expect(visNetworkService.getSeed('unknown')).toBe(-1);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue