Skip to content

Commit

Permalink
Have all unit tests passing, comitting from yesterday.
Browse files Browse the repository at this point in the history
This was particularly tricky due to an angular-cli bug, documented here:
angular/angular-cli#7296

Recommendation: use `ng test --sourcemaps=false` for now while running unit tests.
  • Loading branch information
acoard committed Oct 20, 2017
1 parent aba91ca commit 93c7f4c
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { FormsModule } from "@angular/forms";
import { ToggleComponent } from '../../common/toggle/toggle.component';
import { MspDateComponent } from '../../common/date/date.component';
import { MspProvinceComponent } from '../../common/province/province.component';
import { MspOutofBCRecordComponent } from '../../common/outof-bc/outof-bc.component';
import { MspDischargeDateComponent } from '../../common/discharge-date/discharge-date.component';
import { CalendarYearFormatter } from '../../common/calendar/calendar-year-formatter.component';
import { Ng2CompleterModule } from "ng2-completer";
import { MspDepartureDateComponent } from '../../common/departure-date/departure-date.component';
import { Person } from '../../model/person.model';
import { Relationship } from '../../model/status-activities-documents';

//Weirdly, including MspReturnDateComponent in declarations leads to ALL of the tests failing to run because it can't load the component factory.
//Have to run `ng test --sourcemaps=false`
//https://github.com/angular/angular-cli/issues/7296
import { MspReturnDateComponent } from '../../common/return-date/return-date.component';
import { AddNewDependentBeneficiaryComponent } from './add-new-dependent-beneficiary.component';

describe('AddNewDependentBeneficiaryComponent', () => {
Expand All @@ -8,14 +23,22 @@ describe('AddNewDependentBeneficiaryComponent', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ AddNewDependentBeneficiaryComponent ]
declarations: [AddNewDependentBeneficiaryComponent, ToggleComponent, MspDateComponent, MspProvinceComponent, MspOutofBCRecordComponent, MspDischargeDateComponent, CalendarYearFormatter,
MspReturnDateComponent,
AddNewDependentBeneficiaryComponent,
MspDepartureDateComponent],
imports: [FormsModule, Ng2CompleterModule]
})
.compileComponents();
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(AddNewDependentBeneficiaryComponent);
component = fixture.componentInstance;
let spouse = new Person(Relationship.Spouse);
component.person = spouse;


fixture.detectChanges();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,55 @@ import { ToggleComponent } from '../../common/toggle/toggle.component';
import { StatusInCanadaRadioComponent } from '../../common/status-in-canada-radio/status-in-canada-radio.component';
import { MspDateComponent } from '../../common/date/date.component';
import { AccountPersonalDetailsComponent } from '../personal-info/personal-details/personal-details.component'

import { CalendarYearValidator } from '../../common/calendar/calendar-year.validator';
import { CalendarMonthValidator } from '../../common/calendar/calendar-month.validator';
import { CalendarDayValidator } from '../../common/calendar/calendar-day.validator';
import { CalendarYearFormatter } from '../../common/calendar/calendar-year-formatter.component';
import { AddNewDependentBeneficiaryComponent } from '../add-new-dependent-beneficiary/add-new-dependent-beneficiary.component';
import { MspNameComponent } from '../../common/name/name.component';
import { MspGenderComponent } from "../../common/gender/gender.component";
import { MspBirthDateComponent } from "../../common/birthdate/birthdate.component";
import { MspPhnComponent } from "../../common/phn/phn.component";
import { MspPhoneComponent } from "../../common/phone/phone.component"
import { MspDischargeDateComponent } from "../../common/discharge-date/discharge-date.component";
"../../common/birthdate/birthdate.component";
import { MspSchoolDateComponent } from "../../common/schoolDate/school-date.component";
import { MspAddressComponent } from "../../common/address/address.component";
import { MspProvinceComponent } from "../../common/province/province.component";
import { MspArrivalDateComponent } from "../../common/arrival-date/arrival-date.component";
import { MspOutofBCRecordComponent } from '../../common/outof-bc/outof-bc.component';
import { Mod11CheckValidator } from "../../common/phn/phn.validator";
import { MspCountryComponent } from "../../common/country/country.component";
import { MspDataService } from '../../service/msp-data.service';
import { Ng2CompleterModule } from "ng2-completer";
import { MspDepartureDateComponent } from '../../common/departure-date/departure-date.component';
import {MspReturnDateComponent} from '../../common/return-date/return-date.component';

import { Person } from '../../model/person.model';
import { Relationship } from '../../model/status-activities-documents';






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

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [AddRemoveDependentComponent, ToggleComponent, StatusInCanadaRadioComponent, MspDateComponent, AccountPersonalDetailsComponent, CalendarYearValidator, CalendarMonthValidator, CalendarDayValidator, CalendarYearFormatter],
imports: [FormsModule]
declarations: [AddRemoveDependentComponent, ToggleComponent, StatusInCanadaRadioComponent, MspDateComponent, AccountPersonalDetailsComponent, CalendarYearValidator, CalendarMonthValidator, CalendarDayValidator, CalendarYearFormatter, AddNewDependentBeneficiaryComponent, MspNameComponent, MspGenderComponent, MspBirthDateComponent, MspPhnComponent, MspPhoneComponent, MspDischargeDateComponent, MspSchoolDateComponent, MspAddressComponent, MspProvinceComponent, MspArrivalDateComponent, MspOutofBCRecordComponent, Mod11CheckValidator, MspCountryComponent, MspDepartureDateComponent, MspReturnDateComponent],
imports: [FormsModule, Ng2CompleterModule],
providers: [MspDataService]
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(AddRemoveDependentComponent);
component = fixture.componentInstance;
component.person = new Person(Relationship.Spouse);
fixture.detectChanges();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { LocalStorageModule } from "angular-2-local-storage";
import { Relationship } from "../../model/status-activities-documents";
import { AccountDependentChangeComponent } from "./dependent-change.component";




