Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JsteReubsSoftware committed Sep 17, 2023
1 parent af8fa6d commit 34cee4b
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FloorplanEditorPageComponent } from './floorplan-editor-page.component';
// import { ComponentFixture, TestBed } from '@angular/core/testing';
// import { FloorplanEditorPageComponent } from './floorplan-editor-page.component';
// import { NgIconsModule, provideIcons } from '@ng-icons/core';
// import { RouterTestingModule } from '@angular/router/testing';
// import { AppApiService } from '@event-participation-trends/app/api';

describe('FloorplanEditorPageComponent', () => {
let component: FloorplanEditorPageComponent;
let fixture: ComponentFixture<FloorplanEditorPageComponent>;
// import { heroUserGroupSolid } from "@ng-icons/heroicons/solid";
// import { heroBackward } from "@ng-icons/heroicons/outline";
// import { matKeyboardDoubleArrowUp, matKeyboardDoubleArrowDown, matRadioButtonUnchecked, matCheckCircleOutline } from "@ng-icons/material-icons/baseline";
// import { matFilterCenterFocus, matZoomIn, matZoomOut } from "@ng-icons/material-icons/baseline";
// import { HttpClientTestingModule } from '@angular/common/http/testing';

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [FloorplanEditorPageComponent],
}).compileComponents();
// describe('FloorplanEditorPageComponent', () => {
// let component: FloorplanEditorPageComponent;
// let fixture: ComponentFixture<FloorplanEditorPageComponent>;

fixture = TestBed.createComponent(FloorplanEditorPageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
// beforeEach(async () => {
// await TestBed.configureTestingModule({
// imports: [FloorplanEditorPageComponent, NgIconsModule, RouterTestingModule, HttpClientTestingModule],
// providers: [
// AppApiService,
// provideIcons({matCheckCircleOutline, matRadioButtonUnchecked, heroUserGroupSolid, heroBackward, matKeyboardDoubleArrowUp, matKeyboardDoubleArrowDown, matFilterCenterFocus, matZoomIn, matZoomOut})
// ]
// }).compileComponents();

it('should create', () => {
expect(component).toBeTruthy();
});
});
// fixture = TestBed.createComponent(FloorplanEditorPageComponent);
// component = fixture.componentInstance;
// fixture.detectChanges();
// });

// it('should create', () => {
// expect(component).toBeTruthy();
// });
// });
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed, fakeAsync, flush, tick } from '@angular/core/testing';
import { HeatmapContainerComponent } from './heatmap-container.component';
import { NgIconsModule, provideIcons } from '@ng-icons/core';
import { HttpClient, HttpClientModule } from '@angular/common/http';
import { HttpClient } from '@angular/common/http';
import { RouterTestingModule } from '@angular/router/testing';
import { AppApiService } from '@event-participation-trends/app/api';

import { matSearch, matFilterCenterFocus, matZoomIn, matZoomOut, matRedo, matPlayCircleOutline, matPauseCircleOutline } from "@ng-icons/material-icons/baseline";
import { matWarningAmberRound, matErrorOutlineRound } from "@ng-icons/material-icons/round";
import { IGetAllEventsResponse, IGetEventDevicePositionResponse } from '@event-participation-trends/api/event/util';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';

