Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
…power into dev
  • Loading branch information
TumiPare committed Sep 27, 2023
2 parents 1086985 + 856a044 commit 084d0c2
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/app-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
branches:
- main
- dev
push:
branches:
- dev

jobs:
test:
Expand Down
10 changes: 5 additions & 5 deletions app/WhereIsThePower/src/app/report/report.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h3>Reporting is only available to registered users. </h3>
</ion-icon>
</ion-card-content>
</ion-card>
<ion-text>Substation Blew</ion-text>
<ion-label><h5>Substation Blew</h5></ion-label>
</ion-col>
<ion-col size="6" size-xl="3" class="ion-text-center ion-margin-bottom">
<ion-card (click)="report('CablesStolen')">
Expand All @@ -52,7 +52,7 @@ <h3>Reporting is only available to registered users. </h3>
</ion-icon>
</ion-card-content>
</ion-card>
<ion-text>Cables Stolen</ion-text>
<ion-label>Cables Stolen</ion-label>
</ion-col>
<ion-col size="6" size-xl="3" class="ion-text-center ion-margin-bottom">
<ion-card (click)="report('PowerOutage')">
Expand All @@ -62,7 +62,7 @@ <h3>Reporting is only available to registered users. </h3>
</ion-icon>
</ion-card-content>
</ion-card>
<ion-text>Power Outage</ion-text>
<ion-label>Power Outage</ion-label>
</ion-col>
<ion-col size="6" size-xl="3" offset-xl="1.5" class="ion-text-center ion-margin-bottom">
<ion-card (click)="report('CablesDamaged')">
Expand All @@ -72,7 +72,7 @@ <h3>Reporting is only available to registered users. </h3>
</ion-icon>
</ion-card-content>
</ion-card>
<ion-text>Cables Damaged</ion-text>
<ion-label>Cables Damaged</ion-label>
</ion-col>
<ion-col size="6" size-xl="3" class="ion-text-center ion-margin-bottom">
<ion-card (click)="report('Traffic')">
Expand All @@ -82,7 +82,7 @@ <h3>Reporting is only available to registered users. </h3>
</ion-icon>
</ion-card-content>
</ion-card>
<ion-text>Traffic</ion-text>
<ion-label>Traffic</ion-label>
</ion-col>
</ion-row>
</ion-grid>
Expand Down
100 changes: 100 additions & 0 deletions app/WhereIsThePower/src/app/report/report.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
@@ -1, 99 + 0, 0 @@
// Import necessary modules and dependencies for testing
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { ReportPage } from './report.page';
import { ReportService } from './report.service';
import { AuthService } from '../authentication/auth.service';
import { Router } from '@angular/router';
import { of } from 'rxjs';

// Create mock services
const mockReportService = {
reportIssue: (reportType: string) => {
// Simulate a successful response with a status and a message
return of({ status: 'success', message: ' Report submitted successfully' });
},
};


const mockAuthService = {
isUserLoggedIn: () => Promise.resolve(true), // Change to false for testing non-logged-in state
};

const mockRouter = {
navigate: jasmine.createSpy('navigate'),
};

describe('ReportPage', () => {
let component: ReportPage;
let fixture: ComponentFixture<ReportPage>;
let authService: AuthService;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ReportPage],
providers: [
{ provide: ReportService, useValue: mockReportService },
{ provide: AuthService, useValue: mockAuthService },
{ provide: Router, useValue: mockRouter },
],
}).compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(ReportPage);
component = fixture.componentInstance;
authService = TestBed.inject(AuthService); // Inject AuthService

fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should set "isLoggedIn" to true when the user is logged in', async () => {
await component.ionViewWillEnter();
expect(component.isLoggedIn).toBe(true);
});

it('should navigate to "/tabs/tab-navigate" after reporting an issue', () => {
const reportType = 'SubstationBlew';
component.report(reportType);
expect(mockRouter.navigate).toHaveBeenCalledWith(['/tabs/tab-navigate']);
});

it('should navigate to "/tabs/tab-profile" when "Go to Profile" button is clicked for non-logged-in users', () => {
authService.isUserLoggedIn = () => Promise.resolve(false); // Mock non-logged-in state
fixture.detectChanges();
const navigateSpy = spyOn(component['router'], 'navigate'); // Access private router property
const button = fixture.nativeElement.querySelector('ion-button');
button.click();
fixture.detectChanges();
expect(navigateSpy).toHaveBeenCalledWith(['/tabs/tab-profile']);
});

it('should display the "Reporting is only available to registered users." message for non-logged-in users', () => {
authService.isUserLoggedIn = () => Promise.resolve(false); // Mock non-logged-in state
fixture.detectChanges();
const message = fixture.nativeElement.querySelector('h3');
expect(message.textContent).toContain('Reporting is only available to registered users.');
});

it('should display report options for logged-in users', () => {
authService.isUserLoggedIn = () => Promise.resolve(true); // Mock logged-in state
fixture.detectChanges();
const reportOptions = fixture.nativeElement.querySelectorAll('ion-col');
expect(reportOptions.length).toBeGreaterThan(0);
});

