Skip to content

Commit

Permalink
βœ… πŸ› Improve user input matching mocks and use them
Browse files Browse the repository at this point in the history
The previous unit tests for the input matching assumed that the user input
would be of the form of the label options, so reused the label options as mock
options. However, they actually are of the form of user input objects with data
and metadata and the input as a label.

We create new mock objects with the correct format, and use them in the tests.

This is the reason why #1150
was not caught for so long.

And when we fixed the code, the test broke.
#1150 (comment)
#1150 (comment)

Testing done:

```
npx jest www/__tests__/confirmHelper.test.ts

Test Suites: 1 passed, 1 total
Tests:       11 passed, 11 total
```
  • Loading branch information
shankari committed May 5, 2024
1 parent ed61b8d commit 8b26d2d
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions www/__tests__/confirmHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ const fakeDefaultLabelOptions = {
},
},
};
const fakeInputs = {
MODE: [
{ data: { label: 'walk', start_ts: 1245, end_ts: 5678}},
{ data: { label: 'bike', start_ts: 1245, end_ts: 5678}},
],
PURPOSE: [
{ data: {label: 'home', start_ts: 1245, end_ts: 5678 }},
{ data: {label: 'work', start_ts: 1245, end_ts: 5678 }}
],
};

jest.mock('../js/services/commHelper', () => ({
...jest.requireActual('../js/services/commHelper'),
Expand All @@ -62,8 +72,8 @@ describe('confirmHelper', () => {

it('returns base labelInputDetails for a labelUserInput which does not have mode of study', () => {
const fakeLabelUserInput = {
MODE: fakeDefaultLabelOptions.MODE[1],
PURPOSE: fakeDefaultLabelOptions.PURPOSE[0],
MODE: fakeInputs.MODE[1],
PURPOSE: fakeInputs.PURPOSE[0],
};
const labelInputDetails = labelInputDetailsForTrip(
fakeLabelUserInput,
Expand All @@ -74,8 +84,8 @@ describe('confirmHelper', () => {

it('returns full labelInputDetails for a labelUserInput which has the mode of study', () => {
const fakeLabelUserInput = {
MODE: fakeDefaultLabelOptions.MODE[0], // 'walk' is mode of study
PURPOSE: fakeDefaultLabelOptions.PURPOSE[0],
MODE: fakeInputs.MODE[0], // 'walk' is mode of study
PURPOSE: fakeInputs.PURPOSE[0],
};
const labelInputDetails = labelInputDetailsForTrip(
fakeLabelUserInput,
Expand Down

0 comments on commit 8b26d2d

Please sign in to comment.