Skip to content

Commit

Permalink
increase tests
Browse files Browse the repository at this point in the history
now all but one feature has a passing test, working on testing the reconsent situation
  • Loading branch information
Abby Wheelis committed Nov 1, 2023
1 parent bb8f1ec commit 5fbeac2
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
2 changes: 1 addition & 1 deletion www/__mocks__/pushNotificationMocks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let notifSettings;
let onList = {};
let onList : any = {};

export const mockPushNotification = () => {
window['PushNotification'] = {
Expand Down
63 changes: 59 additions & 4 deletions www/__tests__/pushNotifySettings.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { EVENT_NAMES, publish } from '../js/customEventHandler';
import { markIntroDone } from '../js/onboarding/onboardingHelper';
import { initPushNotify } from '../js/splash/pushNotifySettings';
import { mockCordova, mockBEMUserCache } from '../__mocks__/cordovaMocks';
import { mockLogger } from '../__mocks__/globalMocks';
import { mockPushNotification } from '../__mocks__/pushNotificationMocks';
import { clearNotifMock, getOnList, mockPushNotification } from '../__mocks__/pushNotificationMocks';

mockCordova();
mockLogger();
Expand All @@ -18,10 +19,64 @@ global.fetch = (url: string) => new Promise((rs, rj) => {
}));
}) as any;

it('initializes the push notifications', () => {
initPushNotify();
it('intro done does nothing if not registered', () => {
clearNotifMock();
expect(getOnList()).toStrictEqual({});
publish(EVENT_NAMES.INTRO_DONE_EVENT, "test data");
expect(getOnList()).toStrictEqual({});
})

publish(EVENT_NAMES.CONSENTED_EVENT, "test data");
it('intro done initializes the push notifications', () => {
clearNotifMock();
expect(getOnList()).toStrictEqual({});

initPushNotify();
publish(EVENT_NAMES.INTRO_DONE_EVENT, "test data");
// setTimeout(() => {}, 100);
expect(getOnList()).toStrictEqual(expect.objectContaining({
notification: expect.any(Function),
error: expect.any(Function),
registration: expect.any(Function)
}));
})

it('cloud event does nothing if not registered', () => {
publish(EVENT_NAMES.CLOUD_NOTIFICATION_EVENT, {additionalData: {'content-avaliable': 1}});
//how to test did nothing?
})

it('cloud event handles notification if registered', () => {
initPushNotify();
publish(EVENT_NAMES.CLOUD_NOTIFICATION_EVENT, {additionalData: {'content-avaliable': 1}});
//how to test did something?
})

it('consent event does nothing if not registered', () => {
clearNotifMock();
expect(getOnList()).toStrictEqual({});
publish(EVENT_NAMES.CONSENTED_EVENT, "test data");
expect(getOnList()).toStrictEqual({});
})

// it('consent event registers if intro done', () => {
// clearNotifMock();
// expect(getOnList()).toStrictEqual({});
// initPushNotify();
// markIntroDone();
// // setTimeout(() => {}, 100);
// publish(EVENT_NAMES.CONSENTED_EVENT, "test data");
// setTimeout(() => {}, 200);
// expect(getOnList()).toStrictEqual(expect.objectContaining({
// notification: expect.any(Function),
// error: expect.any(Function),
// registration: expect.any(Function)
// }));
// })

it('consent event does not register if intro not done', () => {
clearNotifMock();
expect(getOnList()).toStrictEqual({});
initPushNotify();
publish(EVENT_NAMES.CONSENTED_EVENT, "test data");
expect(getOnList()).toStrictEqual({}); //nothing, intro not done
})
1 change: 1 addition & 0 deletions www/js/splash/pushNotifySettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export const initPushNotify = function () {
.then(isConsented)
.then(function (consentState) {
if (consentState == true) {
logDebug("already consented, signing up for remote push");
registerPush();
} else {
logDebug("no consent yet, waiting to sign up for remote push");
Expand Down

0 comments on commit 5fbeac2

Please sign in to comment.