Skip to content

Commit

Permalink
Added more integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JsteReubsSoftware committed Sep 19, 2023
1 parent 23d48b1 commit 7f83131
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { DashboardPageComponent } from './dashboard-page.component';
import { NgIconsModule, provideIcons } from '@ng-icons/core';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { Router } from '@angular/router';

import { matKeyboardDoubleArrowUp, matKeyboardDoubleArrowDown } from "@ng-icons/material-icons/baseline";
import { matFilterCenterFocus, matZoomIn, matZoomOut } from "@ng-icons/material-icons/baseline";
import { heroUserGroupSolid } from "@ng-icons/heroicons/solid";
import { heroBackward } from "@ng-icons/heroicons/outline";
import { IGetEventFloorlayoutResponse, IGetFloorplanBoundariesResponse, IImage } from '@event-participation-trends/api/event/util';
import { HttpClient } from '@angular/common/http';
import { AppApiService } from '@event-participation-trends/app/api';

describe('DashboardPageComponent', () => {
let component: DashboardPageComponent;
let fixture: ComponentFixture<DashboardPageComponent>;
let router: Router;
let httpClient: HttpClient;
let httpTestingController: HttpTestingController;
let appApiService: AppApiService;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [DashboardPageComponent, NgIconsModule, HttpClientTestingModule, RouterTestingModule],
providers: [
AppApiService,
provideIcons({heroUserGroupSolid, heroBackward, matKeyboardDoubleArrowUp, matKeyboardDoubleArrowDown, matFilterCenterFocus, matZoomIn, matZoomOut})
],
}).compileComponents();
Expand All @@ -28,6 +35,8 @@ describe('DashboardPageComponent', () => {
fixture.detectChanges();

router = TestBed.inject(Router);
httpClient = TestBed.inject(HttpClient);
appApiService = TestBed.inject(AppApiService);
});

it('should create', () => {
Expand All @@ -46,4 +55,86 @@ describe('DashboardPageComponent', () => {
component.ngOnInit();
expect(router.navigate).toHaveBeenCalledWith(['/home']);
});

it('should get event floorplan boundaries', () => {
httpTestingController = TestBed.inject(HttpTestingController);
httpTestingController.expectOne(`/api/user/getRole`);
// mock response
const response: IGetFloorplanBoundariesResponse = {
boundaries: {
top: 0,
bottom: 0,
left: 0,
right: 0
}
};
component.id = '1';

httpClient.get<IGetFloorplanBoundariesResponse>(`/api/event/getFloorplanBoundaries?eventId=${component.id}`).subscribe(res => {
component.floorlayoutBounds = res.boundaries;

expect(component.floorlayoutBounds).toEqual(response.boundaries);
});

const req = httpTestingController.expectOne(`/api/event/getFloorplanBoundaries?eventId=${component.id}`);
expect(req.request.method).toEqual('GET');

req.flush(response);

httpTestingController.verify();
});

it('should get floorlayout images', () => {
httpTestingController = TestBed.inject(HttpTestingController);
httpTestingController.expectOne(`/api/user/getRole`);
// mock response
const response: IImage[] =[
{
eventId: undefined,
imageBase64: 'image1',
imageObj: undefined,
imageScale: 1,
imageType: 'image/png',
}
];

component.id = '1';

httpClient.get<IImage[]>(`/api/event/getFloorlayoutImages?eventId=${component.id}`).subscribe(res => {
component.floorlayoutImages = res;

expect(component.floorlayoutImages).toEqual(response);
});

const req = httpTestingController.expectOne(`/api/event/getFloorlayoutImages?eventId=${component.id}`);
expect(req.request.method).toEqual('GET');

req.flush(response);

httpTestingController.verify();
});

it('should get event floorlayout', () => {
httpTestingController = TestBed.inject(HttpTestingController);
httpTestingController.expectOne(`/api/user/getRole`);
// mock response
const response: IGetEventFloorlayoutResponse = {
floorlayout: ''
};

component.id = '1';

httpClient.get<IGetEventFloorlayoutResponse>(`/api/event/getFloorlayout?eventId=${component.id}`).subscribe(res => {
component.floorlayoutSnapshot = res.floorlayout!;

expect(component.floorlayoutSnapshot).toEqual(response);
});

const req = httpTestingController.expectOne(`/api/event/getFloorlayout?eventId=${component.id}`);
expect(req.request.method).toEqual('GET');

req.flush(response);

httpTestingController.verify();
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommonModule } from "@angular/common";
import { NgIconsModule, provideIcons } from "@ng-icons/core";
import { Component, OnInit, ViewChild, ElementRef, HostListener, AfterViewInit } from '@angular/core';
import { Component, OnInit, ViewChild, ElementRef, HostListener, AfterViewInit, NgZone } from '@angular/core';
import * as L from 'leaflet';
import 'leaflet.heat';
import Chart, { ChartConfiguration } from 'chart.js/auto';
Expand Down Expand Up @@ -152,7 +152,7 @@ export class DashboardPageComponent implements OnInit, AfterViewInit {
detectionRadius = 2;
// ====================================

constructor(private appApiService: AppApiService, private router : Router, private route: ActivatedRoute) {}
constructor(private appApiService: AppApiService, private router : Router, private route: ActivatedRoute, private ngZone: NgZone) {}

public id = '';
public event : any | null = null;
Expand All @@ -164,11 +164,11 @@ export class DashboardPageComponent implements OnInit, AfterViewInit {
this.id = this.route.parent?.snapshot.paramMap.get('id') || '';

if (!this.id) {
this.router.navigate(['/home']);
this.ngZone.run(() => { this.router.navigate(['/home']); });
}

if (!(await this.hasAccess())) {
this.router.navigate(['/home']);
this.ngZone.run(() => { this.router.navigate(['/home']); });
}

this.timeOffset = (new Date()).getTimezoneOffset() * 60 * 1000;
Expand Down

0 comments on commit 7f83131

Please sign in to comment.