-
Notifications
You must be signed in to change notification settings - Fork 213
Test NSE #4762
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
Test NSE #4762
Conversation
b492607 to
f07410e
Compare
❌ 2 Tests Failed:
View the top 1 failed test(s) by shortest run time
View the full list of 2 ❄️ flaky test(s)
To view more test analytics, go to the Test Analytics Dashboard |
c4c0364 to
c8a89d5
Compare
|
The tests take 0.5 locally... but sometimes on CI they may take more than 1 minute causing the test to fail. |
0bf249d to
861fecd
Compare
stefanceriu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talked about it elsewhere, great stuff! 👏
…he code to be unit tested
…ge to test the `communicationContext`
861fecd to
777cad2
Compare
|



This PR allows to test the notification content after it has been processed by the NSE, using UnitTests.
It contains 2 major project changes
NSE Files references
All NSE files are also referenced by Element X (the main app).
The reason for this is to allow generating mocks, but most importantly because due to a limitation of the Unit Tests, importing as testable the NSE is not possible, the compiler will not flag any error because it's able to find the definitions of the files... but will fail when building because it's not able to compile and link their content, since for some reason the UnitTests do not include the sources of app extensions directly, but just their signatures.
The only solution is then to have also the NSE code referenced in Element X so that the testable import resolves and compiles its sources.
Dynamic Swift Package
Use of the swift package Dynamic.
It allows to access private APIs from Apple... I know that sounds crazy, but the package is only used in UnitTests and it's not supposed to be used in the production code of the main app.
But what is the reason to do so, you might ask. The reason is simple, we use the quite obscure Communication Notifications APIs for instant messaging, these do a lot of stuff behind the curtains.
For example the title and the subtitle of the notification content are completely ignored when rendering the notification, and the values provided when generating the
INIntentto render the icon, set the sender, and the group of the message belongs to (if available) get used in its place.This all gets stored in a private member of the notification content called
communicationContext, and this member is not normally accessible since it's supposed to be used by the OS to render the notification as a communication notification. However there is a ton of logic behind customising the icon, the names displayed for the sender and/or the room based on mentions, threads, DMs and so on.Accessing the
communicationContextvalues is the best way to verify that the notification is formatted in the proper way and manner.Other changes
addSeconderIcontoaddCommunicationContextsince the old name was misleading, and made it seem like the function just added the icon, when in reality it also controls the rendering of the title and subtitle.What is missing?
Would be even nicer if we could get the icon file/image path... but I can't seem to find where it's referenced in the notification content. We could in this way check that the correct placeholder avatar is displayed, or if the correct avatar is used when available. But I am starting to think that is not at all present in the notification content itself, and that the OS does some stuff behind the curtains to handle that.