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:
shlasouski
2021-08-20 15:23:47 +03:00
committed by Alex Rickabaugh
parent b10d90bef6
commit 6e924313c3
2 changed files with 16 additions and 1 deletions
+1 -1
View File
@@ -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/';