-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added finalization review for dives comparison
- Loading branch information
Showing
7 changed files
with
199 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
projects/planner/src/app/shared/profileCompoarator.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import { inject, TestBed } from '@angular/core/testing'; | ||
import { DiveSchedules } from './dive.schedules'; | ||
import { ProfileComparatorService } from './profileComparatorService'; | ||
import { ReloadDispatcher } from './reloadDispatcher'; | ||
import { UnitConversion } from './UnitConversion'; | ||
import { WayPoint } from './models'; | ||
import { ConsumptionByMix, IConsumedMix, Segment, StandardGases, Tank } from 'scuba-physics'; | ||
|
||
describe('ProfileComparison service', () => { | ||
let sut: ProfileComparatorService; | ||
let schedules: DiveSchedules; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [], | ||
imports: [], | ||
providers: [ | ||
ProfileComparatorService, UnitConversion, | ||
ReloadDispatcher, DiveSchedules, | ||
] | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
sut = TestBed.inject(ProfileComparatorService); | ||
schedules = TestBed.inject(DiveSchedules); | ||
}); | ||
|
||
it('Has default dives', () => { | ||
expect(sut.profileA).toEqual(schedules.dives[0]); | ||
expect(sut.profileB).toEqual(schedules.dives[0]); | ||
}); | ||
|
||
it('Has only one profile', () => { | ||
expect(sut.hasTwoProfiles()).toBeFalsy(); | ||
}); | ||
|
||
// TODO remove hasTwoProfiles or use it | ||
// change it to get property and all other properties in the service | ||
it('Has two profiles', () => { | ||
schedules.add(); | ||
expect(sut.hasTwoProfiles()).toBeTruthy(); | ||
}); | ||
|
||
it('Total duration of one dive', inject([UnitConversion], (units: UnitConversion) => { | ||
schedules.selected.diveResult.wayPoints = [ | ||
WayPoint.fromSegment(units, new Segment(0,0, StandardGases.air, 600)) | ||
]; | ||
|
||
expect(sut.totalDuration).toEqual(600); | ||
})); | ||
|
||
it('Total duration Profile B dive', inject([UnitConversion], (units: UnitConversion) => { | ||
schedules.add(); | ||
schedules.dives[0].diveResult.wayPoints = [ | ||
WayPoint.fromSegment(units, new Segment(0,0, StandardGases.air, 500)) | ||
]; | ||
|
||
schedules.dives[1].diveResult.wayPoints = [ | ||
WayPoint.fromSegment(units, new Segment(0,0, StandardGases.air, 700)) | ||
]; | ||
// TODO rename appendProfileToProfileComparison to selectProfile | ||
sut.appendProfileToProfileComparison(1); | ||
|
||
expect(sut.totalDuration).toEqual(700); | ||
})); | ||
|
||
// TODO rename to Consumption profileACombinedTanks, profileBCombinedTanks | ||
describe('Tanks combined consumption', () => { | ||
let combineMethod: jasmine.Spy<(tanks: Tank[]) => IConsumedMix[]>; | ||
|
||
beforeEach(() => { | ||
schedules.add(); | ||
schedules.dives[0].tanksService.tankData[0].consumed = 50; | ||
schedules.dives[1].tanksService.tankData[0].consumed = 100; | ||
sut.appendProfileToProfileComparison(1); | ||
combineMethod = spyOn(ConsumptionByMix, 'combine') | ||
.and.callThrough(); | ||
}); | ||
|
||
it('profileACombinedTanks call combined consumption for Profile A', () => { | ||
const _ = sut.profileACombinedTanks; | ||
expect(combineMethod).toHaveBeenCalledWith(sut.profileA.tanksService.tankData); | ||
}); | ||
|
||
it('profileBCombinedTanks call combined consumption for Profile B', () => { | ||
const _ = sut.profileBCombinedTanks; | ||
expect(combineMethod).toHaveBeenCalledWith(sut.profileB.tanksService.tankData); | ||
}); | ||
}); | ||
|
||
describe('Handles only calculated profiles', () => { | ||
// TODO areProfilesCalculated change to property | ||
// TODO switch waitUntilProfilesCalculated to use events from Dispatcher the drawing components | ||
it('Waits until profiles are calculated', async() => { | ||
let eventReceived = false; | ||
sut.profileAResults.showStillRunning(); | ||
|
||
setTimeout(() => { | ||
sut.profileAResults.profileFinished(); | ||
}, 110); // more than the service waits | ||
|
||
await sut.waitUntilProfilesCalculated().then(() => { | ||
eventReceived = true; | ||
}); | ||
|
||
expect(eventReceived).toBeTruthy(); | ||
}); | ||
|
||
it('By default Not calculated profiles', () => { | ||
expect(sut.areProfilesCalculated()).toBeFalsy(); | ||
}); | ||
|
||
it('Profiles are already calculated', () => { | ||
// TODO distinguish profile calculated, consumption and diveInfo | ||
sut.profileAResults.profileFinished(); | ||
sut.profileBResults.profileFinished(); | ||
expect(sut.areProfilesCalculated()).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe('Select new profile', () => { | ||
const expectedA = 2; | ||
const expectedB = 1; | ||
let newProfileA = -1; // set to non existing index | ||
let newProfileB = -1; | ||
|
||
beforeEach(() => { | ||
schedules.add(); | ||
schedules.add(); | ||
|
||
// TODO rename to ProfileAChanged and dont create new one, but initialize in constructor | ||
sut.profileAIndex.subscribe((newIndex: number) => newProfileA = newIndex); | ||
sut.profileBIndex.subscribe((newIndex: number) => newProfileB = newIndex); | ||
|
||
// TODO remove appendProfileToProfileComparison method return value | ||
sut.appendProfileToProfileComparison(expectedA); | ||
sut.appendProfileToProfileComparison(expectedB); | ||
}); | ||
|
||
it('Selects Profile', () => { | ||
expect(sut.profileA).toEqual(schedules.dives[expectedA]); | ||
expect(sut.profileB).toEqual(schedules.dives[expectedB]); | ||
}); | ||
|
||
it('Profile A change event received', () => { | ||
expect(newProfileA).toEqual(expectedA); | ||
}); | ||
|
||
it('Profile B change event received', () => { | ||
expect(newProfileB).toEqual(expectedB); | ||
}); | ||
}); | ||
}); | ||
|
32 changes: 32 additions & 0 deletions
32
projects/planner/src/app/shared/waypoints-difference.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { WaypointsDifferenceService } from './waypoints-difference.service'; | ||
import { ProfileComparatorService } from './profileComparatorService'; | ||
import { DiveSchedules } from './dive.schedules'; | ||
import { UnitConversion } from './UnitConversion'; | ||
import { ReloadDispatcher } from './reloadDispatcher'; | ||
|
||
fdescribe('WayPoints Difference Service', () => { | ||
let sut: WaypointsDifferenceService; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [], | ||
providers: [ | ||
WaypointsDifferenceService, ProfileComparatorService, | ||
DiveSchedules, UnitConversion, ReloadDispatcher | ||
], | ||
imports: [] | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
sut = TestBed.inject(WaypointsDifferenceService); | ||
}); | ||
|
||
// TODO add more real tests on diff of two dive waypoints | ||
it('No errors comparing waypoints', () => { | ||
// TODO rename to difference, refactor to property | ||
const diff = sut.getRows(); | ||
expect(diff).not.toBeNull(); | ||
}); | ||
}); |