it('should report "SubstationBlew" when the corresponding card is clicked', fakeAsync(() => {
authService.isUserLoggedIn = () => Promise.resolve(true); // Mock logged-in state
fixture.detectChanges();
const reportType = 'SubstationBlew';
const reportSpy = spyOn(mockReportService, 'reportIssue').and.returnValue(of({}));
const card = fixture.nativeElement.querySelector('ion-card');
card.click();
tick();
expect(reportSpy).toHaveBeenCalledWith(reportType);
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class MapModalComponent implements OnInit, AfterViewInit {

const formattedReportType = reportType.replace(/([A-Z])/g, ' $1');

const marker = new mapboxgl.Marker({
const reportMarker = new mapboxgl.Marker({
element: customIcon,
})
.setLngLat([lon, lat])
Expand Down Expand Up @@ -274,9 +274,14 @@ export class MapModalComponent implements OnInit, AfterViewInit {
this.mapSuburbsService.fetchTimeForPolygon(suburbId).subscribe(
(response: any) => {
// Handle the response here


console.log('Time response:', response);
const timesOff = response.result.timesOff; // Assuming "response" holds your API response
console.log("success", response.success);

if(response.success === true)
{
const timesOff = response.result.timesOff; // Assuming "response" holds your API response
if (timesOff && timesOff.length > 0) {
const formattedTimes = timesOff.map((time: any) => {
const start = new Date(time.start * 1000); // Convert seconds to milliseconds
Expand All @@ -289,6 +294,7 @@ export class MapModalComponent implements OnInit, AfterViewInit {
const endMinutes = end.getMinutes().toString().padStart(2, '0');

this.currentSuburbSchedule = `${startHours}:${startMinutes} - ${endHours}:${endMinutes}`;

});

console.log('Formatted Time Ranges:', formattedTimes);
Expand All @@ -313,6 +319,7 @@ export class MapModalComponent implements OnInit, AfterViewInit {
.setLngLat(e.lngLat)
.setHTML(popupContent)
.addTo(this.map);
}
},
(error) => {
// Handle errors here
Expand Down
57 changes: 38 additions & 19 deletions app/WhereIsThePower/src/app/tab-statistics/tab-statistics.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,44 @@ <h3><strong>{{ result.name }}</strong></h3>
</ion-list>
</ion-col>
</ion-row>
<ion-row
*ngIf="isLocationProvided && isAreaFound; else areaNotAvailable"
class="ion-justify-content-center ion-padding-bottom">
<ion-col size="12" class="ion-text-start">
<h2>{{ suburbName }}</h2>
</ion-col>
<ion-col size="10" offset="1" size-md="4" offset-md="0" class="ion-text-center">
<ion-text><h3>Loadshedding for Today</h3></ion-text>
<div class="doughnutChart-container ion-justify-content-center">
<canvas #doughnutChartRef id="doughnutChart"></canvas>
</div>
</ion-col>
<ion-col size="12" size-md="7" offset-md="1" class="ion-text-center ion-padding-vertical ion-justify-content-center ion-padding-vertical">
<ion-text><h3>Loadshedding for this Week</h3></ion-text>
<div class="chart-container">
<canvas #barChart id="barChart"></canvas>
</div>
</ion-col>
</ion-row>
<div *ngIf="isLocationProvided && isAreaFound; else areaNotAvailable">
<ion-row
class="ion-justify-content-center">
<ion-col size="12" class="ion-text-start ion-padding-start">
<h2>{{ suburbName }}</h2>
</ion-col>
</ion-row>
<ion-row>
<ion-col size="12" size-md="4" class="ion-text-center">
<ion-card class="graph ion-padding-bottom ion-padding-start ion-padding-end">
<ion-card-header>
<ion-card-title>
<ion-text><h3>Loadshedding for Today</h3></ion-text>
</ion-card-title>
</ion-card-header>
<ion-card-content>
<div class="doughnutChart-container ion-justify-content-center">
<canvas #doughnutChartRef id="doughnutChart"></canvas>
</div>
</ion-card-content>
</ion-card>
</ion-col>
<ion-col size="12" size-md="8" class="ion-text-center ion-justify-content-center">
<ion-card class="graph">
<ion-card-header>
<ion-card-title>
<ion-text><h3>Loadshedding for this Week</h3></ion-text>
</ion-card-title>
</ion-card-header>
<ion-card-content>
<div class="chart-container">
<canvas #barChart id="barChart"></canvas>
</div>
</ion-card-content>
</ion-card>
</ion-col>
</ion-row>
</div>
<ng-template #areaNotAvailable>
<ion-row>
<ion-col size="8" offset="2" size-md="6" offset-md="3" size-xl="4" offset-xl="4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@
max-height: 300px;
overflow-y: auto; /* Allow scrolling for long lists */
}

.graph{
height: 95%;
}

0 comments on commit 084d0c2

Please sign in to comment.