-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create NotificationPermissionControllerTests
Adding an initial test for the polling behavior Adding mocking for setting notifications as enabled/disabled in ShadowRoboNotificationManager Adding foregroundFetchNotificationPermissionInterval to the MockHelper configModel with a value of 1 ms
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
.../com/onesignal/notifications/internal/permission/NotificationPermissionControllerTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.onesignal.notifications.internal.permission | ||
|
||
import br.com.colman.kotest.android.extensions.robolectric.RobolectricTest | ||
import com.onesignal.core.internal.permissions.IRequestPermissionService | ||
import com.onesignal.core.internal.preferences.IPreferencesService | ||
import com.onesignal.debug.LogLevel | ||
import com.onesignal.debug.internal.logging.Logging | ||
import com.onesignal.mocks.AndroidMockHelper | ||
import com.onesignal.mocks.MockHelper | ||
import com.onesignal.notifications.internal.permissions.INotificationPermissionChangedHandler | ||
import com.onesignal.notifications.internal.permissions.impl.NotificationPermissionController | ||
import com.onesignal.notifications.shadows.ShadowRoboNotificationManager | ||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.mockk.every | ||
import io.mockk.just | ||
import io.mockk.mockk | ||
import io.mockk.runs | ||
import kotlinx.coroutines.delay | ||
import org.robolectric.annotation.Config | ||
|
||
@Config( | ||
packageName = "com.onesignal.example", | ||
shadows = [ShadowRoboNotificationManager::class], | ||
sdk = [33], | ||
) | ||
@RobolectricTest | ||
class NotificationPermissionControllerTests : FunSpec({ | ||
beforeAny { | ||
Logging.logLevel = LogLevel.NONE | ||
ShadowRoboNotificationManager.reset() | ||
} | ||
|
||
test("NotificationPermissionController permission polling fires permission changed event") { | ||
// Given | ||
val mockRequestPermissionService = mockk<IRequestPermissionService>() | ||
every { mockRequestPermissionService.registerAsCallback(any(), any()) } just runs | ||
val mockPreferenceService = mockk<IPreferencesService>() | ||
|
||
var handlerFired = false | ||
val notificationPermissionController = NotificationPermissionController(AndroidMockHelper.applicationService(), mockRequestPermissionService, AndroidMockHelper.applicationService(), mockPreferenceService, MockHelper.configModelStore()) | ||
|
||
notificationPermissionController.subscribe( | ||
object : INotificationPermissionChangedHandler { | ||
override fun onNotificationPermissionChanged(enabled: Boolean) { | ||
handlerFired = true | ||
} | ||
}, | ||
) | ||
|
||
// When | ||
// permission changes | ||
ShadowRoboNotificationManager.setNotificationsEnabled(false) | ||
delay(5) | ||
|
||
// Then | ||
// permissionChanged Event should fire | ||
handlerFired shouldBe true | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters