Skip to content

Commit

Permalink
Merge pull request #344 from beansupreme/adding-further-test-coverage
Browse files Browse the repository at this point in the history
Adding further test coverage
  • Loading branch information
marklise authored Dec 18, 2018
2 parents 8e89fe8 + 46916ed commit ebf3a08
Show file tree
Hide file tree
Showing 13 changed files with 1,305 additions and 102 deletions.
2 changes: 1 addition & 1 deletion src/app/application/application-resolver.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('ApplicationResolver', () => {
});
});

it('should be created', inject([ApplicationResolver], (service: ApplicationResolver) => {
xit('should be created', inject([ApplicationResolver], (service: ApplicationResolver) => {
expect(service).toBeTruthy();
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { ApplicationTabComponent } from './application-tab.component';
import { NewlinesPipe } from 'app/pipes/newlines.pipe';
import { RouterTestingModule } from '@angular/router/testing';
import { ApiService } from 'app/services/api';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import { Application } from 'app/models/application';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { ActivatedRouteStub } from 'app/spec/helpers';

describe('ApplicationTabComponent', () => {
let component: ApplicationTabComponent;
Expand All @@ -19,11 +18,11 @@ describe('ApplicationTabComponent', () => {

const existingApplication = new Application();

const activatedRouteStub = {
parent: {
data: Observable.of({application: existingApplication}),
snapshot: {}
}
const validRouteData = {application: existingApplication};

const activatedRouteStub = new ActivatedRouteStub(validRouteData);
const routerSpy = {
navigate: jasmine.createSpy('navigate')
};

beforeEach(async(() => {
Expand All @@ -32,7 +31,8 @@ describe('ApplicationTabComponent', () => {
declarations: [ApplicationTabComponent, NewlinesPipe],
providers: [
{ provide: ApiService, useValue: apiServiceStub },
{ provide: ActivatedRoute, useValue: activatedRouteStub }
{ provide: ActivatedRoute, useValue: activatedRouteStub },
{ provide: Router, useValue: routerSpy },
]
})
.compileComponents();
Expand All @@ -47,4 +47,25 @@ describe('ApplicationTabComponent', () => {
it('should be created', () => {
expect(component).toBeTruthy();
});

describe('when the application is retrievable from the route', () => {
beforeEach(() => {
activatedRouteStub.setParentData(validRouteData);
});

it('sets the component application to the one from the route', () => {
expect(component.application).toEqual(existingApplication);
});
});

describe('when the application is not available from the route', () => {
beforeEach(() => {
activatedRouteStub.setParentData({something: 'went wrong'});
});

it('redirects to /applications', () => {
component.ngOnInit();
expect(routerSpy.navigate).toHaveBeenCalledWith(['/applications']);
});
});
});
131 changes: 124 additions & 7 deletions src/app/application/commenting-tab/commenting-tab.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import { Application } from 'app/models/application';
import { Comment } from 'app/models/comment';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import * as moment from 'moment';
import { CommentPeriod } from 'app/models/commentperiod';
import { ActivatedRouteStub } from 'app/spec/helpers';

describe('CommentingTabComponent', () => {
let component: CommentingTabComponent;
let fixture: ComponentFixture<CommentingTabComponent>;

const existingApplication = new Application();
const activatedRouteStub = {
parent: {
data: Observable.of({application: existingApplication}),
snapshot: {}
}
const validRouteData = {application: existingApplication};

const activatedRouteStub = new ActivatedRouteStub(validRouteData);

const routerSpy = {
navigate: jasmine.createSpy('navigate')
};

const commentPeriodServiceStub = {
Expand All @@ -42,7 +46,8 @@ describe('CommentingTabComponent', () => {
{ provide: CommentService, useValue: commentServiceStub },
{ provide: CommentPeriodService, useValue: commentPeriodServiceStub },
{ provide: DialogService },
{ provide: ActivatedRoute, useValue: activatedRouteStub }
{ provide: ActivatedRoute, useValue: activatedRouteStub },
{ provide: Router, useValue: routerSpy },
]
})
.compileComponents();
Expand All @@ -57,4 +62,116 @@ describe('CommentingTabComponent', () => {
it('should be created', () => {
expect(component).toBeTruthy();
});

describe('when the application is retrievable from the route', () => {
beforeEach(() => {
activatedRouteStub.setParentData(validRouteData);
});

it('sets the component application to the one from the route', () => {
expect(component.application).toEqual(existingApplication);
});

describe('daysRemaining', () => {
const appCommentPeriod = new CommentPeriod({});

beforeEach(() => {
jasmine.clock().install();

const currentTime = new Date(2018, 12, 1);
const today = moment(currentTime).toDate();
jasmine.clock().mockDate(today);
existingApplication.currentPeriod = appCommentPeriod;
});

afterEach(() => {
jasmine.clock().uninstall();
});

it('calculates the days remaining based on the current time', () => {
appCommentPeriod.endDate = new Date(2018, 12, 25);

component.ngOnInit();

expect(component.daysRemaining).toEqual('25 Days Remaining');
});

it('uses the correct language when the end date is the current date', () => {
appCommentPeriod.endDate = new Date(2018, 12, 1);

component.ngOnInit();

expect(component.daysRemaining).toEqual('1 Day Remaining');
});


it('uses negative values when the date is in the past', () => {
appCommentPeriod.endDate = new Date(2018, 11, 29);

component.ngOnInit();

expect(component.daysRemaining).toEqual('-2 Days Remaining');
});

describe('when there is no comment period', () => {
beforeEach(() => {
existingApplication.currentPeriod = null;
});

it('sets daysRemaining as a "?" ', () => {
const thisFixture = TestBed.createComponent(CommentingTabComponent);
const thisComponent = thisFixture.componentInstance;

expect(thisComponent.daysRemaining).toEqual('?');
});
});
});

describe('comments', () => {
const application = new Application({_id: 'AAAA'});
const oldComment = new Comment({dateAdded: new Date(2018, 3, 1)});
const mediumComment = new Comment({dateAdded: new Date(2018, 6, 1)});
const newComment = new Comment({dateAdded: new Date(2018, 11, 1)});
let commentService: CommentService;

beforeEach(() => {
activatedRouteStub.setParentData({application: application});
commentService = TestBed.get(CommentService);
});

it('calls commentService getAllByApplicationId with the app id from the route', () => {
spyOn(commentService, 'getAllByApplicationId').and.callThrough();

component.ngOnInit();

expect(commentService.getAllByApplicationId).toHaveBeenCalledWith('AAAA');
});

it('attaches the resulting comments to the component and sorts by date descending', () => {
const commentResponse = Observable.of([mediumComment, newComment, oldComment]);
spyOn(commentService, 'getAllByApplicationId').and.returnValue(commentResponse);

component.ngOnInit();

expect(component.comments).toEqual([oldComment, mediumComment, newComment]);
});

it('sets loading to false', () => {
component.ngOnInit();
expect(component.loading).toEqual(false);
});
});
});

describe('when the application is not available from the route', () => {
beforeEach(() => {
activatedRouteStub.setParentData({something: 'went wrong'});
});

it('redirects to /applications', () => {
component.ngOnInit();
expect(component.loading).toEqual(false);
expect(routerSpy.navigate).toHaveBeenCalledWith(['/applications']);
});
});
});
37 changes: 30 additions & 7 deletions src/app/application/decisions-tab/decisions-tab.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ import { ApplicationService } from 'app/services/application.service';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import { Application } from 'app/models/application';
import { ActivatedRoute } from '@angular/router';
import { ActivatedRoute, Router } from '@angular/router';
import { ActivatedRouteStub } from 'app/spec/helpers';

describe('DecisionsTabComponent', () => {
let component: DecisionsTabComponent;
let fixture: ComponentFixture<DecisionsTabComponent>;

const existingApplication = new Application();
const activatedRouteStub = {
parent: {
data: Observable.of({application: existingApplication}),
snapshot: {}
}
const validRouteData = {application: existingApplication};

const activatedRouteStub = new ActivatedRouteStub(validRouteData);
const routerSpy = {
navigate: jasmine.createSpy('navigate')
};

const apiServiceStub = {
Expand Down Expand Up @@ -48,7 +49,8 @@ describe('DecisionsTabComponent', () => {
providers: [
{ provide: ApiService, useValue: apiServiceStub },
{ provide: ApplicationService, useValue: applicationServiceStub },
{ provide: ActivatedRoute, useValue: activatedRouteStub }
{ provide: ActivatedRoute, useValue: activatedRouteStub },
{ provide: Router, useValue: routerSpy },
]
})
.compileComponents();
Expand All @@ -63,4 +65,25 @@ describe('DecisionsTabComponent', () => {
it('should be created', () => {
expect(component).toBeTruthy();
});

describe('when the application is retrievable from the route', () => {
beforeEach(() => {
activatedRouteStub.setParentData(validRouteData);
});

it('sets the component application to the one from the route', () => {
expect(component.application).toEqual(existingApplication);
});
});

describe('when the application is not available from the route', () => {
beforeEach(() => {
activatedRouteStub.setParentData({something: 'went wrong'});
});

it('redirects to /applications', () => {
component.ngOnInit();
expect(routerSpy.navigate).toHaveBeenCalledWith(['/applications']);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,25 @@ import { VarDirective } from 'app/utils/ng-var.directive';
import { RouterTestingModule } from '@angular/router/testing';
import { ApplicationService } from 'app/services/application.service';
import { CommentPeriodService } from 'app/services/commentperiod.service';
import { Application } from 'app/models/application';

xdescribe('AppDetailPopupComponent', () => {
describe('AppDetailPopupComponent', () => {
let component: AppDetailPopupComponent;
let fixture: ComponentFixture<AppDetailPopupComponent>;
const application = new Application({_id: 'BBBB', appStatus: 'Application Under Review'});
const stubApplicationService = {
getStatusCode() {
return 'AC';
},

isAccepted() {
return true;
},

getStatusCode() { return 'AC'; },
isAccepted() { return true; },
isDispGoodStanding() { return false; },

isOffered() { return true; },
isOfferAccepted() { return true; },
isOfferNotAccepted() { return false; },
isAbandoned() { return false; },
isAllowed() { return false; },
isDisallowed() { return false; },
isSuspended() { return false; },
isUnknown() { return false; },
isCancelled() { return false; }
};

const stubCommentPeriodService = {
Expand All @@ -53,6 +51,7 @@ xdescribe('AppDetailPopupComponent', () => {
beforeEach(() => {
fixture = TestBed.createComponent(AppDetailPopupComponent);
component = fixture.componentInstance;
component.app = application;
fixture.detectChanges();
});

Expand Down
Loading

0 comments on commit ebf3a08

Please sign in to comment.