Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite angular service - input-matcher #1061

Merged
merged 21 commits into from
Nov 10, 2023

Conversation

jiji14
Copy link
Contributor

@jiji14 jiji14 commented Oct 10, 2023

Rewrite input-matcher.js Angular service

Related Issue: GitHub Issue #1001

Input-matcher is a function designed to check if the user's trip input is correct and print logs. I've kept the fundamental logic while updating the old JavaScript syntax and adding input/output types for each function.

Screenshot


1. Replacing moment with Luxon

Previously, the Moment format function was used to print logs. I have replaced moment with Luxon.

Here's a comparison of the two outputs:
Comparison Screenshot


2. Unit Testing

I have written test cases for both valid and invalid inputs for each function. To ensure proper testing, please add "testEnvironment": "jsdom" to your jest.config.json (I haven't pushed the update for jest.config.json to avoid conflicts).

Here are the test results:
Test Results


I had to merge onboarding_routing_sept_2023 branch because service_rewrite_2023 is too out-dated.

@jiji14 jiji14 marked this pull request as draft October 10, 2023 16:54
@jiji14 jiji14 marked this pull request as ready for review October 13, 2023 22:38
www/js/survey/input-matcher.ts Outdated Show resolved Hide resolved
www/js/survey/input-matcher.ts Outdated Show resolved Hide resolved
www/__tests__/input-matcher.test.ts Outdated Show resolved Hide resolved
@JGreenlee
Copy link
Collaborator

resolved merge conflicts

@jiji14 jiji14 marked this pull request as draft October 16, 2023 16:56
@jiji14 jiji14 requested a review from JGreenlee October 17, 2023 19:45
www/js/types/diaryTypes.ts Outdated Show resolved Hide resolved
www/js/types/diaryTypes.ts Show resolved Hide resolved
www/__tests__/inputMatcher.test.ts Outdated Show resolved Hide resolved
@jiji14 jiji14 marked this pull request as ready for review October 18, 2023 18:17
the-bay-kay added a commit to the-bay-kay/e-mission-phone that referenced this pull request Oct 18, 2023
As discussed in PR e-mission#1061, Jiji is working on setting up a folder in
`www/js/` to contain many of our type interfaces and templates.  For
now, I've added my own `fileIOTypes.ts`.  We discussed the types added
so far, and found we were working with overlapping types! As such,
I plan to copy over her version of `DiaryTypes.ts` found in commit
ffcc871, and will use that to replace the current dataObj interface
in `controlHelper.test.ts`.

Changes made:
- Set up `www/js/types`, moved fsWindow interface there
- Added basic tests for createWriteFile
@jiji14 jiji14 requested a review from JGreenlee October 18, 2023 19:55
the-bay-kay added a commit to the-bay-kay/e-mission-phone that referenced this pull request Oct 19, 2023
- While the types themselves may be subject to change, the goal is to
 set up a good foundation for strict typing in the future! As such,
 I added some to a basic version of Jiji's diaryTypes (see PR
 e-mission#1061), and will be updating those regularly.
@JGreenlee
Copy link
Collaborator

@shankari So what do we want to do with this PR? Are we going to change the tests to match the ones on the server (#1061 (comment))? Are we going to do that now or later?

One other option is to let #1086 absorb this PR since it includes these changes and builds on top of them. We could leave this PR open and come back to it when we figure out the testing strategy.

@shankari
Copy link
Contributor

shankari commented Nov 4, 2023

@JGreenlee thanks for the clarification around TestUserInputFakeData.py and the different tests here.
I think we can go ahead and merge this now, but we should file a separate cleanup issue to pull out the javascript + python input matcher code into a separate module, and unify the tests in both languages.

This wasn't in "Ready for review", so I'm going to go and review #1086 for now just in case there's anything else pending here. But the tests are passing, so if this is moved into the correct column, I am happy to merge ASAP

Copy link
Contributor

@shankari shankari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is really hard to review this change given the extraneous whitespace.
@jiji14 @JGreenlee can one of you please fix the prettier issues so that I can focus on the actual changes?

www/js/survey/enketo/enketo-trip-button.js Show resolved Hide resolved
@jiji14
Copy link
Contributor Author

jiji14 commented Nov 4, 2023

It is really hard to review this change given the extraneous whitespace. @jiji14 @JGreenlee can one of you please fix the prettier issues so that I can focus on the actual changes?

@shankari Let me fix this!

@jiji14
Copy link
Contributor Author

jiji14 commented Nov 6, 2023

@shankari

I deleted inputMatcher dependency in factory, and then Prettier changed the line break since it became shorter than the original one. That's why the white space got altered. The only solution I can think of to fix this issue is to use prettier ignore line so that you don't see the changes, but I don't think it's a good idea. What do you think?

[ before ]

  .factory(
    'EnketoNotesButtonService',
    function (InputMatcher, EnketoSurveyAnswer, Logger, $timeout) {
      var enbs = {};

[ after ]

  .factory('EnketoNotesButtonService', function (EnketoSurveyAnswer, Logger, $timeout) {
    var enbs = {};

@JGreenlee
Copy link
Collaborator

JGreenlee commented Nov 6, 2023

I deleted inputMatcher dependency in factory, and then Prettier changed the line break since it became shorter than the original one. That's why the white space got altered.

Interesting that Prettier actually changes the indent level based on one line being longer or shorter.

I agree and think you should leave it how it is. When we look at the diff, we can just enable the 'Hide whitespace' option to make it easier to review

@shankari
Copy link
Contributor

shankari commented Nov 6, 2023

@jiji14 if there is a real change in the line, I am OK with associate whitespace changes. I just don't like whitespace changes with no associated code changes caused by different editors.

When we look at the diff, we can just enable the 'Hide whitespace' option to make it easier to review

I will probably not use "Hide whitespace" because it will also hide the spurious whitespace changes. But maybe if Prettier ensures that we never get those...

@shankari
Copy link
Contributor

if there is a real change in the line, I am OK with associate whitespace changes.

Although it is really annoying that because of the difference in indentation, pretty much every single line was changed.
Particularly annoying since I have been very picky about whitespace changes to keep the commit history clean.
I wonder if it would be worthwhile to use prettier ignore when we have such large scale extraneous changes, and periodically remove them in a single commit labeled "prettier catch up" or something.

Let's see how often this happens before deciding...

@shankari
Copy link
Contributor

@JGreenlee I just merged this. If you pull it into #1086 I can review that tomorrow.

@shankari shankari merged commit db08c76 into e-mission:service_rewrite_2023 Nov 10, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants