Compare commits

...

7 Commits

Author SHA1 Message Date
Spencer Ofwiti
9dd4f6de4e Merge branch 'master' into spencer/fix-tests 2021-06-29 19:22:57 +03:00
Spencer Ofwiti
faa0758f95 Fix safe pipe in pages component tests. 2021-06-25 12:07:13 +03:00
Spencer Ofwiti
0343142a38 Fix tests for directives. 2021-06-25 11:53:06 +03:00
Spencer Ofwiti
f5c69cc574 Revert auth guard handler. 2021-06-25 11:03:00 +03:00
Spencer Ofwiti
599ffe9079 Fix tests. 2021-06-25 09:40:29 +03:00
Spencer Ofwiti
78a8558882 Add HttpClient and Router testing modules to test. 2021-06-24 20:51:06 +03:00
Spencer Ofwiti
7e93aea96f Fix broken tests. 2021-06-24 19:34:02 +03:00
19 changed files with 168 additions and 55 deletions

View File

@ -100,5 +100,9 @@
"hooks": { "hooks": {
"pre-commit": "npx pretty-quick --staged && npm run format:lint && npx lint-staged" "pre-commit": "npx pretty-quick --staged && npm run format:lint && npx lint-staged"
} }
},
"browser": {
"child_process": false,
"fs": false
} }
} }

View File

@ -3,12 +3,15 @@ import { TestBed } from '@angular/core/testing';
// Application imports // Application imports
import { AuthGuard } from '@app/_guards/auth.guard'; import { AuthGuard } from '@app/_guards/auth.guard';
import { RouterTestingModule } from '@angular/router/testing';
describe('AuthGuard', () => { describe('AuthGuard', () => {
let guard: AuthGuard; let guard: AuthGuard;
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({}); TestBed.configureTestingModule({
imports: [RouterTestingModule],
});
guard = TestBed.inject(AuthGuard); guard = TestBed.inject(AuthGuard);
}); });

View File

@ -3,12 +3,15 @@ import { TestBed } from '@angular/core/testing';
// Application imports // Application imports
import { RoleGuard } from '@app/_guards/role.guard'; import { RoleGuard } from '@app/_guards/role.guard';
import { RouterTestingModule } from '@angular/router/testing';
describe('RoleGuard', () => { describe('RoleGuard', () => {
let guard: RoleGuard; let guard: RoleGuard;
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({}); TestBed.configureTestingModule({
imports: [RouterTestingModule],
});
guard = TestBed.inject(RoleGuard); guard = TestBed.inject(RoleGuard);
}); });

View File

@ -3,10 +3,12 @@ import { TestBed } from '@angular/core/testing';
// Application imports // Application imports
import { ErrorInterceptor } from '@app/_interceptors/error.interceptor'; import { ErrorInterceptor } from '@app/_interceptors/error.interceptor';
import { MatDialogModule } from '@angular/material/dialog';
describe('ErrorInterceptor', () => { describe('ErrorInterceptor', () => {
beforeEach(() => beforeEach(() =>
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [MatDialogModule],
providers: [ErrorInterceptor], providers: [ErrorInterceptor],
}) })
); );

View File

@ -1,12 +1,15 @@
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { AuthService } from '@app/_services/auth.service'; import { AuthService } from '@app/_services/auth.service';
import { HttpClientTestingModule } from '@angular/common/http/testing';
describe('AuthService', () => { describe('AuthService', () => {
let service: AuthService; let service: AuthService;
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({}); TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
});
service = TestBed.inject(AuthService); service = TestBed.inject(AuthService);
}); });

View File

@ -1,12 +1,15 @@
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { ErrorDialogService } from './error-dialog.service'; import { ErrorDialogService } from './error-dialog.service';
import { MatDialogModule } from '@angular/material/dialog';
describe('ErrorDialogService', () => { describe('ErrorDialogService', () => {
let service: ErrorDialogService; let service: ErrorDialogService;
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({}); TestBed.configureTestingModule({
imports: [MatDialogModule],
});
service = TestBed.inject(ErrorDialogService); service = TestBed.inject(ErrorDialogService);
}); });

View File

