Do nothing for action clicks (#702)

* Do nothing for action clicks

* [AUTOMATED]: Prettier Code Styling

* Address comment
This commit is contained in:
Mertcan Mermerkaya
2018-04-25 12:48:01 +01:00
committed by GitHub
parent a51bf41bbe
commit cfb9ca0d7a
2 changed files with 27 additions and 1 deletions
@@ -159,11 +159,15 @@ export class SWController extends ControllerInterface {
) {
// Not an FCM notification, do nothing.
return;
} else if (event.action) {
// User clicked on an action button.
// This will allow devs to act on action button clicks by using a custom
// onNotificationClick listener that they define.
return;
}
// Prevent other listeners from receiving the event
event.stopImmediatePropagation();
event.notification.close();
const msgPayload: MessagePayload = event.notification.data[FCM_MSG];
@@ -517,6 +517,28 @@ describe('Firebase Messaging > *SWController', () => {
expect(event.stopImmediatePropagation.callCount).to.equal(0);
});
it('should do nothing for action clicks', async () => {
const waitUntilSpy = sandbox.spy();
const event: any = {
notification: {
data: {
FCM_MSG: {
notification: {}
}
},
close: sandbox.spy()
},
waitUntil: waitUntilSpy,
stopImmediatePropagation: sandbox.spy(),
action: 'action1'
};
const swController = new SWController(app);
swController.onNotificationClick(event);
expect(event.stopImmediatePropagation.callCount).to.equal(0);
});
it('should handle FCM notification without a notification data field', async () => {
const waitUntilSpy = sandbox.spy();
const event: any = {