This repository has been archived by the owner on Dec 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
335 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
app/WhereIsThePower/src/app/authentication/auth.guard.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { AuthGuard } from './auth.guard'; | ||
|
||
describe('AuthGuard', () => { | ||
let guard: AuthGuard; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
guard = TestBed.inject(AuthGuard); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(guard).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { TestBed, inject, async } from '@angular/core/testing'; | ||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; | ||
import { AuthService } from './auth.service'; | ||
import { RegisterUser } from '../shared/models/register-user'; | ||
import { User } from '../shared/models/user'; | ||
|
||
describe('AuthService', () => { | ||
let authService: AuthService; | ||
let httpMock: HttpTestingController; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [HttpClientTestingModule], | ||
providers: [AuthService], | ||
}); | ||
|
||
authService = TestBed.inject(AuthService); | ||
httpMock = TestBed.inject(HttpTestingController); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(authService).toBeTruthy(); | ||
}); | ||
|
||
it('should sign up a user', () => { | ||
const registerUser: RegisterUser = { | ||
firstName: 'andy', | ||
lastName: 'vis', | ||
email: '[email protected]', | ||
password: 'Helloworld123', | ||
}; | ||
|
||
authService.signupUser(registerUser).subscribe((response) => { | ||
}); | ||
|
||
const req = httpMock.expectOne(`${authService.apiUrl}user`); | ||
expect(req.request.method).toBe('POST'); | ||
req.flush({ }); | ||
}); | ||
|
||
it('should log in a user', () => { | ||
const user: User = { | ||
authType: '', | ||
email: '', | ||
password: '', | ||
firstName: '', | ||
lastName: '' | ||
}; | ||
|
||
authService.loginUser(user).subscribe((response) => { | ||
}); | ||
|
||
const req = httpMock.expectOne(`${authService.apiUrl}auth`); | ||
expect(req.request.method).toBe('POST'); | ||
req.flush({ token: 'sample_token' }); | ||
}); | ||
|
||
it('should save user data', async(() => { | ||
authService.saveUserData('Token', 'sample_token').then(() => { | ||
}); | ||
})); | ||
|
||
it('should sign out a user', async(() => { | ||
authService.signOutUser(); | ||
})); | ||
|
||
it('should get user data', async(() => { | ||
authService.getUserData().then((userData) => { | ||
}); | ||
})); | ||
|
||
it('should check if a user is logged in', async(() => { | ||
authService.isUserLoggedIn().then((loggedIn) => { | ||
}); | ||
})); | ||
|
||
it('should get authentication headers', () => { | ||
const headers = authService.getAuthHeaders(); | ||
}); | ||
|
||
afterEach(() => { | ||
httpMock.verify(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// @ts-nocheck | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { Pipe, PipeTransform, Injectable, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA, Directive, Input, Output } from '@angular/core'; | ||
import { isPlatformBrowser } from '@angular/common'; | ||
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; | ||
import { By } from '@angular/platform-browser'; | ||
import { Observable, of as observableOf, throwError } from 'rxjs'; | ||
|
||
import { Component } from '@angular/core'; | ||
import { ReportPage } from './report.page'; | ||
import { ReportService } from './report.service'; | ||
import { Router } from '@angular/router'; | ||
import { AuthService } from '../authentication/auth.service'; | ||
|
||
@Injectable() | ||
class MockReportService {} | ||
|
||
@Injectable() | ||
class MockRouter { | ||
navigate() {}; | ||
} | ||
|
||
@Injectable() | ||
class MockAuthService {} | ||
|
||
@Directive({ selector: '[myCustom]' }) | ||
class MyCustomDirective { | ||
@Input() myCustom; | ||
} | ||
|
||
@Pipe({name: 'translate'}) | ||
class TranslatePipe implements PipeTransform { | ||
transform(value) { return value; } | ||
} | ||
|
||
@Pipe({name: 'phoneNumber'}) | ||
class PhoneNumberPipe implements PipeTransform { | ||
transform(value) { return value; } | ||
} | ||
|
||
@Pipe({name: 'safeHtml'}) | ||
class SafeHtmlPipe implements PipeTransform { | ||
transform(value) { return value; } | ||
} | ||
|
||
describe('ReportPage', () => { | ||
let fixture; | ||
let component; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ FormsModule, ReactiveFormsModule ], | ||
declarations: [ | ||
ReportPage, | ||
TranslatePipe, PhoneNumberPipe, SafeHtmlPipe, | ||
MyCustomDirective | ||
], | ||
schemas: [ CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA ], | ||
providers: [ | ||
{ provide: ReportService, useClass: MockReportService }, | ||
{ provide: Router, useClass: MockRouter }, | ||
{ provide: AuthService, useClass: MockAuthService } | ||
] | ||
}).overrideComponent(ReportPage, { | ||
|
||
}).compileComponents(); | ||
fixture = TestBed.createComponent(ReportPage); | ||
component = fixture.debugElement.componentInstance; | ||
}); | ||
|
||
afterEach(() => { | ||
component.ngOnDestroy = function() {}; | ||
fixture.destroy(); | ||
}); | ||
|
||
it('should run #constructor()', async () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should run #ngOnInit()', async () => { | ||
|
||
component.ngOnInit(); | ||
|
||
}); | ||
|
||
xit('should run #ionViewWillEnter()', async () => { | ||
component.authService = component.authService || {}; | ||
spyOn(component.authService, 'isUserLoggedIn'); | ||
await component.ionViewWillEnter(); | ||
// expect(component.authService.isUserLoggedIn).toHaveBeenCalled(); | ||
}); | ||
|
||
xit('should run #report()', async () => { | ||
component.reportService = component.reportService || {}; | ||
spyOn(component.reportService, 'reportIssue').and.returnValue(observableOf({})); | ||
component.router = component.router || {}; | ||
spyOn(component.router, 'navigate'); | ||
component.report({}); | ||
// expect(component.reportService.reportIssue).toHaveBeenCalled(); | ||
// expect(component.router.navigate).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should run #ngOnDestroy()', async () => { | ||
component.createReportSubscription = component.createReportSubscription || {}; | ||
spyOn(component.createReportSubscription, 'unsubscribe'); | ||
component.ngOnDestroy(); | ||
// expect(component.createReportSubscription.unsubscribe).toHaveBeenCalled(); | ||
}); | ||
|
||
}); |
125 changes: 125 additions & 0 deletions
125
app/WhereIsThePower/src/app/tab-profile/tab-profile.page.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// @ts-nocheck | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { Pipe, PipeTransform, Injectable, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA, Directive, Input, Output } from '@angular/core'; | ||
import { isPlatformBrowser } from '@angular/common'; | ||
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; | ||
import { By } from '@angular/platform-browser'; | ||
import { Observable, of as observableOf, throwError } from 'rxjs'; | ||
|
||
import { Component } from '@angular/core'; | ||
import { TabProfilePage } from './tab-profile.page'; | ||
import { AuthService } from '../authentication/auth.service'; | ||
import { ModalController } from '@ionic/angular'; | ||
|
||
@Injectable() | ||
class MockAuthService {} | ||
|
||
@Directive({ selector: '[myCustom]' }) | ||
class MyCustomDirective { | ||
@Input() myCustom; | ||
} | ||
|
||
@Pipe({name: 'translate'}) | ||
class TranslatePipe implements PipeTransform { | ||
transform(value) { return value; } | ||
} | ||
|
||
@Pipe({name: 'phoneNumber'}) | ||
class PhoneNumberPipe implements PipeTransform { | ||
transform(value) { return value; } | ||
} | ||
|
||
@Pipe({name: 'safeHtml'}) | ||
class SafeHtmlPipe implements PipeTransform { | ||
transform(value) { return value; } | ||
} | ||
|
||
describe('TabProfilePage', () => { | ||
let fixture; | ||
let component; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ FormsModule, ReactiveFormsModule ], | ||
declarations: [ | ||
TabProfilePage, | ||
TranslatePipe, PhoneNumberPipe, SafeHtmlPipe, | ||
MyCustomDirective | ||
], | ||
schemas: [ CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA ], | ||
providers: [ | ||
{ provide: AuthService, useClass: MockAuthService }, | ||
ModalController | ||
] | ||
}).overrideComponent(TabProfilePage, { | ||
|
||
}).compileComponents(); | ||
fixture = TestBed.createComponent(TabProfilePage); | ||
component = fixture.debugElement.componentInstance; | ||
}); | ||
|
||
afterEach(() => { | ||
component.ngOnDestroy = function() {}; | ||
fixture.destroy(); | ||
}); | ||
|
||
xit('should run #constructor()', async () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
xit('should run #ngOnInit()', async () => { | ||
component.authService = component.authService || {}; | ||
component.authService.user = observableOf({ | ||
firstName: { | ||
charAt: function() {} | ||
} | ||
}); | ||
component.authService.isLoggedin = 'isLoggedin'; | ||
spyOn(component, 'getInitialDataURL'); | ||
component.ngOnInit(); | ||
// expect(component.getInitialDataURL).toHaveBeenCalled(); | ||
}); | ||
|
||
xit('should run #showSignupComponent()', async () => { | ||
component.modalController = component.modalController || {}; | ||
spyOn(component.modalController, 'create'); | ||
await component.showSignupComponent(); | ||
// expect(component.modalController.create).toHaveBeenCalled(); | ||
}); | ||
|
||
xit('should run #showLoginComponent()', async () => { | ||
component.modalController = component.modalController || {}; | ||
spyOn(component.modalController, 'create'); | ||
await component.showLoginComponent(); | ||
// expect(component.modalController.create).toHaveBeenCalled(); | ||
}); | ||
|
||
xit('should run #logout()', async () => { | ||
component.authService = component.authService || {}; | ||
spyOn(component.authService, 'signOutUser'); | ||
spyOn(component, 'toggleTheme'); | ||
await component.logout(); | ||
// expect(component.authService.signOutUser).toHaveBeenCalled(); | ||
// expect(component.toggleTheme).toHaveBeenCalled(); | ||
}); | ||
|
||
xit('should run #ngOnDestroy()', async () => { | ||
component.userSubscription = component.userSubscription || {}; | ||
spyOn(component.userSubscription, 'unsubscribe'); | ||
component.ngOnDestroy(); | ||
// expect(component.userSubscription.unsubscribe).toHaveBeenCalled(); | ||
}); | ||
|
||
xit('should run #getInitialDataURL()', async () => { | ||
|
||
component.getInitialDataURL({}); | ||
|
||
}); | ||
|
||
xit('should run #toggleTheme()', async () => { | ||
|
||
component.toggleTheme({}); | ||
|
||
}); | ||
|
||
}); |