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

🎟️ πŸ”” πŸ“± Custom Events + pushNotify + storeDeviceSettings + remoteNotify rewrites #1093

Merged

Conversation

Abby-Wheelis
Copy link
Member

This will replace #1090, after we re-evaluated and made a decision to continue forward with custom events in #1024. I elected to start a fresh PR to keep the blame as clean as I could.

This introduces custom events, and migrates pushNotify to typescript. As this PR stands, there will be events "duplicated" because some applications still use $emit and $on while others use the new publish and subscribe. Where applicable, some events are broadcast using both methods, so they can be received by both methods.

Abby Wheelis added 7 commits October 31, 2023 14:11
React doesn't quite support custom events, so we're writing our own event handling code

this will apply to our custom events, rather than the built-in events like 'onClick'
in preparation for full de-angularization, renaming the file to preserve some of the blame history
updating to React, including the event subscription model usage
for now, so they get picked up both ways
@Abby-Wheelis
Copy link
Member Author

The custom events fit well into this paradigm, I've added the subscription calls to the "init" function that is replacing the platform.ready() call. The difficulty here is finding the best place to call this initialization script, I'm not sure we have a translation for $ionicPlatform.ready() yet, at least that I know of.

@Abby-Wheelis
Copy link
Member Author

One solution I found was to call the initialization logic using componentDidMount but that method did not seem to exist in App.tsx - I instead decided to add the call near other initialization logic:

  useEffect(() => {
    if (!appConfig) return;
    setServerConnSettings(appConfig).then(() => {
      refreshOnboardingState();
    });
    initPushNotify();
  }, [appConfig]);

I'm not sure if this is the best place for this, but it does seem to be working

Abby Wheelis added 6 commits October 31, 2023 16:38
after merging, needed to fix the differences in the was startprefs is used
the way to access the data from the event is with event.detail, not event.detail.data

I discovered and fixed this, as well as adding mocks, when I started a draft test

currently runs the code, but does not check that it runs correctly - used to know mocks were sufficient
now all but one feature has a passing test, working on testing the reconsent situation
moving to event-driven paradigm, so we don't call the method from pushNotify directly. this will apply to storedevicesettings once it gets migrated
Abby Wheelis added 2 commits November 1, 2023 12:01
after working on the consent event and process for checking for reconsent, we now have a test for that module that passes
Abby Wheelis added 2 commits November 1, 2023 13:46
added in test for the cloud event when subscribed and when not subscribed. additional mocking was required to handle the silent push functions
I had originally omitted the timeout because it seemed to break the test, but upon having the tests fully working, I was able to restore it

this change makes the test code a little more realistic
@Abby-Wheelis
Copy link
Member Author

This is going to have to be merged after #1072, because I pulled those changes into this PR, but the events are implemented and tested, and pushNotify has been rewritten and has tests. I'm glad we went with events, it made the code easier to test and somewhat simpler to implement.

@Abby-Wheelis Abby-Wheelis marked this pull request as ready for review November 1, 2023 19:54
@Abby-Wheelis
Copy link
Member Author

Abby-Wheelis commented Nov 1, 2023

Ok, that's my test that's failing now, I can sometimes replicate the fail locally, let me see if I can find the cause.


update: no clue how that was a "sometimes" fail (locally, it worked sometimes), since I had misspelled a key in my mock config, but I've resolve that and ironed out some of the "timeouts" (the events set of actions, which take some time to complete, but are async by design) and I centralized the clearNotifMock call to an afterEach instead of calling it in every test.

Abby Wheelis added 2 commits November 1, 2023 14:33
moved the clear plugin into an "afterEach" call to clean up the code

corrected a key spelling that fixed one of the tests, and updated the way I wait for the event handling to happen https://stackoverflow.com/questions/45478730/jest-react-testing-check-state-after-delay
syncing up the ways that tests run, replacing the way timeouts are set, removing unneeded timeout extension
@Abby-Wheelis Abby-Wheelis changed the base branch from service_rewrite_2023 to master November 2, 2023 14:44
@Abby-Wheelis Abby-Wheelis changed the base branch from master to service_rewrite_2023 November 2, 2023 14:44
Abby Wheelis added 2 commits November 3, 2023 10:58
I found two problems to fix in my testing - first was that I was not properly removing the event listeners and learned more: https://macarthur.me/posts/options-for-removing-event-listeners

Second was that I was missing a mock, which meant some of the storage operations were failing due to that function not exisiting
now testing for settings stored on initialization, on consent, and on intro done