import { CaptchaComponent } from "mygovbc-captcha-widget/src/app/captcha/captcha.component";
import { CaptchaDataService } from "mygovbc-captcha-widget/src/app/captcha-data.service";

Expand All @@ -20,7 +23,6 @@ describe("AccountDependentChangeComponent", () => {
const changeDetectorRefStub = {};
const routerStub = {};
const processServiceStub = {};
const relationshipStub = {};
TestBed.configureTestingModule({
declarations: [ AccountDependentChangeComponent, CaptchaComponent ],
schemas: [ NO_ERRORS_SCHEMA ],
Expand All @@ -29,15 +31,12 @@ describe("AccountDependentChangeComponent", () => {
MspDataService,
{ provide: Router, useValue: routerStub },
{ provide: ProcessService, useValue: processServiceStub },
// LocalStorageService,
LocalStorageModule.withConfig({
prefix: 'TEST.ca.bc.gov.msp',
storageType: 'sessionStorage'
}),
{ provide: Relationship, useValue: relationshipStub },
CaptchaDataService
],
imports: [FormsModule]
imports: [FormsModule, LocalStorageModule.withConfig({
prefix: 'ca.bc.gov.msp',
storageType: 'sessionStorage'
})]
});
fixture = TestBed.createComponent(AccountDependentChangeComponent);
comp = fixture.componentInstance;
Expand All @@ -47,10 +46,6 @@ describe("AccountDependentChangeComponent", () => {
expect(comp).toBeTruthy();
});

it("Relationship defaults to: Relationship", () => {
expect(comp.Relationship).toEqual(Relationship);
});

it("changedDependents defaults to: []", () => {
expect(comp.changedDependents).toEqual([]);
});
Expand Down Expand Up @@ -83,7 +78,7 @@ describe("AccountDependentChangeComponent", () => {
comp.addChild(Relationship.Child19To24);
expect(comp.children.length).toBe(2);
comp.clearDependent(comp.children[0]);
comp.clearDependent(comp.children[1]);
comp.clearDependent(comp.children[0]); //second child, as indexes are reset
expect(comp.children.length).toBe(0);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class AccountDependentChangeComponent extends BaseComponent {
addChild(relationship: Relationship){
const child = new Person(relationship);
this.changedDependents.push(child);
this.children.push(child);
}

/** Remove a dependent that the user had added to the form, e.g. by mistake. Spouse or children. */
Expand All @@ -73,6 +74,9 @@ export class AccountDependentChangeComponent extends BaseComponent {
if (dependent.relationship === Relationship.Spouse){
this.spouse = null;
}

this.children = this.children
.filter(x => x !== dependent);
}

get spouse(): Person {
Expand All @@ -87,6 +91,12 @@ export class AccountDependentChangeComponent extends BaseComponent {
return this.dataService.getMspAccountApp().children;
}

set children(val: Person[]) {
this.dataService.getMspAccountApp().children = val;
}




// TODO!
get spouseRemoval(): Person {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { MspLogService } from '../../service/log.service';
import { ActivatedRoute, Router } from '@angular/router';
import { RouterTestingModule } from '@angular/router/testing';
import { ProcessService } from "../../service/process.service";
import { MspApiService } from '../../service/msp-api.service';

import { CaptchaComponent } from "mygovbc-captcha-widget/src/app/captcha/captcha.component";
import { CaptchaDataService } from "mygovbc-captcha-widget/src/app/captcha-data.service";
Expand All @@ -27,7 +28,7 @@ describe('AccountPrepareComponent', () => {
storageType: 'sessionStorage'
})],
providers: [MspDataService, MspLogService, ProcessService,
LocalStorageService, CaptchaDataService
LocalStorageService, CaptchaDataService, MspApiService

]
})
Expand Down
13 changes: 10 additions & 3 deletions src/app/components/msp/model/account.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class MspAccountApp implements ApplicationBase {

set children(value: Array<Person>) {
this._children = value;
console.log("ARC account setChild length",this._children.length);
}

private _addedSpouse: Person;
Expand Down Expand Up @@ -100,7 +101,9 @@ class MspAccountApp implements ApplicationBase {

set removedSpouse(value: Person) {
this._removedSpouse = value;
this._removedSpouse.operationActionType = OperationActionType.Remove;
if (value){
this._removedSpouse.operationActionType = OperationActionType.Remove;
}
}

get addedSpouse(): Person {
Expand All @@ -109,7 +112,9 @@ class MspAccountApp implements ApplicationBase {

set addedSpouse(value: Person) {
this._addedSpouse = value;
this._addedSpouse.operationActionType = OperationActionType.Add;
if (value){
this._addedSpouse.operationActionType = OperationActionType.Add;
}
}

get updatedSpouse(): Person {
Expand All @@ -118,7 +123,9 @@ class MspAccountApp implements ApplicationBase {

set updatedSpouse(value: Person) {
this._updatedSpouse = value;
this._updatedSpouse.operationActionType = OperationActionType.Update;
if (value){
this._updatedSpouse.operationActionType = OperationActionType.Update;
}
}

set applicant(apt: Person) {
Expand Down

0 comments on commit 93c7f4c

Please sign in to comment.