Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
Added tests to support optional values on some data that wasn't manda…
Browse files Browse the repository at this point in the history
…tory
  • Loading branch information
minuscorp committed Apr 17, 2018
1 parent 2746a18 commit a818eef
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 34 deletions.
62 changes: 35 additions & 27 deletions web/app/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,43 @@ export enum BuildStatus {
export type FastlaneStatus =
'failure'|'success'|'ci_problem'|'pending'|'missing_fastfile';

export function fastlaneStatusToEnum(status: FastlaneStatus): BuildStatus {
switch (status) {
case 'success':
return BuildStatus.SUCCESS;
case 'failure':
return BuildStatus.FAILED;
case 'pending':
return BuildStatus.PENDING;
case 'missing_fastfile':
return BuildStatus.MISSING_FASTFILE;
case 'ci_problem':
return BuildStatus.INTERNAL_ISSUE;
default:
throw new Error(`Unknown status type ${status}`);
export function fastlaneStatusToEnum(status?: FastlaneStatus): BuildStatus {
if (status) {
switch (status) {
case 'success':
return BuildStatus.SUCCESS;
case 'failure':
return BuildStatus.FAILED;
case 'pending':
return BuildStatus.PENDING;
case 'missing_fastfile':
return BuildStatus.MISSING_FASTFILE;
case 'ci_problem':
return BuildStatus.INTERNAL_ISSUE;
default:
throw new Error(`Unknown status type ${status}`);
}
} else {
return BuildStatus.PENDING;
}
}

export function buildStatusToIcon(status: BuildStatus) {
switch (status) {
case BuildStatus.SUCCESS:
return 'done';
case BuildStatus.PENDING:
return 'pause_circle_filled';
case BuildStatus.FAILED:
case BuildStatus.MISSING_FASTFILE:
return 'error';
case BuildStatus.INTERNAL_ISSUE:
return 'warning';
default:
throw new Error(`Unknown build status ${status}`);
export function buildStatusToIcon(status?: BuildStatus) {
if (status) {
switch (status) {
case BuildStatus.SUCCESS:
return 'done';
case BuildStatus.PENDING:
return 'pause_circle_filled';
case BuildStatus.FAILED:
case BuildStatus.MISSING_FASTFILE:
return 'error';
case BuildStatus.INTERNAL_ISSUE:
return 'warning';
default:
throw new Error(`Unknown build status ${status}`);
}
} else {
return 'pause_circle_filled';
}
}
2 changes: 1 addition & 1 deletion web/app/dashboard/dashboard.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<ng-container matColumnDef="latestBuild">
<mat-header-cell *matHeaderCellDef>Latest Build</mat-header-cell>
<!-- TODO: Pipe this into a relative time pipe -->
<mat-cell *matCellDef="let project">{{project.latestDate | date: 'fullDate'}}</mat-cell>
<mat-cell *matCellDef="let project">{{ (project.latestDate !== null) ? (project.latestDate | date: 'fullDate') : "n/a"}}</mat-cell>
</ng-container>

<!-- TODO: Add Repo Column -->
Expand Down
5 changes: 4 additions & 1 deletion web/app/dashboard/dashboard.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {DataService} from '../services/data.service';

import {DashboardComponent} from './dashboard.component';
import {mockProjectSummaryList} from './test_helpers/mock_project_summary';
import { COMMON_DEPRECATED_I18N_PIPES } from '@angular/common';

describe('DashboardComponent', () => {
let component: DashboardComponent;
Expand Down Expand Up @@ -47,10 +48,12 @@ describe('DashboardComponent', () => {
subject.next(mockProjectSummaryList); // Resolve observable

expect(component.isLoading).toBe(false);
expect(component.projects.length).toBe(3);
expect(component.projects.length).toBe(4);
expect(component.projects[0].id).toBe('1');
expect(component.projects[0].name).toBe('the coolest project');
expect(component.projects[1].latestStatus).toBe(BuildStatus.SUCCESS);
expect(component.projects[2].statusIcon).toBe('error');
expect(component.projects[3].latestDate).toBe(null);
expect(component.projects[3].statusIcon).toBe('pause_circle_filled');
});
});
7 changes: 7 additions & 0 deletions web/app/dashboard/test_helpers/mock_project_summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ export const mockProjectSummaryList: ProjectSummary[] = [
lane: 'ios test',
latest_timestamp: '2018-04-04 16:11:58 -0700'
}),
new ProjectSummary({
id: '4',
name: 'this project needs some work',
latest_status: null,
lane: 'ios test',
latest_timestamp: null
}),
];
8 changes: 4 additions & 4 deletions web/app/models/project_summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ export interface ProjectSummaryResponse {
id: string;
name: string;
lane: string;
latest_status: FastlaneStatus;
latest_timestamp: string;
latest_status?: FastlaneStatus;
latest_timestamp?: string;
}

export class ProjectSummary {
readonly name: string;
readonly id: string;
readonly lane: string;
readonly latestStatus: BuildStatus;
readonly latestDate: Date;
readonly latestDate?: Date;
readonly statusIcon: string;

constructor(projectSummary: ProjectSummaryResponse) {
Expand All @@ -22,6 +22,6 @@ export class ProjectSummary {
this.lane = projectSummary.lane;
this.latestStatus = fastlaneStatusToEnum(projectSummary.latest_status);
this.statusIcon = buildStatusToIcon(this.latestStatus);
this.latestDate = new Date(projectSummary.latest_timestamp);
this.latestDate = projectSummary.latest_timestamp !== null ? new Date(projectSummary.latest_timestamp) : null;
}
}
2 changes: 1 addition & 1 deletion web/app/services/data.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('DataService', () => {
const projectsRequest = mockHttp.expectOne('/data/projects');
projectsRequest.flush(mockProjectListResponse);

expect(projects.length).toBe(3);
expect(projects.length).toBe(4);
expect(projects[0].name).toBe('the coolest project');
expect(projects[0].lane).toBe('ios test');
expect(projects[1].latestStatus).toBe(BuildStatus.SUCCESS);
Expand Down
7 changes: 7 additions & 0 deletions web/app/services/test_helpers/mock_project_response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ export const mockProjectListResponse: ProjectSummaryResponse[] = [
lane: 'ios test',
latest_timestamp: '2018-04-04 16:11:58 -0700'
},
{
id: '4',
name: 'this project needs some work',
latest_status: null,
lane: 'ios test',
latest_timestamp: null
},
];

0 comments on commit a818eef

Please sign in to comment.