Notification preferences API and screen (1n) (Feature 19) (#166)
CI / ci (push) Successful in 5m53s
CI / ci (push) Successful in 5m53s
Co-authored-by: orchestrator-agent <20+orchestrator-agent@code.cubecraftcreations.com>
This commit was merged in pull request #166.
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
decodeVapidKey,
|
||||
encodeBase64url,
|
||||
PermissionGestureError,
|
||||
pushStatus,
|
||||
subscribePush,
|
||||
subscriptionBody,
|
||||
unsubscribePush,
|
||||
@@ -306,3 +307,31 @@ describe('unsubscribePush', () => {
|
||||
await expect(unsubscribePush(api, env)).rejects.toThrow(/did not remove its push subscription/)
|
||||
})
|
||||
})
|
||||
|
||||
describe('pushStatus', () => {
|
||||
it('is on with permission granted and a subscription', async () => {
|
||||
const { env } = setup({ permission: 'granted', current: subscription() })
|
||||
expect(await pushStatus(env)).toBe('on')
|
||||
})
|
||||
|
||||
it.each([
|
||||
['not subscribed', { permission: 'granted' as const }],
|
||||
['permission not yet asked', { permission: 'default' as const }],
|
||||
['no service worker registered', { permission: 'granted' as const, registered: false }],
|
||||
])('is off when %s', async (_, options) => {
|
||||
const { env, notification } = setup(options)
|
||||
expect(await pushStatus(env)).toBe('off')
|
||||
expect(notification.requestPermission).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('is denied when the browser blocks notifications', async () => {
|
||||
const { env } = setup({ permission: 'denied', current: subscription() })
|
||||
expect(await pushStatus(env)).toBe('denied')
|
||||
})
|
||||
|
||||
it('is unsupported without Web Push', async () => {
|
||||
const { env } = setup()
|
||||
expect(await pushStatus({ ...env, pushManager: false })).toBe('unsupported')
|
||||
expect(await pushStatus({ ...env, notification: undefined })).toBe('unsupported')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user