diff --git a/src/testing/activated-route-stub.ts b/src/testing/activated-route-stub.ts new file mode 100644 index 0000000..ad73d78 --- /dev/null +++ b/src/testing/activated-route-stub.ts @@ -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(); + + 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)); + } +} diff --git a/src/testing/index.ts b/src/testing/index.ts new file mode 100644 index 0000000..277364a --- /dev/null +++ b/src/testing/index.ts @@ -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'; diff --git a/src/testing/router-link-directive-stub.ts b/src/testing/router-link-directive-stub.ts new file mode 100644 index 0000000..37954f5 --- /dev/null +++ b/src/testing/router-link-directive-stub.ts @@ -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; + } +} diff --git a/src/testing/shared-module-stub.ts b/src/testing/shared-module-stub.ts new file mode 100644 index 0000000..d74d246 --- /dev/null +++ b/src/testing/shared-module-stub.ts @@ -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 {} diff --git a/src/testing/token-service-stub.ts b/src/testing/token-service-stub.ts new file mode 100644 index 0000000..7cba280 --- /dev/null +++ b/src/testing/token-service-stub.ts @@ -0,0 +1,8 @@ +export class TokenServiceStub { + getBySymbol(symbol: string): any { + return { + name: 'Reserve', + symbol: 'RSV' + }; + } +} diff --git a/src/testing/transaction-service-stub.ts b/src/testing/transaction-service-stub.ts new file mode 100644 index 0000000..5b05098 --- /dev/null +++ b/src/testing/transaction-service-stub.ts @@ -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 { + return of('Hello World'); + } +} diff --git a/src/testing/user-service-stub.ts b/src/testing/user-service-stub.ts new file mode 100644 index 0000000..ba19a02 --- /dev/null +++ b/src/testing/user-service-stub.ts @@ -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 { + 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 + }; + } +}