@ -1,12 +1,15 @@
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { LocationService } from '@app/_services/location.service'; import { LocationService } from '@app/_services/location.service';
import { HttpClientTestingModule } from '@angular/common/http/testing';
describe('LocationService', () => { describe('LocationService', () => {
let service: LocationService; let service: LocationService;
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({}); TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
});
service = TestBed.inject(LocationService); service = TestBed.inject(LocationService);
}); });

View File

@ -1,6 +1,7 @@
import { TestBed } from '@angular/core/testing'; import { TestBed } from '@angular/core/testing';
import { TokenService } from '@app/_services/token.service'; import { TokenService } from '@app/_services/token.service';
import { Token } from '@app/_models';
describe('TokenService', () => { describe('TokenService', () => {
let service: TokenService; let service: TokenService;
@ -15,10 +16,27 @@ describe('TokenService', () => {
}); });
it('should return token for available token', () => { it('should return token for available token', () => {
expect(service.getTokenBySymbol('RSV')).toEqual({ name: 'Reserve', symbol: 'RSV' }); const token: Token = {
name: 'Giftable Reserve',
symbol: 'GRZ',
address: '0xa686005CE37Dce7738436256982C3903f2E4ea8E',
supply: '1000000001000000000000000000',
decimals: '18',
reserves: {},
};
service.addToken(token);
service.getTokenBySymbol('GRZ').then((tokenSubject) => {
tokenSubject.subscribe((returnedToken) => {
expect(returnedToken).toEqual(token);
});
});
}); });
it('should not return token for unavailable token', () => { it('should not return token for unavailable token', () => {
expect(service.getTokenBySymbol('ABC')).toBeUndefined(); service.getTokenBySymbol('ABC').then((tokenSubject) => {
tokenSubject.subscribe((returnedToken) => {
expect(returnedToken).toBeUndefined();
});
});
}); });
}); });

View File

@ -23,38 +23,52 @@ describe('UserService', () => {
}); });
it('should return action for available id', () => { it('should return action for available id', () => {
expect(service.getActionById('1')).toEqual({ service.getActionById('1').subscribe((returnedAction) => {
expect(
returnedAction.toEqual({
id: 1, id: 1,
user: 'Tom', user: 'Tom',
role: 'enroller', role: 'enroller',
action: 'Disburse RSV 100', action: 'Disburse RSV 100',
approval: false, approval: false,
})
);
}); });
}); });
it('should not return action for unavailable id', () => { it('should not return action for unavailable id', () => {
expect(service.getActionById('9999999999')).toBeUndefined(); service.getActionById('9999999999').subscribe((returnedAction) => {
expect(returnedAction.toBeUndefined());
});
}); });
it('should switch action approval from false to true', () => { it('should switch action approval from false to true', () => {
service.approveAction('1'); service.approveAction('1');
expect(service.getActionById('1')).toEqual({ service.getActionById('1').subscribe((returnedAction) => {
expect(
returnedAction.toEqual({
id: 1, id: 1,
user: 'Tom', user: 'Tom',
role: 'enroller', role: 'enroller',
action: 'Disburse RSV 100', action: 'Disburse RSV 100',
approval: true, approval: true,
})
);
}); });
}); });
it('should switch action approval from true to false', () => { it('should switch action approval from true to false', () => {
service.revokeAction('2'); service.revokeAction('2');
expect(service.getActionById('2')).toEqual({ service.getActionById('2').subscribe((returnedAction) => {
expect(
returnedAction.toEqual({
id: 2, id: 2,
user: 'Christine', user: 'Christine',
role: 'admin', role: 'admin',
action: 'Change user phone number', action: 'Change user phone number',
approval: false, approval: false,
})
);
}); });
}); });
}); });

View File

