refactor(service-worker): update tests based of review feedback (#25860)

- Rename invalid click event name
- Make test expects more explicit
- Remove NotificationClickEvent in favor of NotificationEvent

PR Close #25860
This commit is contained in:
Joost Zöllner 2018-09-21 11:09:44 +02:00 committed by Kara Erickson
parent c4ad83e7cd
commit f017b26e5d
4 changed files with 13 additions and 12 deletions

View File

@ -313,7 +313,7 @@ import {async_fit, async_it} from './async';
(msg: {message: string}) => receivedMessages.push(msg.message)); (msg: {message: string}) => receivedMessages.push(msg.message));
sendMessage('NOTIFICATION_CLICK', 'this was a click'); sendMessage('NOTIFICATION_CLICK', 'this was a click');
sendMessage('NOT_OTIFICATION_CLICK', 'this was not a click'); sendMessage('NOT_IFICATION_CLICK', 'this was not a click');
sendMessage('NOTIFICATION_CLICK', 'this was a click too'); sendMessage('NOTIFICATION_CLICK', 'this was a click too');
sendMessage('KCILC_NOITACIFITON', 'this was a KCILC_NOITACIFITON message'); sendMessage('KCILC_NOITACIFITON', 'this was a KCILC_NOITACIFITON message');

View File

@ -135,11 +135,12 @@ const serverUpdate =
scope.updateServerState(serverUpdate); scope.updateServerState(serverUpdate);
const gotNotificationClick = (async() => { const gotNotificationClick = (async() => {
const event = await obsToSinglePromise(push.messagesClicked); const event: any = await obsToSinglePromise(push.messagesClicked);
expect(event).toEqual({action: 'clicked', notification: {clicked: true}}); expect(event.action).toEqual('clicked');
expect(event.notification.title).toEqual('This is a test');
})(); })();
await scope.handleClick({clicked: true}, 'clicked'); await scope.handleClick({title: 'This is a test'}, 'clicked');
await gotNotificationClick; await gotNotificationClick;
}); });
}); });

View File

@ -72,7 +72,7 @@ interface ActivateEvent extends ExtendableEvent {}
// Notification API // Notification API
interface NotificationEvent { interface NotificationEvent extends ExtendableEvent {
action: string; action: string;
notification: Notification; notification: Notification;
} }
@ -83,8 +83,6 @@ interface PushEvent extends ExtendableEvent {
data: PushMessageData; data: PushMessageData;
} }
interface NotificationClickEvent extends NotificationEvent, ExtendableEvent {}
interface PushMessageData { interface PushMessageData {
arrayBuffer(): ArrayBuffer; arrayBuffer(): ArrayBuffer;
blob(): Blob; blob(): Blob;
@ -116,7 +114,7 @@ interface ServiceWorkerGlobalScope {
addEventListener(event: 'fetch', fn: (event?: FetchEvent) => any): void; addEventListener(event: 'fetch', fn: (event?: FetchEvent) => any): void;
addEventListener(event: 'install', fn: (event?: ExtendableEvent) => any): void; addEventListener(event: 'install', fn: (event?: ExtendableEvent) => any): void;
addEventListener(event: 'push', fn: (event?: PushEvent) => any): void; addEventListener(event: 'push', fn: (event?: PushEvent) => any): void;
addEventListener(event: 'notificationclick', fn: (event?: NotificationClickEvent) => any): void; addEventListener(event: 'notificationclick', fn: (event?: NotificationEvent) => any): void;
addEventListener(event: 'sync', fn: (event?: SyncEvent) => any): void; addEventListener(event: 'sync', fn: (event?: SyncEvent) => any): void;
fetch(request: Request|string): Promise<Response>; fetch(request: Request|string): Promise<Response>;

View File

@ -593,10 +593,12 @@ const manifestUpdateHash = sha1(JSON.stringify(manifestUpdate));
expect(await makeRequest(scope, '/foo.txt')).toEqual('this is foo'); expect(await makeRequest(scope, '/foo.txt')).toEqual('this is foo');
await driver.initialized; await driver.initialized;
await scope.handleClick({title: 'This is a test', body: 'Test body'}, 'button'); await scope.handleClick({title: 'This is a test', body: 'Test body'}, 'button');
expect(scope.clients.getMock('default') !.messages).toEqual([{ const message: any = scope.clients.getMock('default') !.messages[0];
type: 'NOTIFICATION_CLICK',
data: {action: 'button', notification: {title: 'This is a test', body: 'Test body'}} 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');
}); });
async_it('prefetches updates to lazy cache when set', async() => { async_it('prefetches updates to lazy cache when set', async() => {