-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
front: write unit tests for transformRowDataOnChange
No change in behavior, just testing the previous behavior of the simulation input table, when a value changes.
- Loading branch information
1 parent
3fa263f
commit e8b9591
Showing
3 changed files
with
109 additions
and
24 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
75 changes: 75 additions & 0 deletions
75
front/src/modules/timesStops/helpers/__tests__/utils.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,75 @@ | ||
import type { PathWaypointRow } from 'modules/timesStops/types'; | ||
import { transformRowDataOnChange } from '../utils'; | ||
|
||
|
||
describe('transformRowDataOnChange', () => { | ||
const whateverOperation = { fromRowIndex: 2 }; | ||
|
||
describe('arrival is set, departure just changed', () => { | ||
it('should update stop duration from the arrival and departure', () => { | ||
const rowData = { | ||
opId: 'd94a2af4-6667-11e3-89ff-01f464e0362d', | ||
name: 'Gr', | ||
arrival: '23:40:00', | ||
departure: '23:50:00', | ||
stopFor: '300', // no longer correct, not yet updated by the function | ||
} as PathWaypointRow; | ||
const previousRowData = { | ||
opId: 'd94a2af4-6667-11e3-89ff-01f464e0362d', | ||
name: 'Gr', | ||
arrival: '23:40:00', | ||
departure: '23:45:00', | ||
stopFor: '300', | ||
} as PathWaypointRow; | ||
const result = transformRowDataOnChange(rowData, previousRowData, whateverOperation, 4); | ||
expect(result).toEqual({ | ||
opId: 'd94a2af4-6667-11e3-89ff-01f464e0362d', | ||
name: 'Gr', | ||
arrival: '23:40:00', | ||
departure: '23:50:00', | ||
stopFor: '600', // now correct with the new arrival and departure | ||
isMarginValid: true, | ||
}); | ||
}); | ||
}); | ||
describe('theoritical margin is incorrect', () => { | ||
it('should set isMarginValid flag to false', () => { | ||
const rowData = { | ||
opId: 'd94a2af4-6667-11e3-89ff-01f464e0362d', | ||
name: 'Gr', | ||
theoreticalMargin: '10', | ||
} as PathWaypointRow; | ||
const previousRowData = { | ||
opId: 'd94a2af4-6667-11e3-89ff-01f464e0362d', | ||
name: 'Gr', | ||
} as PathWaypointRow; | ||
const result = transformRowDataOnChange(rowData, previousRowData, whateverOperation, 4); | ||
expect(result.isMarginValid).toBe(false); | ||
}); | ||
}); | ||
describe('user removed first row theoritical margin', () => { | ||
it('should set the theoritical margin back to 0%', () => { | ||
const rowData = { | ||
opId: 'd94a2af4-6667-11e3-89ff-01f464e0362d', | ||
name: 'Gr', | ||
} as PathWaypointRow; | ||
const previousRowData = { | ||
opId: 'd94a2af4-6667-11e3-89ff-01f464e0362d', | ||
name: 'Gr', | ||
theoreticalMargin: '10%', | ||
} as PathWaypointRow; | ||
const operation = { | ||
fromRowIndex: 0, | ||
}; | ||
const result = transformRowDataOnChange(rowData, previousRowData, operation, 4); | ||
expect(result).toEqual({ | ||
opId: 'd94a2af4-6667-11e3-89ff-01f464e0362d', | ||
name: 'Gr', | ||
arrival: null, | ||
isMarginValid: true, | ||
onStopSignal: false, | ||
theoreticalMargin: '0%', | ||
}); | ||
}); | ||
}); | ||
}); |
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