Add test fixtures.

This commit is contained in:
Spencer Ofwiti 2020-11-25 10:54:00 +03:00
parent f228a9866b
commit db4d713532
7 changed files with 153 additions and 0 deletions

View File

@ -0,0 +1,24 @@
import { convertToParamMap, ParamMap, Params } from '@angular/router';
import { ReplaySubject } from 'rxjs';
/**
* An ActivateRoute test double with a `paramMap` observable.
* Use the `setParamMap()` method to add the next `paramMap` value.
*/
export class ActivatedRouteStub {
// Use a ReplaySubject to share previous values with subscribers
// and pump new values into the `paramMap` observable
private subject = new ReplaySubject<ParamMap>();
constructor(initialParams?: Params) {
this.setParamMap(initialParams);
}
/** The mock paramMap observable */
readonly paramMap = this.subject.asObservable();
/** Set the paramMap observables's next value */
setParamMap(params?: Params): void {
this.subject.next(convertToParamMap(params));
}
}

6
src/testing/index.ts Normal file
View File

@ -0,0 +1,6 @@
export * from './activated-route-stub';
export * from './router-link-directive-stub';
export * from './shared-module-stub';
export * from './user-service-stub';
export * from './token-service-stub';
export * from './transaction-service-stub';

View File

@ -0,0 +1,14 @@
import {Directive, HostListener, Input} from '@angular/core';
@Directive({
selector: '[routerLink]'
})
export class RouterLinkDirectiveStub {
@Input('routerLink') linkParams: any;
navigatedTo: any = null;
@HostListener('click')
onClick(): void {
this.navigatedTo = this.linkParams;
}
}

View File

@ -0,0 +1,10 @@
import {Component} from '@angular/core';
@Component({selector: 'app-sidebar', template: ''})
export class SidebarStubComponent {}
@Component({selector: 'app-topbar', template: ''})
export class TopbarStubComponent {}
@Component({selector: 'app-footer', template: ''})
export class FooterStubComponent {}

View File

@ -0,0 +1,8 @@
export class TokenServiceStub {
getBySymbol(symbol: string): any {
return {
name: 'Reserve',
symbol: 'RSV'
};
}
}

View File

@ -0,0 +1,11 @@
import {Observable, of} from 'rxjs';
export class TransactionServiceStub {
setTransaction(transaction: any, cacheSize: number): void {}
setConversion(conversion: any): void {}
getAllTransactions(offset: number, limit: number): Observable<any> {
return of('Hello World');
}
}

View File

@ -0,0 +1,80 @@
import {Observable, of} from 'rxjs';
export class UserServiceStub {
users = [
{id: 1, name: 'John Doe', phone: '+25412345678', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'user', created: '08/16/2020', balance: '12987', failedPinAttempts: 1, status: 'approved', bio: 'Bodaboda', gender: 'male'},
{id: 2, name: 'Jane Buck', phone: '+25412341234', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'vendor', created: '04/02/2020', balance: '56281', failedPinAttempts: 0, status: 'approved', bio: 'Groceries', gender: 'female'},
{id: 3, name: 'Mc Donald', phone: '+25498765432', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'group', created: '11/16/2020', balance: '450', failedPinAttempts: 2, status: 'unapproved', bio: 'Food', gender: 'male'},
{id: 4, name: 'Hera Cles', phone: '+25498769876', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'user', created: '05/28/2020', balance: '5621', failedPinAttempts: 3, status: 'approved', bio: 'Shop', gender: 'female'},
{id: 5, name: 'Silver Fia', phone: '+25462518374', address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865', type: 'token agent', created: '10/10/2020', balance: '817', failedPinAttempts: 0, status: 'unapproved', bio: 'Electronics', gender: 'male'},
];
actions = [
{ id: 1, user: 'Tom', role: 'enroller', action: 'Disburse RSV 100', approval: false },
{ id: 2, user: 'Christine', role: 'admin', action: 'Change user phone number', approval: true },
{ id: 3, user: 'Will', role: 'superadmin', action: 'Reclaim RSV 1000', approval: true },
{ id: 4, user: 'Vivian', role: 'enroller', action: 'Complete user profile', approval: true },
{ id: 5, user: 'Jack', role: 'enroller', action: 'Reclaim RSV 200', approval: false },
{ id: 6, user: 'Patience', role: 'enroller', action: 'Change user information', approval: false }
];
getUserById(id: string): any {
return {
id: 1,
name: 'John Doe',
phone: '+25412345678',
address: '0xc86ff893ac40d3950b4d5f94a9b837258b0a9865',
type: 'user',
created: '08/16/2020',
balance: '12987',
failedPinAttempts: 1,
status: 'approved',
bio: 'Bodaboda',
gender: 'male'
};
}
getUser(userKey: string): Observable<any> {
console.log('Here');
return of({
dateRegistered: 1595537208,
key: {
ethereum: [
'0x51d3c8e2e421604e2b644117a362d589c5434739',
'0x9D7c284907acbd4a0cE2dDD0AA69147A921a573D'
]
},
location: {
external: {},
latitude: '22.430670',
longitude: '151.002995'
},
selling: [
'environment',
'health',
'transport'
],
vcard: 'QkVHSU46VkNBUkQNClZFUlNJT046My4wDQpFTUFJTDphYXJuZXNlbkBob3RtYWlsLmNvbQ0KRk46S3VydMKgS3JhbmpjDQpOOktyYW5qYztLdXJ0Ozs7DQpURUw7VFlQPUNFTEw6NjkyNTAzMzQ5ODE5Ng0KRU5EOlZDQVJEDQo='
});
}
getActionById(id: string): any {
return {
id: 1,
user: 'Tom',
role: 'enroller',
action: 'Disburse RSV 100',
approval: false
};
}
approveAction(id: number): any {
return {
id: 1,
user: 'Tom',
role: 'enroller',
action: 'Disburse RSV 100',
approval: true
};
}
}