mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(service-worker): NPE if onActionClick is undefined (#43210)
Previously, it leads to fail if notification.data.onActionClick is undefined PR Close #43210
This commit is contained in:
committed by
Alex Rickabaugh
parent
b10d90bef6
commit
6e924313c3
@@ -354,7 +354,7 @@ export class Driver implements Debuggable, UpdateSource {
|
||||
|
||||
const notificationAction = action === '' || action === undefined ? 'default' : action;
|
||||
|
||||
const onActionClick = notification?.data?.onActionClick[notificationAction];
|
||||
const onActionClick = notification?.data?.onActionClick?.[notificationAction];
|
||||
|
||||
const urlToOpen = new URL(onActionClick?.url ?? '', this.scope.registration.scope).href;
|
||||
|
||||
|
||||
@@ -1055,6 +1055,21 @@ describe('Driver', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('no onActionClick field', () => {
|
||||
it('has no client interaction', async () => {
|
||||
expect(await makeRequest(scope, '/foo.txt')).toEqual('this is foo');
|
||||
spyOn(scope.clients, 'openWindow');
|
||||
|
||||
await driver.initialized;
|
||||
await scope.handleClick(
|
||||
{title: 'This is a test without action', body: 'Test body without action', data: {}});
|
||||
await scope.handleClick(
|
||||
{title: 'This is a test with an action', body: 'Test body with an action', data: {}},
|
||||
'someAction');
|
||||
expect(scope.clients.openWindow).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('URL resolution', () => {
|
||||
it('should resolve relative to service worker scope', async () => {
|
||||
(scope.registration.scope as string) = 'http://localhost/foo/bar/';
|
||||
|
||||
Reference in New Issue
Block a user