Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Spratt committed Mar 16, 2022
1 parent 58ed4fc commit 33f2aa6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 6 deletions.
4 changes: 3 additions & 1 deletion udmd/web/src/app/device/device.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
</mat-card>

<nav mat-tab-nav-bar [tabPanel]="tabPanel">
<a mat-tab-link routerLink="points" routerLinkActive #rla="routerLinkActive" [active]="rla.isActive">Points</a>
<a mat-tab-link routerLink="points" routerLinkActive="active" #rla="routerLinkActive" [active]="rla.isActive"
>Points</a
>
</nav>
<mat-tab-nav-panel #tabPanel>
<div class="container">
Expand Down
2 changes: 1 addition & 1 deletion udmd/web/src/app/points/points.component.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p>points works!</p>
<p>{{ points }}</p>
47 changes: 47 additions & 0 deletions udmd/web/src/app/points/points.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,55 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ActivatedRoute } from '@angular/router';
import { ApolloQueryResult } from '@apollo/client/core';
import { of } from 'rxjs';
import { Point, PointsQueryResponse } from './points';
import { PointsComponent } from './points.component';
import { PointsModule } from './points.module';
import { PointsService } from './points.service';

describe('PointsComponent', () => {
let component: PointsComponent;
let fixture: ComponentFixture<PointsComponent>;
let mockPointsService: jasmine.SpyObj<PointsService>;
let points: Point[] = [
{
id: 'point-id-123',
},
];

beforeEach(async () => {
mockPointsService = jasmine.createSpyObj(PointsService, ['getPoints']);
mockPointsService.getPoints.and.returnValue(
of(<ApolloQueryResult<PointsQueryResponse>>{
data: {
device: {
id: 'device-id-123',
points,
},
},
loading: false,
})
);

await TestBed.configureTestingModule({
imports: [PointsModule],
providers: [
{ provide: PointsService, useValue: mockPointsService },
{
provide: ActivatedRoute,
useValue: {
parent: {
snapshot: {
parent: {
params: {
id: 'device-id-123',
},
},
},
},
},
},
],
}).compileComponents();
});

Expand All @@ -21,4 +62,10 @@ describe('PointsComponent', () => {
it('should create', () => {
expect(component).toBeTruthy();
});

it('should store the points in memory', () => {
expect(mockPointsService.getPoints).toHaveBeenCalledWith('device-id-123');
expect(component.points).toEqual(points);
expect(component.loading).toBeFalse();
});
});
8 changes: 4 additions & 4 deletions udmd/web/src/app/points/points.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { ApolloTestingController, ApolloTestingModule } from 'apollo-angular/tes
import { GraphQLModule } from '../graphql/graphql.module';
import { GET_POINTS } from './points.gql';
import { PointsQueryResponse } from './points';
import { DeviceService } from './points.service';
import { PointsService } from './points.service';

describe('DeviceService', () => {
let service: DeviceService;
describe('PointsService', () => {
let service: PointsService;
let controller: ApolloTestingController;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [ApolloTestingModule, GraphQLModule],
});
service = TestBed.inject(DeviceService);
service = TestBed.inject(PointsService);
controller = TestBed.inject(ApolloTestingController);
});

Expand Down

0 comments on commit 33f2aa6

Please sign in to comment.