also testing for not done if not consented on initialization, and if intro not done on consent
@Abby-Wheelis Abby-Wheelis changed the title 🎟️ πŸ”” Custom Events + pushNotify rewrite 🎟️ πŸ”” πŸ“± Custom Events + pushNotify + storeDeviceSettings rewrites Nov 3, 2023
@Abby-Wheelis
Copy link
Member Author

On checking for anything else listening for the events, I found that remotenotify listens for the notification event --

$rootScope.$on('cloud:push:notification', function (event, data) {

Since these changes alter the way we handle events, I'm probably going to move ahead with rewriting that file here as well. That will make this PR relatively big, but should take care of all the event-driven functionality in splash at once.

Abby Wheelis added 8 commits November 3, 2023 11:44
this is leftover code and I never used it in testing, removing
hoping to preserve some commit history here

remotenotify uses the cloud notif event, so rewritting alongside the rest of the event-driven code
migrate the file into typescript, including adding the event handling

remove references (all unused)

add init call with others in App.tsx
prettier wanted to make a bunch of changes to code that I didn't edit, so putting it in a dedicated commit
since our eventual goal is to remove angular, removing these calls since it will evaluate false if undefined anyways
checks for no action if not subscribed and action if subscribed
adding more tests - leveraged mocks to ensure that calls to open url or create popup were happening at the appropriate times
@Abby-Wheelis
Copy link
Member Author

This PR now encompasses all of the uses of the events for "intro done" "consent done" and "cloud notification". This includes customEventHandler, pushNotify, storeDeviceSettings, and remoteNotify -- along with the updates to my work in #1072 to ensure the events are handled in the new way. There are also tests for the custom events and each of the three splash services rewritten here!

@Abby-Wheelis Abby-Wheelis changed the title 🎟️ πŸ”” πŸ“± Custom Events + pushNotify + storeDeviceSettings rewrites 🎟️ πŸ”” πŸ“± Custom Events + pushNotify + storeDeviceSettings + remoteNotify rewrites Nov 3, 2023
Copy link
Collaborator

@JGreenlee JGreenlee left a comment

Choose a reason for hiding this comment

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

First pass of review-
This looks really clean already and I just have a few comments right now. The event code is definitely useful and I can see how it all comes together in the places you've utilized it!

www/js/splash/remoteNotifyHandler.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is really cool and not nearly as complex as I thought!

www/js/customEventHandler.ts Outdated Show resolved Hide resolved
www/js/splash/pushNotifySettings.ts Outdated Show resolved Hide resolved
www/js/splash/pushNotifySettings.ts Outdated Show resolved Hide resolved
data.additionalData.payload &&
data.additionalData.payload.alert_type
) {
if (data.additionalData.payload.alert_type == 'website') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@shankari Are we ever going to re-implement external web launches via push notification? If not, we can simplify

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should re-implement all the different types of push notification. I have pitched the external web launches, in particular, as mechanism for providing incentives for deployments with autogenerated tokens. The program admin can send a link to an amazon gift card directly to the participant though a push notification, without having to know their email/phone number etc.
Follow on to e-mission/e-mission-docs#976

Abby Wheelis added 5 commits November 6, 2023 11:59
we still have the information through debug statements
e-mission#1093 (comment)

kept to remain consistent within file
when I moved from the formatted alert to a plain alert, the text that ends up in the alert changed, but I did not update my test

also added a space between the title and the text
the-bay-kay added a commit to the-bay-kay/e-mission-phone that referenced this pull request Nov 9, 2023
- borrowed the windowAlert mocks from PR e-mission#1093, to allow error checking
- added mockCheck, updated some tests to use to `toEqual()`
@shankari
Copy link
Contributor

This has a merge conflict. Let me try to resolve if it is easy to avoid getting stuck in a circular loop...

Comment on lines +102 to +104
markIntroDone();
await new Promise((r) => setTimeout(r, 500));
publish(EVENTS.CONSENTED_EVENT, 'test data');
Copy link
Contributor

Choose a reason for hiding this comment

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

future fix: I think you also want to check that the user settings are not set before the CONSENTED_EVENT even though the intro is done.

@shankari
Copy link
Contributor

@JGreenlee merging this now - another potential source of merge conflicts

@shankari shankari merged commit ccb50c5 into e-mission:service_rewrite_2023 Nov 10, 2023
2 checks passed
@Abby-Wheelis Abby-Wheelis deleted the event-notif-rewrite branch November 10, 2023 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Address code reviews with "future"
Development

Successfully merging this pull request may close these issues.

3 participants