refactor(service-worker): Format comments and add additional test (#25860)
- Format JSDoc for notificationClicks - Add comment on why handleClick does not use hasOwnProperty - Add additional test that uses handleClick without action PR Close #25860
This commit is contained in:
parent
4a01ada291
commit
aca8ea9c0b
|
@ -27,15 +27,14 @@ export class SwPush {
|
|||
|
||||
/**
|
||||
* Emits the payloads of the received push notification messages as well as the action the user
|
||||
* interacted with.
|
||||
* If no action was used the action property will be an empty string `''`.
|
||||
* interacted with. If no action was used the action property will be an empty string `''`.
|
||||
*
|
||||
* Note that the `notification` property is **not** a
|
||||
* [Notification](https://developer.mozilla.org/en-US/docs/Web/API/Notification) object but rather
|
||||
* a
|
||||
* Note that the `notification` property is **not** a [Notification][Mozilla Notification] object
|
||||
* but rather a
|
||||
* [NotificationOptions](https://notifications.spec.whatwg.org/#dictdef-notificationoptions)
|
||||
* object that also includes the `title` of the
|
||||
* [Notification](https://developer.mozilla.org/en-US/docs/Web/API/Notification) object.
|
||||
* object that also includes the `title` of the [Notification][Mozilla Notification] object.
|
||||
*
|
||||
* [Mozilla Notification]: https://developer.mozilla.org/en-US/docs/Web/API/Notification
|
||||
*/
|
||||
readonly notificationClicks: Observable < {
|
||||
action: string;
|
||||
|
|
|
@ -309,6 +309,8 @@ export class Driver implements Debuggable, UpdateSource {
|
|||
notification.close();
|
||||
|
||||
const options: {-readonly[K in keyof Notification]?: Notification[K]} = {};
|
||||
// The filter uses `name in notification` because the properties are on the prototype so
|
||||
// hasOwnProperty does not work here
|
||||
NOTIFICATION_OPTION_NAMES.filter(name => name in notification)
|
||||
.forEach(name => options[name] = notification[name]);
|
||||
|
||||
|
|
|
@ -589,16 +589,30 @@ const manifestUpdateHash = sha1(JSON.stringify(manifestUpdate));
|
|||
}]);
|
||||
});
|
||||
|
||||
async_it('broadcasts notification click events', async() => {
|
||||
async_it('broadcasts notification click events with action', async() => {
|
||||
expect(await makeRequest(scope, '/foo.txt')).toEqual('this is foo');
|
||||
await driver.initialized;
|
||||
await scope.handleClick({title: 'This is a test', body: 'Test body'}, 'button');
|
||||
await scope.handleClick(
|
||||
{title: 'This is a test with action', body: 'Test body with action'}, 'button');
|
||||
const message: any = scope.clients.getMock('default') !.messages[0];
|
||||
|
||||
expect(message.type).toEqual('NOTIFICATION_CLICK');
|
||||
expect(message.data.action).toEqual('button');
|
||||
expect(message.data.notification.title).toEqual('This is a test');
|
||||
expect(message.data.notification.body).toEqual('Test body');
|
||||
expect(message.data.notification.title).toEqual('This is a test with action');
|
||||
expect(message.data.notification.body).toEqual('Test body with action');
|
||||
});
|
||||
|
||||
async_it('broadcasts notification click events without action', async() => {
|
||||
expect(await makeRequest(scope, '/foo.txt')).toEqual('this is foo');
|
||||
await driver.initialized;
|
||||
await scope.handleClick(
|
||||
{title: 'This is a test without action', body: 'Test body without action'});
|
||||
const message: any = scope.clients.getMock('default') !.messages[0];
|
||||
|
||||
expect(message.type).toEqual('NOTIFICATION_CLICK');
|
||||
expect(message.data.action).toBeUndefined();
|
||||
expect(message.data.notification.title).toEqual('This is a test without action');
|
||||
expect(message.data.notification.body).toEqual('Test body without action');
|
||||
});
|
||||
|
||||
async_it('prefetches updates to lazy cache when set', async() => {
|
||||
|
|
Loading…
Reference in New Issue