Skip to content

Commit

Permalink
some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pladaria committed Nov 29, 2018
1 parent fb97c33 commit c287873
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
31 changes: 15 additions & 16 deletions src/__tests__/calendar-test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
import {createCalendarEvent} from '../calendar';
import {
createFakeAndroidPostMessage,
removeFakeAndroidPostMessage,
} from './fake-post-message';

test('set a calendar event', async cb => {
expect.assertions(4);

const t1 = 1000;
const t2 = 2000;

window.tuentiWebView = {
postMessage: jsonMessage => {
const message = JSON.parse(jsonMessage);

expect(message.type).toBe('CREATE_CALENDAR_EVENT');
expect(message.payload.beginTime).toBe(1);
expect(message.payload.endTime).toBe(2);

window.__tuenti_webview_bridge!.postMessage(
JSON.stringify({
type: 'CREATE_CALENDAR_EVENT',
id: message.id,
}),
);
createFakeAndroidPostMessage({
checkMessage: msg => {
expect(msg.type).toBe('CREATE_CALENDAR_EVENT');
expect(msg.payload.beginTime).toBe(1);
expect(msg.payload.endTime).toBe(2);
},
};
getResponse: msg => ({
type: 'CREATE_CALENDAR_EVENT',
id: msg.id,
}),
});

createCalendarEvent({
beginTime: t1,
endTime: t2,
title: 'some title',
}).then(res => {
expect(res).toBeUndefined();
delete window.tuentiWebView;
removeFakeAndroidPostMessage();
cb();
});
});
6 changes: 4 additions & 2 deletions src/__tests__/contacts-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const ANY_CONTACT = {
},
};

afterEach(() => {
removeFakeAndroidPostMessage();
});

test('request contact', async cb => {
createFakeAndroidPostMessage({
checkMessage: message => {
Expand All @@ -30,7 +34,6 @@ test('request contact', async cb => {

requestContact().then(res => {
expect(res).toEqual(ANY_CONTACT);
removeFakeAndroidPostMessage();
cb();
});
});
Expand All @@ -54,7 +57,6 @@ test('request contact filtered', async cb => {
filter: 'email',
}).then(res => {
expect(res).toEqual(ANY_CONTACT);
removeFakeAndroidPostMessage();
cb();
});
});
10 changes: 4 additions & 6 deletions src/__tests__/device-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {

const ANY_STRING = 'any-string';

afterEach(() => {
removeFakeAndroidPostMessage();
});

test('request sim icc', async cb => {
createFakeAndroidPostMessage({
checkMessage: message => {
Expand All @@ -21,7 +25,6 @@ test('request sim icc', async cb => {

requestSimIcc().then(res => {
expect(res).toEqual(ANY_STRING);
removeFakeAndroidPostMessage();
cb();
});
});
Expand All @@ -41,7 +44,6 @@ test('request sim imsi', async cb => {

requestSimImsi().then(res => {
expect(res).toEqual(ANY_STRING);
removeFakeAndroidPostMessage();
cb();
});
});
Expand All @@ -61,7 +63,6 @@ test('request device imei', async cb => {

requestDeviceImei().then(res => {
expect(res).toEqual(ANY_STRING);
removeFakeAndroidPostMessage();
cb();
});
});
Expand All @@ -77,7 +78,6 @@ test('request sim icc (failed)', async cb => {

requestSimIcc().then(res => {
expect(res).toBeNull();
removeFakeAndroidPostMessage();
cb();
});
});
Expand All @@ -93,7 +93,6 @@ test('request sim imsi (failed)', async cb => {

requestSimImsi().then(res => {
expect(res).toBeNull();
removeFakeAndroidPostMessage();
cb();
});
});
Expand All @@ -109,7 +108,6 @@ test('request device imei (failed)', async cb => {

requestDeviceImei().then(res => {
expect(res).toBeNull();
removeFakeAndroidPostMessage();
cb();
});
});
7 changes: 4 additions & 3 deletions src/__tests__/utils-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {

const ANY_STRING = 'any-string';

afterEach(() => {
removeFakeAndroidPostMessage();
});

test('attach to email', async cb => {
const PARAMS = {
url: 'any-url',
Expand All @@ -28,7 +32,6 @@ test('attach to email', async cb => {

attachToEmail(PARAMS).then(res => {
expect(res).toBeUndefined();
removeFakeAndroidPostMessage();
cb();
});
});
Expand All @@ -47,7 +50,6 @@ test('set webview title', async cb => {

setWebViewTitle(ANY_STRING).then(res => {
expect(res).toBeUndefined();
removeFakeAndroidPostMessage();
cb();
});
});
Expand Down Expand Up @@ -76,7 +78,6 @@ test('notify page loaded', async cb => {

notifyPageLoaded().then(res => {
expect(res).toBeUndefined();
removeFakeAndroidPostMessage();
cb();
});
});

0 comments on commit c287873

Please sign in to comment.