-
Notifications
You must be signed in to change notification settings - Fork 34
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
✍ Angular Services needing rewrite #977
Comments
Can we try to set up a test framework for pure functions so that we can:
Note that since these are pure functions, any errors may not be as easy to spot as errors in more visual, component-based functionality. So it would be great if we could do TDD for this round. We should anticipate it taking longer for the initial write, but requiring fewer rounds once it is done. |
Tips for rewriting Angular services into
|
I have identified these as services that don't significantly depend on other services and would be good to start with:
I have also marked the services that I plan to rewrite myself. There are a few big ones like |
@shankari Do you have any guidance on how to test functions that use Cordova plugins? Should we mock them? I can find some resources online of how to do that, but is there anywhere else in the project that we mock for testing that I could look at? |
I think that there are a few server tests that use mocking. We haven't had phone tests before, so they don't use mocking. For my own edification, is it correct that we can't just call the BEMUserCache plugin because you are running this a javascript environment without access to the cordova plugins? But even in that case, I don't think you need to mock the |
Correct. In the context that Jest runs the test in, Cordova does not exist.
localStorage exists on all browsers, but Jest doesn't run in a browser. I am guessing it's a Node process, so we can't use browser APIs I see some people saying that Jest automatically mocks I had to scroll down further to find the answer: https://stackoverflow.com/a/74309873 |
After discussion with @shankari , I am going to be changing ConfirmHelper to reproduce the functionality of i18nUtils because we decided that it is no longer needed - more specifically I am going to be making |
Per my conversation today with @shankari , I am going to start working on both of the |
What about I'd be happy to start on |
@Abby-Wheelis I wonder if this is the service that is trying to call the notification API during onboarding. It is in splash... |
Yes, that will need to be rewritten. Good find! It ties in closely with |
maybe? I'll certainly keep an eye on it. This is may be the place to reconsider how we handle consent, since there's several functions here that deal with gathering and saving consent. e-mission/e-mission-phone#1009 (comment) I can get an issue started to discuss if we want to make this change now / what we want to change to. |
I'm not 100% if |
Same question as Abby! I don't think |
@jiji14 Yes Be careful with these services -- even if none of their functions are explicitly called somewhere else in the codebase, they might have initialization logic that automatically runs when the Angular module is registered. E.g. with $ionicPlatform.ready().then(function() {
localNotify.registerRedirectHandler();
Logger.log("finished registering handlers, about to fire queued events");
$window.cordova.plugins.notification.local.fireQueuedEvents();
}); Anything inside |
Since both of my PR's are pending at the moment, I figured I'd start on the last |
I think I'm at a point to start on a new service rewrite ( |
Just updated the list adding
Technically, none of the calorie and MET code is used right now, but we will want to re-implement something like it later. (Instead of counting the calories burned from active travel (like walking or biking), we want to breakdown how many minutes were spent in high-intensity / moderate intensity / low-intensity active travel. Higher MET = higher intensity. It would also be cool to show MET over time for each active trip.) Open to discussion about how to organize the rewrites. I think we should definitely break them apart and place them in What do others think (especially @Abby-Wheelis who has worked the most closely with the dataset code)? |
I agree with breaking these apart into their own files - are you saying that From what I remember, the custom dataset code is used somewhat subtly, but it's very important, especially as more deployments are customizing their mode options, so we just need to make sure that we're still initializing and using the custom dataset when appropriate. discussion about old/new dash mismatch Overall, I agree with with your plan, that looks like it would make a total of 5 ts files (carbon, met, dataset helper, footprint helper, and met helper) which accounts for the 5 angular modules that currently make up those two files. I think breaking it down is better, and will mean things are more readable when we look back on them later. |
We talked about this some more today, and there are a few questions we need to figure out:
@shankari what do you think about these MET and Carbon considerations? |
|
The rewrite is done and merged to |
We have rewritten nearly all of the Angular directives and view as React components. So there is very little view/controller code left. However, this is a good amount of JS code still lingering around in Angular services (aka factories).
Prior to the first PR of the migration (before e-mission/e-mission-phone#974), there were ~78
.js
files in thewww/js
directory.As of 9/15/23, on the branch where we're the furthest ahead in the migration (on e-mission/e-mission-phone#1018) there are 48
.js
files, 16.ts
files, 8.jsx
files, and 47.tsx
files.Of the 48
.js
files, many of them actively being replaced right now - and many more of them will be gradually pruned as being obsolete as we progress with the migration.But the rest of them, (which I estimate is about half), we'll want to address on a separate timeline for the sake of efficiency. Here are a list of files I think will need to be rewritten:
// removed, not needed to rewritejs/i18n-utils.js
(if we still plan to use i18n-ized filenames. I think it would be preferable to just move fully to keyed i18n)js/services.js
(contains multiple services incl.(@JGreenlee),CommHelper
ControlHelper
(@the-bay-kay),UnifiedDataLoader
(@the-bay-kay). These should be split into separate files)js/config/dynamic_config.js
(~350 lines @JGreenlee)js/config/imperial.js
(was already rewritten intouseImperialConfig.ts
anyway)js/config/server_conn.js
(@JGreenlee)js/control/emailService.js
(@niccolopaganini)js/control/uploadService.js
(@Abby-Wheelis)js/diary/services.js
(this file was HUGE but has mostly been rewritten already. ~380 lines remain that should be rewritten into timelineHelper.ts (@the-bay-kay)js/plugin/storage.js
(@JGreenlee)js/splash/customURL.js
(@jiji14)// not needed on account of ❓js/splash/localnotify.js
LocalNotify
is not used anymore (is that ok?) #1028js/splash/notifScheduler.js
(@sebastianbarry)js/splash/pushnotify.js
(@Abby-Wheelis)// not needed - https://github.com/e-mission/e-mission-phone/pull/1040/files#r1351501452js/splash/referral.js
(I'm not actually sure what this file does or if we need it)js/splash/remotenotify.js
(@Abby-Wheelis)js/splash/startprefs.js
(@Abby-Wheelis)js/splash/storedevicesettings.js
(@Abby-Wheelis)js/stats/clientstats.js
(@JGreenlee)js/survey/input-matcher.js
(@jiji14)js/survey/enketo/answer.js
(rewrite intojs/survey/enketo/enketoHelper.ts
) (@Abby-Wheelis)js/survey/enketo/infinite_scroll_filters.js
(@sebastianbarry)js/survey/multilabel/infinite_scroll_filters.js
(@sebastianbarry)js/survey/enketo/enketo-add-note-button.js
(@JGreenlee)js/survey/enketo/enketo-trip-button.js
(@JGreenlee)js/survey/multilabel/multilabel-ui.js
(@JGreenlee)js/metrics-factory.js
(@Abby-Wheelis)js/metrics-mappings.js
(@Abby-Wheelis)After all these are rewritten, there will be some cleanup tasks (@JGreenlee):
ngApp.js
intoindex.js
getAngularService
is not used anywhereangular-react-helper.tsx
(it served us well 🫡)controllers.js
,diary.js
,main.js
,services.js
(should be empty),localnotify.js
,referral.js
,i18n-utils.js
, the Angular service fromlogger.ts
Also needing to happen:
OpenSourceLicenses.md
The text was updated successfully, but these errors were encountered: