Skip to content

Commit

Permalink
chore(notification): add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nsbarsukov committed Oct 3, 2023
1 parent 89ab26e commit 6798568
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
storage,
workers,
view-transition,
notification,
]
name: ${{ matrix.project }}
steps:
Expand Down
59 changes: 59 additions & 0 deletions libs/notification/tests/notification.spec.ts
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');
});
});
});

0 comments on commit 6798568

Please sign in to comment.