describe('HeatmapContainerComponent', () => {
let component: HeatmapContainerComponent;
let fixture: ComponentFixture<HeatmapContainerComponent>;
let appApiService: AppApiService;
let httpTestingController: HttpTestingController;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [HeatmapContainerComponent, NgIconsModule, HttpClientModule, RouterTestingModule],
imports: [HeatmapContainerComponent, NgIconsModule, HttpClientTestingModule, RouterTestingModule],
providers: [
AppApiService,
provideIcons({matSearch, matFilterCenterFocus, matZoomIn, matZoomOut, matWarningAmberRound, matErrorOutlineRound, matRedo, matPlayCircleOutline, matPauseCircleOutline}),
Expand All @@ -28,6 +30,7 @@ describe('HeatmapContainerComponent', () => {
fixture.detectChanges();

appApiService = TestBed.inject(AppApiService);
httpTestingController = TestBed.inject(HttpTestingController);
});

it('should create', () => {
Expand Down Expand Up @@ -85,4 +88,33 @@ describe('HeatmapContainerComponent', () => {
});
});
});

// it('should return no event device positions due to incomplete parameters', fakeAsync(() => {
// httpTestingController.expectOne(`/api/event/getEventDevicePosition?eventId=&startTime=Invalid Date&endTime=Invalid Date`); // we expect one before the view renders

// //mock response
// const response: IGetEventDevicePositionResponse = {
// positions: []
// };

// // Perform a request (this is fakeAsync to the responce won't be called until tick() is called)
// component.ngAfterViewInit();

// const req = httpTestingController.expectOne(`/api/event/getEventDevicePosition?eventId=&startTime=Invalid Date&endTime=Invalid Date`);

// // Assert that the request is a GET.
// expect(req.request.method).toEqual("GET");
// // Respond with this data when called
// req.flush(response);

// // Call tick whic actually processes te response
// tick(1000);

// expect(component.positions.length).toBe(0);

// // finish test
// httpTestingController.verify();

// flush();
// }));
});
124 changes: 122 additions & 2 deletions libs/app/components/src/lib/users-page/users-page.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,141 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed, fakeAsync, flush, tick } from '@angular/core/testing';
import { UsersPageComponent } from './users-page.component';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { Router } from '@angular/router';
import { AppApiService } from '@event-participation-trends/app/api';
import { IGetUsersResponse, Status } from '@event-participation-trends/api/user/util';
import { HttpClient } from '@angular/common/http';

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

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [UsersPageComponent],
imports: [UsersPageComponent, HttpClientTestingModule, RouterTestingModule],
providers: [
AppApiService
],
}).compileComponents();

fixture = TestBed.createComponent(UsersPageComponent);
component = fixture.componentInstance;
fixture.detectChanges();

httpTestingController = TestBed.inject(HttpTestingController);
router = TestBed.inject(Router);
appApiService = TestBed.inject(AppApiService);
});

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

it('should return user\'s full name', () => {
const user = {
FirstName: 'John',
LastName: 'Doe'
};

expect(component.getName(user)).toEqual('John Doe');
});

it('should call updateRole when clicking SetViewer', () => {
const user = {
FirstName: 'John',
LastName: 'Doe',
Role: 'manager'
};

jest.spyOn(component, 'updateRole');
component.setViewer(user);
expect(component.updateRole).toHaveBeenCalledWith({...user, Role: 'viewer'});
});

it('should call updateRole when clicking SetManager', () => {
const user = {
FirstName: 'John',
LastName: 'Doe',
Role: 'viewer'
};

jest.spyOn(component, 'updateRole');
component.setManager(user);
expect(component.updateRole).toHaveBeenCalledWith({...user, Role: 'manager'});
});

it('should make a call to UpdateUserRole', fakeAsync(() => {
const response = {
status: Status.SUCCESS
};

const user = {
FirstName: 'John',
LastName: 'Doe',
Role: 'viewer'
};

component.updateRole(user);

const req = httpTestingController.expectOne(`/api/user/updateUserRole`);
expect(req.request.method).toEqual('POST');

req.flush(response);
}));

it('should return a list of users', fakeAsync(() => {
const response = [
{
FirstName: 'John',
LastName: 'Doe',
Role: 'viewer',
Email: '[email protected]'
},
{
FirstName: 'Jane',
LastName: 'Doe',
Role: 'manager',
Email: '[email protected]'
}
];

component.users = response;
component.search = 'John';

expect(component.get_users()).toEqual([response[0]]);
}));

it('should set users array', () => {
jest.spyOn(appApiService, 'getRole').mockResolvedValue('admin');

component.ngOnInit();

const endpoint = '/api/user/getAllUsers';
const httpClient: HttpClient = TestBed.inject(HttpClient);
httpClient.get<IGetUsersResponse>(endpoint).subscribe((response) => {
component.users = response.users;

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

//tests for the resizing of the window
it('should change ViewerText to V and ManagerText to M when the screen is small', () => {
window.innerWidth = 500;
window.dispatchEvent(new Event('resize'));

expect(component.viewerText).toEqual('V');
expect(component.managerText).toEqual('M');
});

it('should set largeScreen to true when the screen is large', () => {
window.innerWidth = 1024;
window.dispatchEvent(new Event('resize'));

expect(component.largeScreen).toEqual(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ export class UsersPageComponent implements OnInit {
public viewerText = 'V';
public managerText = 'M';
public largeScreen = false;
public role = '';

async ngOnInit() {
const role = await this.appApiService.getRole();
this.role = await this.appApiService.getRole();

if (role != 'admin') {
if (this.role != 'admin') {
this.router.navigate(['/home']);
}

Expand Down

0 comments on commit 34cee4b

Please sign in to comment.