@ -8,11 +8,12 @@ import {
TopbarStubComponent, TopbarStubComponent,
TransactionServiceStub, TransactionServiceStub,
} from '@src/testing'; } from '@src/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
describe('AppComponent', () => { describe('AppComponent', () => {
beforeEach(async () => { beforeEach(async () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
imports: [RouterTestingModule], imports: [HttpClientTestingModule, RouterTestingModule],
declarations: [AppComponent, FooterStubComponent, SidebarStubComponent, TopbarStubComponent], declarations: [AppComponent, FooterStubComponent, SidebarStubComponent, TopbarStubComponent],
providers: [{ provide: TransactionService, useClass: TransactionServiceStub }], providers: [{ provide: TransactionService, useClass: TransactionServiceStub }],
}).compileComponents(); }).compileComponents();

View File

@ -1,17 +1,33 @@
// Core imports // Core imports
import { ElementRef, Renderer2 } from '@angular/core'; import { Component, DebugElement } from '@angular/core';
// Application imports // Application imports
import { PasswordToggleDirective } from '@app/auth/_directives/password-toggle.directive'; import { PasswordToggleDirective } from '@app/auth/_directives/password-toggle.directive';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
// tslint:disable-next-line:prefer-const @Component({
let elementRef: ElementRef; template: ` <div>
// tslint:disable-next-line:prefer-const <input type="password" id="password" />
let renderer: Renderer2; <span id="icon" class="fa fa-eye" appPasswordToggle [id]="'password'" [iconId]="'icon'"></span>
</div>`,
})
class TestComponent {}
describe('PasswordToggleDirective', () => { describe('PasswordToggleDirective', () => {
it('should create an instance', () => { let fixture: ComponentFixture<TestComponent>;
const directive = new PasswordToggleDirective(elementRef, renderer); let des: DebugElement[];
expect(directive).toBeTruthy();
beforeEach(() => {
fixture = TestBed.configureTestingModule({
declarations: [PasswordToggleDirective, TestComponent],
}).createComponent(TestComponent);
fixture.detectChanges();
des = fixture.debugElement.queryAll(By.directive(PasswordToggleDirective));
});
it('should have one element with menu-toggle directive', () => {
expect(des.length).toBe(1);
}); });
}); });

View File

@ -1,6 +1,7 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AuthComponent } from '@app/auth/auth.component'; import { AuthComponent } from '@app/auth/auth.component';
import { HttpClientTestingModule } from '@angular/common/http/testing';
describe('AuthComponent', () => { describe('AuthComponent', () => {
let component: AuthComponent; let component: AuthComponent;
@ -8,6 +9,7 @@ describe('AuthComponent', () => {
beforeEach(async () => { beforeEach(async () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
declarations: [AuthComponent], declarations: [AuthComponent],
}).compileComponents(); }).compileComponents();
}); });

View File

@ -1,6 +1,8 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AccountSearchComponent } from './account-search.component'; import { AccountSearchComponent } from './account-search.component';
import { ReactiveFormsModule } from '@angular/forms';
import { HttpClientTestingModule } from '@angular/common/http/testing';
describe('AccountSearchComponent', () => { describe('AccountSearchComponent', () => {
let component: AccountSearchComponent; let component: AccountSearchComponent;
@ -9,6 +11,7 @@ describe('AccountSearchComponent', () => {
beforeEach(async () => { beforeEach(async () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
declarations: [AccountSearchComponent], declarations: [AccountSearchComponent],
imports: [ReactiveFormsModule, HttpClientTestingModule],
}).compileComponents(); }).compileComponents();
}); });

View File

@ -48,7 +48,7 @@ describe('AdminComponent', () => {
it('#approveAction should toggle approval status', () => { it('#approveAction should toggle approval status', () => {
const action = userService.getActionById('1'); const action = userService.getActionById('1');
expect(action).toBe({ expect(action).toEqual({
id: 1, id: 1,
user: 'Tom', user: 'Tom',
role: 'enroller', role: 'enroller',

View File

@ -1,6 +1,8 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { PagesComponent } from '@pages/pages.component'; import { PagesComponent } from '@pages/pages.component';
import { SharedModule } from '@app/shared/shared.module';
import { RouterTestingModule } from '@angular/router/testing';
describe('PagesComponent', () => { describe('PagesComponent', () => {
let component: PagesComponent; let component: PagesComponent;
@ -8,6 +10,7 @@ describe('PagesComponent', () => {
beforeEach(async () => { beforeEach(async () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
imports: [SharedModule, RouterTestingModule],
declarations: [PagesComponent], declarations: [PagesComponent],
}).compileComponents(); }).compileComponents();
}); });

View File

@ -1,6 +1,8 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { TransactionDetailsComponent } from '@pages/transactions/transaction-details/transaction-details.component'; import { TransactionDetailsComponent } from '@pages/transactions/transaction-details/transaction-details.component';
import { RouterTestingModule } from '@angular/router/testing';
import { HttpClientTestingModule } from '@angular/common/http/testing';
describe('TransactionDetailsComponent', () => { describe('TransactionDetailsComponent', () => {
let component: TransactionDetailsComponent; let component: TransactionDetailsComponent;
@ -8,6 +10,7 @@ describe('TransactionDetailsComponent', () => {
beforeEach(async () => { beforeEach(async () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
imports: [RouterTestingModule, HttpClientTestingModule],
declarations: [TransactionDetailsComponent], declarations: [TransactionDetailsComponent],
}).compileComponents(); }).compileComponents();
}); });

View File

@ -1,21 +1,34 @@
// Core imports // Core imports
import { ElementRef, Renderer2 } from '@angular/core'; import { Component, DebugElement } from '@angular/core';
// Application imports // Application imports
import { MenuSelectionDirective } from '@app/shared/_directives/menu-selection.directive'; import { MenuSelectionDirective } from '@app/shared/_directives/menu-selection.directive';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
@Component({
template: ` <div appMenuSelection>
<div id="sidebar"></div>
<div id="content"></div>
<div id="sidebarCollapse"></div>
</div>`,
})
class TestComponent {}
describe('MenuSelectionDirective', () => { describe('MenuSelectionDirective', () => {
// tslint:disable-next-line:prefer-const let fixture: ComponentFixture<TestComponent>;
let elementRef: ElementRef; let des: DebugElement[];
// tslint:disable-next-line:prefer-const
let renderer: Renderer2;
beforeEach(() => { beforeEach(() => {
// renderer = new fixture = TestBed.configureTestingModule({
declarations: [MenuSelectionDirective, TestComponent],
}).createComponent(TestComponent);
fixture.detectChanges();
des = fixture.debugElement.queryAll(By.directive(MenuSelectionDirective));
}); });
it('should create an instance', () => { it('should have one element with menu-selection directive', () => {
const directive = new MenuSelectionDirective(elementRef, renderer); expect(des.length).toBe(1);
expect(directive).toBeTruthy();
}); });
}); });

View File

@ -1,16 +1,32 @@
// Core imports
import { ElementRef, Renderer2 } from '@angular/core';
// Application imports // Application imports
import { MenuToggleDirective } from '@app/shared/_directives/menu-toggle.directive'; import { MenuToggleDirective } from '@app/shared/_directives/menu-toggle.directive';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { Component, DebugElement } from '@angular/core';
import { By } from '@angular/platform-browser';
@Component({
template: ` <div appMenuToggle>
<div id="sidebar"></div>
<div id="content"></div>
<div id="sidebarCollapse"></div>
</div>`,
})
class TestComponent {}
describe('MenuToggleDirective', () => { describe('MenuToggleDirective', () => {
// tslint:disable-next-line:prefer-const let fixture: ComponentFixture<TestComponent>;
let elementRef: ElementRef; let des: DebugElement[];
// tslint:disable-next-line:prefer-const
let renderer: Renderer2; beforeEach(() => {
it('should create an instance', () => { fixture = TestBed.configureTestingModule({
const directive = new MenuToggleDirective(elementRef, renderer); declarations: [MenuToggleDirective, TestComponent],
expect(directive).toBeTruthy(); }).createComponent(TestComponent);
fixture.detectChanges();
des = fixture.debugElement.queryAll(By.directive(MenuToggleDirective));
});
it('should have one element with menu-toggle directive', () => {
expect(des.length).toBe(1);
}); });
}); });

View File

@ -1,6 +1,7 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'; import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ErrorDialogComponent } from './error-dialog.component'; import { ErrorDialogComponent } from './error-dialog.component';
import { MAT_DIALOG_DATA, MatDialogModule } from '@angular/material/dialog';
describe('ErrorDialogComponent', () => { describe('ErrorDialogComponent', () => {
let component: ErrorDialogComponent; let component: ErrorDialogComponent;
@ -9,6 +10,8 @@ describe('ErrorDialogComponent', () => {
beforeEach(async () => { beforeEach(async () => {
await TestBed.configureTestingModule({ await TestBed.configureTestingModule({
declarations: [ErrorDialogComponent], declarations: [ErrorDialogComponent],
imports: [MatDialogModule],
providers: [{ provide: MAT_DIALOG_DATA, useValue: {} }],
}).compileComponents(); }).compileComponents();
}); });