From 2fc38db6f42d534cfddc6387dfcd3eba0afe3c1e Mon Sep 17 00:00:00 2001 From: Amber-Leigh Lezar Date: Mon, 25 Sep 2023 15:25:36 +0200 Subject: [PATCH 1/6] Update UI --- .../src/app/report/report.page.html | 2 +- .../shared/map-modal/map-modal.component.ts | 11 +++- .../tab-statistics/tab-statistics.page.html | 57 ++++++++++++------- .../tab-statistics/tab-statistics.page.scss | 4 ++ 4 files changed, 52 insertions(+), 22 deletions(-) diff --git a/app/WhereIsThePower/src/app/report/report.page.html b/app/WhereIsThePower/src/app/report/report.page.html index e7fe158e..3f6758cb 100644 --- a/app/WhereIsThePower/src/app/report/report.page.html +++ b/app/WhereIsThePower/src/app/report/report.page.html @@ -42,7 +42,7 @@

Reporting is only available to registered users.

- Substation Blew +
Substation Blew
diff --git a/app/WhereIsThePower/src/app/shared/map-modal/map-modal.component.ts b/app/WhereIsThePower/src/app/shared/map-modal/map-modal.component.ts index ac25d862..568f96e3 100644 --- a/app/WhereIsThePower/src/app/shared/map-modal/map-modal.component.ts +++ b/app/WhereIsThePower/src/app/shared/map-modal/map-modal.component.ts @@ -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]) @@ -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 @@ -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); @@ -313,6 +319,7 @@ export class MapModalComponent implements OnInit, AfterViewInit { .setLngLat(e.lngLat) .setHTML(popupContent) .addTo(this.map); + } }, (error) => { // Handle errors here diff --git a/app/WhereIsThePower/src/app/tab-statistics/tab-statistics.page.html b/app/WhereIsThePower/src/app/tab-statistics/tab-statistics.page.html index 3da360d5..e08e2ff1 100644 --- a/app/WhereIsThePower/src/app/tab-statistics/tab-statistics.page.html +++ b/app/WhereIsThePower/src/app/tab-statistics/tab-statistics.page.html @@ -30,25 +30,44 @@

{{ result.name }}

- - -

{{ suburbName }}

-
- -

Loadshedding for Today

-
- -
-
- -

Loadshedding for this Week

-
- -
-
-
+
+ + +

{{ suburbName }}

+
+
+ + + + + +

Loadshedding for Today

+
+
+ +
+ +
+
+
+
+ + + + +

Loadshedding for this Week

+
+
+ +
+ +
+
+
+
+
+
diff --git a/app/WhereIsThePower/src/app/tab-statistics/tab-statistics.page.scss b/app/WhereIsThePower/src/app/tab-statistics/tab-statistics.page.scss index 150cc913..1cb6222b 100644 --- a/app/WhereIsThePower/src/app/tab-statistics/tab-statistics.page.scss +++ b/app/WhereIsThePower/src/app/tab-statistics/tab-statistics.page.scss @@ -11,3 +11,7 @@ max-height: 300px; overflow-y: auto; /* Allow scrolling for long lists */ } + +.graph{ + height: 95%; +} From 65274ad1bc4725fbab36f0db1dea25b8ae34c63f Mon Sep 17 00:00:00 2001 From: AmberLz Date: Tue, 26 Sep 2023 21:49:18 +0200 Subject: [PATCH 2/6] Update report.page.html Display text as white in dark mode --- app/WhereIsThePower/src/app/report/report.page.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/WhereIsThePower/src/app/report/report.page.html b/app/WhereIsThePower/src/app/report/report.page.html index 3f6758cb..c7d8e12b 100644 --- a/app/WhereIsThePower/src/app/report/report.page.html +++ b/app/WhereIsThePower/src/app/report/report.page.html @@ -42,7 +42,7 @@

Reporting is only available to registered users.

-
Substation Blew
+
Substation Blew
@@ -52,7 +52,7 @@

Reporting is only available to registered users.

- Cables Stolen + Cables Stolen
@@ -62,7 +62,7 @@

Reporting is only available to registered users.

- Power Outage + Power Outage
@@ -72,7 +72,7 @@

Reporting is only available to registered users.

- Cables Damaged + Cables Damaged
@@ -82,7 +82,7 @@

Reporting is only available to registered users.

- Traffic + Traffic
From 11fbe0ea7fbf3b75eeda9341d2f2d93992245a39 Mon Sep 17 00:00:00 2001 From: AmberLz Date: Tue, 26 Sep 2023 22:14:18 +0200 Subject: [PATCH 3/6] Updated DEV --- .github/workflows/app-test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/app-test.yml b/.github/workflows/app-test.yml index cd55bb8e..ac764a59 100644 --- a/.github/workflows/app-test.yml +++ b/.github/workflows/app-test.yml @@ -4,6 +4,9 @@ on: branches: - main - dev + push: + branches: + - dev jobs: test: From 088da380a184d8d32c5064f792a8dc97048f6717 Mon Sep 17 00:00:00 2001 From: AmberLz Date: Wed, 27 Sep 2023 08:58:36 +0200 Subject: [PATCH 4/6] Create report.spec.ts --- .../src/app/report/report.spec.ts | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 app/WhereIsThePower/src/app/report/report.spec.ts diff --git a/app/WhereIsThePower/src/app/report/report.spec.ts b/app/WhereIsThePower/src/app/report/report.spec.ts new file mode 100644 index 00000000..199403f0 --- /dev/null +++ b/app/WhereIsThePower/src/app/report/report.spec.ts @@ -0,0 +1,99 @@ +// 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: reportType, ' 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; + 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); + })); +}); From 1316b7f938ed30b1e546e5584ca3443f5e27d352 Mon Sep 17 00:00:00 2001 From: AmberLz Date: Wed, 27 Sep 2023 09:01:49 +0200 Subject: [PATCH 5/6] Delete report.spec.ts --- .../src/app/report/report.spec.ts | 99 ------------------- 1 file changed, 99 deletions(-) delete mode 100644 app/WhereIsThePower/src/app/report/report.spec.ts diff --git a/app/WhereIsThePower/src/app/report/report.spec.ts b/app/WhereIsThePower/src/app/report/report.spec.ts deleted file mode 100644 index 199403f0..00000000 --- a/app/WhereIsThePower/src/app/report/report.spec.ts +++ /dev/null @@ -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: reportType, ' 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; - 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); - })); -}); From 856a0444f4bdc9cb59b8ef3223025429437b93b7 Mon Sep 17 00:00:00 2001 From: AmberLz Date: Wed, 27 Sep 2023 09:02:46 +0200 Subject: [PATCH 6/6] Update report.spec.ts --- .../src/app/report/report.spec.ts | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 app/WhereIsThePower/src/app/report/report.spec.ts diff --git a/app/WhereIsThePower/src/app/report/report.spec.ts b/app/WhereIsThePower/src/app/report/report.spec.ts new file mode 100644 index 00000000..b169b38a --- /dev/null +++ b/app/WhereIsThePower/src/app/report/report.spec.ts @@ -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; + 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); + })); +});