hatepoint / phrases-hyperskill-tests

0 stars 1 forks source link

Tests fail when using Broadcast receiver #11

Closed hatepoint closed 1 year ago

hatepoint commented 1 year ago

Can you please check the latest commit in dev/stage3? I didn't figure out how to add the support for notifications + broadcasts Other tests seem to work fine

Thanks @RedJocker

RedJocker commented 1 year ago

Is the solution on dev/stage3 the one you intend to test? I don't see a broadcast receiver on there.

RedJocker commented 1 year ago

Are you able to load user submissions from hyperstudio? Because the last tester on stopwatch project tried solving with use of AlarmManager+BroadcastReceiver and at first it didn't work, but then I wrote that method supportForAlarmManager and was able make assertions as expected. In case you can load try loading submission of user 282739162, I believe it is the last one, and run against current tests.

Another thing, I'm not sure that you are aware that tests can control passage of time with shadowLooper.idleFor(timeAmount, TimeUnit.THE_UNIT_YOU_LIKE). Probably to trigger alarm you have to schedule a time in the future and advance the clock to be after that time

hatepoint commented 1 year ago

I've never used hyperstudio before. Can you send me a link?

RedJocker commented 1 year ago

If you have permissions it appears a button with a purple H and a notepad on stages of a project together with some other buttons with admin links. for stopwatch stage5 would be this https://studio.hyperskill.org/login?next=/steps/9290/submissions, but you need permission. If you can see that then you can also load the submission on androidStudio clicking on a stage of the project with right click then course-creator -> apply hyperskill submission.


I think it is easier to include here the solution that uses AlarmManager + BroadcastReceiver and I will take a look on it. I have finished other tasks I was doing and alexandra asked me to give priority to this project so no need to be struggling with test just send me the troubles and I can try make them work

hatepoint commented 1 year ago

The solution is on the dev/stage3 branch. Receiver: https://github.com/hatepoint/phrases-hyperskill-tests/blob/dev/stage3/Phrases/stage3/src/main/java/org/hyperskill/phrases/Notification.kt AlarmManager (that one scheduleNotification method that is marked with / /): https://github.com/hatepoint/phrases-hyperskill-tests/blob/dev/stage3/Phrases/stage3/src/main/java/org/hyperskill/phrases/MainActivity.kt

RedJocker commented 1 year ago

Ok, I think I found the problem. Robolectric uses emulated time, but time libraries like Calendar are not shadowed by robolectric and return the actual computer time instead of the emulated time that begins at 1970-01-01 00:00 +/- timezone. And because of this supportForAlarmManager is never triggering intents, since there is a time comparation there happening with trigger time on today and SystemClock in beggining of 1970.

I think It is possible to have a @Before setup method to set the emulated time so that it syncs with computer time. I will keep testing things here to see how to handle this.

RedJocker commented 1 year ago

sent a pull request, now the test is failing because of notification title, but the notification is being sent though broadcast receiver