-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from tef-novum/pladaria
complete test coverage
- Loading branch information
Showing
13 changed files
with
567 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import {requestContact} from '../contacts'; | ||
import { | ||
createFakeAndroidPostMessage, | ||
removeFakeAndroidPostMessage, | ||
} from './fake-post-message'; | ||
|
||
const ANY_CONTACT = { | ||
name: 'Homer J. Simpson', | ||
email: 'chunkylover53@aol.com', | ||
phoneNumber: '(939)-555-0113', | ||
address: { | ||
street: '742 Evergreen Terrace', | ||
city: 'Springfield', | ||
country: 'USA', | ||
postalCode: '49007', | ||
}, | ||
}; | ||
|
||
test('request contact', async cb => { | ||
createFakeAndroidPostMessage({ | ||
checkMessage: message => { | ||
expect(message.type).toBe('GET_CONTACT_DATA'); | ||
}, | ||
getResponse: message => ({ | ||
type: message.type, | ||
id: message.id, | ||
payload: ANY_CONTACT, | ||
}), | ||
}); | ||
|
||
requestContact().then(res => { | ||
expect(res).toEqual(ANY_CONTACT); | ||
removeFakeAndroidPostMessage(); | ||
cb(); | ||
}); | ||
}); | ||
|
||
test('request contact filtered', async cb => { | ||
createFakeAndroidPostMessage({ | ||
checkMessage: message => { | ||
expect(message.type).toBe('GET_CONTACT_DATA'); | ||
expect(message.payload).toEqual({ | ||
filter: 'email', | ||
}); | ||
}, | ||
getResponse: message => ({ | ||
type: message.type, | ||
id: message.id, | ||
payload: ANY_CONTACT, | ||
}), | ||
}); | ||
|
||
requestContact({ | ||
filter: 'email', | ||
}).then(res => { | ||
expect(res).toEqual(ANY_CONTACT); | ||
removeFakeAndroidPostMessage(); | ||
cb(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import {requestSimIcc, requestSimImsi, requestDeviceImei} from '../device'; | ||
import { | ||
createFakeAndroidPostMessage, | ||
removeFakeAndroidPostMessage, | ||
} from './fake-post-message'; | ||
|
||
const ANY_STRING = 'any-string'; | ||
|
||
test('request sim icc', async cb => { | ||
createFakeAndroidPostMessage({ | ||
checkMessage: message => { | ||
expect(message.type).toBe('SIM_ICC'); | ||
expect(message.payload).toBeUndefined(); | ||
}, | ||
getResponse: message => ({ | ||
type: message.type, | ||
id: message.id, | ||
payload: {icc: ANY_STRING}, | ||
}), | ||
}); | ||
|
||
requestSimIcc().then(res => { | ||
expect(res).toEqual(ANY_STRING); | ||
removeFakeAndroidPostMessage(); | ||
cb(); | ||
}); | ||
}); | ||
|
||
test('request sim imsi', async cb => { | ||
createFakeAndroidPostMessage({ | ||
checkMessage: message => { | ||
expect(message.type).toBe('IMSI'); | ||
expect(message.payload).toBeUndefined(); | ||
}, | ||
getResponse: message => ({ | ||
type: message.type, | ||
id: message.id, | ||
payload: {imsi: ANY_STRING}, | ||
}), | ||
}); | ||
|
||
requestSimImsi().then(res => { | ||
expect(res).toEqual(ANY_STRING); | ||
removeFakeAndroidPostMessage(); | ||
cb(); | ||
}); | ||
}); | ||
|
||
test('request device imei', async cb => { | ||
createFakeAndroidPostMessage({ | ||
checkMessage: message => { | ||
expect(message.type).toBe('IMEI'); | ||
expect(message.payload).toBeUndefined(); | ||
}, | ||
getResponse: message => ({ | ||
type: message.type, | ||
id: message.id, | ||
payload: {imei: ANY_STRING}, | ||
}), | ||
}); | ||
|
||
requestDeviceImei().then(res => { | ||
expect(res).toEqual(ANY_STRING); | ||
removeFakeAndroidPostMessage(); | ||
cb(); | ||
}); | ||
}); | ||
|
||
test('request sim icc (failed)', async cb => { | ||
createFakeAndroidPostMessage({ | ||
checkMessage: message => { | ||
expect(message.type).toBe('SIM_ICC'); | ||
expect(message.payload).toBeUndefined(); | ||
}, | ||
getResponse: () => ({type: 'other', id: ''}), | ||
}); | ||
|
||
requestSimIcc().then(res => { | ||
expect(res).toBeNull(); | ||
removeFakeAndroidPostMessage(); | ||
cb(); | ||
}); | ||
}); | ||
|
||
test('request sim imsi (failed)', async cb => { | ||
createFakeAndroidPostMessage({ | ||
checkMessage: message => { | ||
expect(message.type).toBe('IMSI'); | ||
expect(message.payload).toBeUndefined(); | ||
}, | ||
getResponse: () => ({type: 'other', id: ''}), | ||
}); | ||
|
||
requestSimImsi().then(res => { | ||
expect(res).toBeNull(); | ||
removeFakeAndroidPostMessage(); | ||
cb(); | ||
}); | ||
}); | ||
|
||
test('request device imei (failed)', async cb => { | ||
createFakeAndroidPostMessage({ | ||
checkMessage: message => { | ||
expect(message.type).toBe('IMEI'); | ||
expect(message.payload).toBeUndefined(); | ||
}, | ||
getResponse: () => ({type: 'other', id: ''}), | ||
}); | ||
|
||
requestDeviceImei().then(res => { | ||
expect(res).toBeNull(); | ||
removeFakeAndroidPostMessage(); | ||
cb(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import {nativeAlert, nativeConfirm, nativeMessage} from '../dialogs'; | ||
import { | ||
createFakeAndroidPostMessage, | ||
removeFakeAndroidPostMessage, | ||
} from './fake-post-message'; | ||
|
||
const ANY_TITLE = 'any-title'; | ||
const ANY_MESSAGE = 'any-message'; | ||
const ANY_BUTTON_TEXT = 'any-button-text'; | ||
const ANY_ACCEPT_TEXT = 'any-accept-text'; | ||
const ANY_CANCEL_TEXT = 'any-cancel-text'; | ||
const ANY_DURATION = 5000; | ||
|
||
afterEach(() => { | ||
removeFakeAndroidPostMessage(); | ||
}); | ||
|
||
test('native alert', async cb => { | ||
createFakeAndroidPostMessage({ | ||
checkMessage: message => { | ||
expect(message.type).toBe('ALERT'); | ||
expect(message.payload!).toEqual({ | ||
title: ANY_TITLE, | ||
message: ANY_MESSAGE, | ||
buttonText: ANY_BUTTON_TEXT, | ||
}); | ||
}, | ||
getResponse: message => ({ | ||
type: message.type, | ||
id: message.id, | ||
}), | ||
}); | ||
|
||
nativeAlert({ | ||
title: ANY_TITLE, | ||
message: ANY_MESSAGE, | ||
buttonText: ANY_BUTTON_TEXT, | ||
}).then(res => { | ||
expect(res).toBeUndefined(); | ||
cb(); | ||
}); | ||
}); | ||
|
||
test('native confirm', async cb => { | ||
createFakeAndroidPostMessage({ | ||
checkMessage: message => { | ||
expect(message.type).toBe('CONFIRM'); | ||
expect(message.payload).toEqual({ | ||
message: ANY_MESSAGE, | ||
title: ANY_TITLE, | ||
acceptText: ANY_ACCEPT_TEXT, | ||
cancelText: ANY_CANCEL_TEXT, | ||
}); | ||
}, | ||
getResponse: message => ({ | ||
type: message.type, | ||
id: message.id, | ||
payload: {result: true}, | ||
}), | ||
}); | ||
|
||
nativeConfirm({ | ||
title: ANY_TITLE, | ||
message: ANY_MESSAGE, | ||
acceptText: ANY_ACCEPT_TEXT, | ||
cancelText: ANY_CANCEL_TEXT, | ||
}).then(res => { | ||
expect(res).toBe(true); | ||
cb(); | ||
}); | ||
}); | ||
|
||
test('native message', async cb => { | ||
createFakeAndroidPostMessage({ | ||
checkMessage: message => { | ||
expect(message.type).toBe('MESSAGE'); | ||
expect(message.payload).toEqual({ | ||
message: ANY_MESSAGE, | ||
duration: ANY_DURATION, | ||
buttonText: ANY_BUTTON_TEXT, | ||
}); | ||
}, | ||
getResponse: message => ({ | ||
type: message.type, | ||
id: message.id, | ||
}), | ||
}); | ||
|
||
nativeMessage({ | ||
message: ANY_MESSAGE, | ||
duration: ANY_DURATION, | ||
buttonText: ANY_BUTTON_TEXT, | ||
}).then(res => { | ||
expect(res).toBeUndefined(); | ||
cb(); | ||
}); | ||
}); | ||
|
||
test('native alert fallbacks to browser alert', async cb => { | ||
const alert = jest.fn(); | ||
window.alert = alert; | ||
|
||
nativeAlert({ | ||
message: ANY_MESSAGE, | ||
}).then(res => { | ||
expect(res).toBeUndefined(); | ||
expect(alert.mock.calls.length).toBe(1); | ||
expect(alert.mock.calls[0][0]).toBe(ANY_MESSAGE); | ||
cb(); | ||
}); | ||
|
||
delete window.alert; | ||
}); | ||
|
||
test('native confirm fallbacks to browser confirm', async cb => { | ||
const confirm = jest.fn().mockReturnValue(true); | ||
|
||
window.confirm = confirm; | ||
|
||
nativeConfirm({ | ||
message: ANY_MESSAGE, | ||
}).then(res => { | ||
expect(res).toBe(true); | ||
expect(confirm.mock.calls.length).toBe(1); | ||
expect(confirm.mock.calls[0][0]).toBe(ANY_MESSAGE); | ||
cb(); | ||
}); | ||
|
||
delete window.confirm; | ||
}); | ||
|
||
test('native message fallbacks to browser alert', async cb => { | ||
const alert = jest.fn(); | ||
window.alert = alert; | ||
|
||
nativeMessage({ | ||
message: ANY_MESSAGE, | ||
}).then(res => { | ||
expect(res).toBeUndefined(); | ||
expect(alert.mock.calls.length).toBe(1); | ||
expect(alert.mock.calls[0][0]).toBe(ANY_MESSAGE); | ||
cb(); | ||
}); | ||
|
||
delete window.alert; | ||
}); |
Oops, something went wrong.