-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89ab26e
commit 6798568
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -28,6 +28,7 @@ jobs: | |
storage, | ||
workers, | ||
view-transition, | ||
notification, | ||
] | ||
name: ${{ matrix.project }} | ||
steps: | ||
|
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,59 @@ | ||
import {TestBed} from '@angular/core/testing'; | ||
import {NOTIFICATION_SUPPORT, NotificationService} from '@ng-web-apis/notification'; | ||
import {firstValueFrom} from 'rxjs'; | ||
|
||
describe('Notification API', () => { | ||
describe('if Notification API is not supported', () => { | ||
let service: NotificationService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
{ | ||
provide: NOTIFICATION_SUPPORT, | ||
useValue: false, | ||
}, | ||
NotificationService, | ||
], | ||
}); | ||
|
||
service = TestBed.inject(NotificationService); | ||
}); | ||
|
||
it('method `requestPermission` (from `NotificationService`) returns Observable which fails with error', async () => { | ||
await expectAsync( | ||
firstValueFrom(service.requestPermission()), | ||
).toBeRejectedWithError('Notification API is not supported in your browser'); | ||
}); | ||
|
||
it('method `open` (from `NotificationService`) returns Observable which fails with error', async () => { | ||
await expectAsync( | ||
firstValueFrom(service.open('Hello world')), | ||
).toBeRejectedWithError('Notification API is not supported in your browser'); | ||
}); | ||
}); | ||
|
||
describe('if Notification API is supported', () => { | ||
let service: NotificationService; | ||
let notificationSupportToken: boolean; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [NotificationService], | ||
}); | ||
|
||
service = TestBed.inject(NotificationService); | ||
notificationSupportToken = TestBed.inject(NOTIFICATION_SUPPORT); | ||
}); | ||
|
||
it('token `NOTIFICATION_SUPPORT` returns true', () => { | ||
expect(notificationSupportToken).toBe(true); | ||
}); | ||
|
||
it('method `requestPermission` (from `NotificationService`) returns `default` permission for the first time', async () => { | ||
const permission = await firstValueFrom(service.requestPermission()); | ||
|
||
expect(permission).toBe('default'); | ||
}); | ||
}); | ||
}); |