Skip to content

Commit cb1b527

Browse files
committed
Updating various mocks
Updated the Ionic Native Core The following plugins we updated: • Background-Geolocation • Barcode Scanner
1 parent 6a8153e commit cb1b527

File tree

13 files changed

+6383
-4887
lines changed

13 files changed

+6383
-4887
lines changed

package-lock.json

Lines changed: 6243 additions & 4791 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
{
22
"name": "ionic-native-mocks",
3-
"version": "2.0.11",
4-
"description":
5-
"Mocks for Ionic Native for Cordova and Ionic with TypeScript, ES6+, Promise and Observable support",
6-
"author":
7-
"Chris Griffith <chris.griffith@gmail.com> (https://aj-software.com)",
3+
"version": "2.0.12",
4+
"description": "Mocks for Ionic Native for Cordova and Ionic with TypeScript, ES6+, Promise and Observable support",
5+
"author": "Chris Griffith <chris.griffith@gmail.com> (https://aj-software.com)",
86
"homepage": "https://github.com/chrisgriffith/ionic-native-mocks#readme",
97
"license": "MIT",
108
"devDependencies": {
11-
"@angular/compiler": "5.2.9",
12-
"@angular/compiler-cli": "5.2.9",
13-
"@angular/core": "5.2.9",
9+
"@angular/compiler": "4.4.4",
10+
"@angular/compiler-cli": "4.4.4",
11+
"@angular/core": "4.4.4",
1412
"@ionic-native/action-sheet": "^4.9.1",
1513
"@ionic-native/admob-free": "^4.9.1",
1614
"@ionic-native/admob-pro": "^4.9.1",
@@ -192,47 +190,45 @@
192190
"@ionic-native/zeroconf": "^4.9.1",
193191
"@ionic-native/zip": "^4.9.1",
194192
"@types/cordova": "0.0.34",
195-
"@types/jasmine": "^2.8.6",
196-
"@types/node": "^9.4.7",
193+
"@types/jasmine": "^2.8.8",
194+
"@types/node": "^8.10.20",
197195
"canonical-path": "0.0.2",
198196
"child-process-promise": "2.2.1",
199-
"conventional-changelog-cli": "1.3.1",
200-
"cpr": "2.0.2",
197+
"conventional-changelog-cli": "1.3.4",
198+
"cpr": "2.0.0",
201199
"cz-conventional-changelog": "2.0.0",
202-
"decamelize": "1.2.0",
203-
"dgeni": "0.4.7",
204-
"dgeni-packages": "0.16.10",
200+
"dgeni": "^0.4.9",
201+
"dgeni-packages": "^0.26.2",
205202
"fs-extra": "2.0.0",
206203
"fs-extra-promise": "0.4.1",
207204
"gulp": "3.9.1",
208205
"gulp-rename": "1.2.2",
209206
"gulp-replace": "0.5.4",
210207
"gulp-tslint": "6.1.2",
211208
"jasmine-core": "^2.99.1",
212-
"karma": "^1.7.1",
209+
"karma": "^1.7.0",
213210
"karma-cli": "^1.0.1",
214-
"karma-jasmine": "^1.1.1",
211+
"karma-jasmine": "^1.1.2",
215212
"karma-phantomjs-launcher": "^1.0.4",
216213
"karma-typescript": "^3.0.12",
217214
"karma-typescript-es6-transform": "^1.0.4",
218-
"lodash": "4.17.4",
215+
"lodash": "^4.17.10",
219216
"minimist": "1.2.0",
220217
"node-html-encoder": "0.0.2",
221218
"q": "1.5.0",
222219
"queue": "4.2.1",
223220
"rimraf": "2.6.1",
224-
"rxjs": "^5.5.7",
221+
"rxjs": "^5.5.11",
225222
"semver": "5.3.0",
226-
"tslint": "^5.9.1",
227-
"tslint-ionic-rules": "0.0.14",
228-
"typescript": "~2.6.2",
229-
"zone.js": "^0.8.20"
223+
"tslint": "3.15.1",
224+
"tslint-ionic-rules": "0.0.8",
225+
"typescript": "~2.4.2",
226+
"zone.js": "^0.8.26"
230227
},
231228
"scripts": {
232229
"start": "npm run test:watch",
233230
"lint": "gulp lint",
234-
"build":
235-
"npm run clean && npm run lint && npm run build:core && npm run build:modules",
231+
"build": "npm run clean && npm run lint && npm run build:core && npm run build:modules",
236232
"build:core": "ngc -p scripts/build/tsconfig-core.json",
237233
"build:modules": "node scripts/build/build.js",
238234
"clean": "rimraf dist .tmp",

src/@ionic-native-mocks/core/decorators.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { _throw } from 'rxjs/observable/throw';
2+
13
import { Observable } from 'rxjs/Observable';
24

35
import {
@@ -158,7 +160,7 @@ export function CordovaCheck(opts: CordovaCheckOptions = {}) {
158160
if (opts.sync) {
159161
return null;
160162
} else if (opts.observable) {
161-
return Observable.throw(new Error(check && check.error));
163+
return _throw(new Error(check && check.error));
162164
}
163165
return Promise.reject(check && check.error);
164166
}

src/@ionic-native-mocks/core/plugin.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Observable } from 'rxjs/Observable';
2+
import { fromEvent } from 'rxjs/observable/fromEvent';
23

34
import { checkReady } from './bootstrap';
45
import { CordovaOptions } from './decorators';
@@ -233,7 +234,7 @@ function wrapObservable(
233234
args: any[],
234235
opts: any = {}
235236
) {
236-
return new Observable((observer: any) => {
237+
return new Observable(observer => {
237238
let pluginResult;
238239

239240
if (opts.destruct) {
@@ -316,7 +317,7 @@ export function wrapEventObservable(
316317
event: string,
317318
element: any = window
318319
): Observable<any> {
319-
return Observable.fromEvent(element, event);
320+
return fromEvent(element, event);
320321
}
321322

322323
/**
@@ -333,7 +334,7 @@ export function overrideFunction(
333334
args: any[],
334335
opts: any = {}
335336
): Observable<any> {
336-
return new Observable((observer: any) => {
337+
return new Observable(observer => {
337338
const availabilityCheck = checkAvailability(
338339
pluginObj,
339340
null,
@@ -387,7 +388,7 @@ export function wrapInstance(
387388
if (opts.sync) {
388389
return callInstance(pluginObj, methodName, args, opts);
389390
} else if (opts.observable) {
390-
return new Observable((observer: any) => {
391+
return new Observable(observer => {
391392
let pluginResult;
392393

393394
if (opts.destruct) {

src/@ionic-native-mocks/core/util.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,22 @@ export const pluginWarn = (
5353
): void => {
5454
if (method) {
5555
console.warn(
56-
`'Native: tried calling ${pluginName}, but the ${pluginName} ' plugin is not installed.`
56+
'Native: tried calling ' +
57+
pluginName +
58+
'.' +
59+
method +
60+
', but the ' +
61+
pluginName +
62+
' plugin is not installed.'
5763
);
5864
} else {
5965
console.warn(
60-
`Native: tried accessing the ${pluginName} plugin but it's not installed.`
66+
`'Native: tried accessing the ${pluginName} plugin but it's not installed.`
6167
);
6268
}
6369
if (plugin) {
6470
console.warn(
65-
`Install the ${pluginName} plugin: 'ionic cordova plugin add ${plugin}'`
71+
`Install the ${pluginName} plugin: 'ionic cordova plugin add ${plugin}'`
6672
);
6773
}
6874
};
@@ -75,11 +81,17 @@ export const pluginWarn = (
7581
export const cordovaWarn = (pluginName: string, method?: string): void => {
7682
if (method) {
7783
console.warn(
78-
`Native: tried calling ${pluginName}.${method}, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator`
84+
'Native: tried calling ' +
85+
pluginName +
86+
'.' +
87+
method +
88+
', but Cordova is not available. Make sure to include cordova.js or run in a device/simulator'
7989
);
8090
} else {
8191
console.warn(
82-
`'Native: tried accessing the ${pluginName} plugin but Cordova is not available. Make sure to include cordova.js or run in a device/simulator`
92+
'Native: tried accessing the ' +
93+
pluginName +
94+
' plugin but Cordova is not available. Make sure to include cordova.js or run in a device/simulator'
8395
);
8496
}
8597
};

src/@ionic-native-mocks/plugins/background-geolocation/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,11 @@ export class BackgroundGeolocatioMock extends BackgroundGeolocation {
403403
* In case or error (SettingNotFoundException) fail callback will be executed.
404404
* @returns {Promise<boolean>}
405405
*/
406-
watchLocationMode(): Promise<boolean> {
407-
return new Promise((resolve, reject) => {
408-
resolve();
406+
watchLocationMode(): Observable<number> {
407+
return Observable.create((observer: Observer<any>) => {
408+
let response: number;
409+
observer.next( response );
410+
observer.complete();
409411
});
410412
};
411413
/**

src/@ionic-native-mocks/plugins/barcode-scanner/index.ts

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,37 +44,42 @@ export interface BarcodeScannerOptions {
4444
}
4545

4646
export interface BarcodeScanResult {
47-
format: 'QR_CODE' | 'DATA_MATRIX' | 'UPC_E' | 'UPC_A' | 'EAN_8' | 'EAN_13' | 'CODE_128' | 'CODE_39' | 'CODE_93' | 'CODABAR' | 'ITF' | 'RSS14' | 'RSS_EXPANDED' | 'PDF417' | 'AZTEC' | 'MSI';
47+
format: 'QR_CODE' | 'DATA_MATRIX' | 'UPC_E' | 'UPC_A' | 'EAN_8' | 'EAN_13' | 'CODE_128' | 'CODE_39' | 'CODE_93' | 'CODABAR' | 'ITF' | 'RSS14' | 'RSS_EXPANDED' | 'PDF_417' | 'AZTEC' | 'MSI';
4848
cancelled: boolean;
4949
text: string;
5050
}
5151

5252
export class BarcodeScannerMock extends BarcodeScanner {
53-
index: number = 0;
54-
/**
55-
* Open the barcode scanner.
56-
* @param options {BarcodeScannerOptions} Optional options to pass to the scanner
57-
* @returns {Promise<any>} Returns a Promise that resolves with scanner data, or rejects with an error.
58-
*/
59-
scan(options?: BarcodeScannerOptions): Promise<BarcodeScanResult> {
60-
let theResult: BarcodeScanResult = {format: 'QR_CODE', cancelled: false, text: 'RESPONSE' };
53+
Encode: {
54+
TEXT_TYPE: string;
55+
EMAIL_TYPE: string;
56+
PHONE_TYPE: string;
57+
SMS_TYPE: string;
58+
};
6159

62-
return new Promise((resolve, reject) => {
63-
resolve(theResult);
64-
});
65-
}
66-
/**
67-
* Encodes data into a barcode.
68-
* NOTE: not well supported on Android
69-
* @param type {string} Type of encoding
70-
* @param data {any} Data to encode
71-
* @returns {Promise<any>}
72-
*/
73-
encode(type: string, data: any): Promise<any> {
74-
return new Promise((resolve, reject) => {
75-
resolve();
76-
});
77-
}
78-
}
60+
/**
61+
* Open the barcode scanner.
62+
* @param {BarcodeScannerOptions} [options] Optional options to pass to the scanner
63+
* @returns {Promise<any>} Returns a Promise that resolves with scanner data, or rejects with an error.
64+
*/
65+
scan(options?: BarcodeScannerOptions): Promise<BarcodeScanResult> {
66+
let theResult: BarcodeScanResult = { format: 'QR_CODE', cancelled: false, text: 'RESPONSE' };
7967

68+
return new Promise((resolve, reject) => {
69+
resolve(theResult);
70+
});
71+
}
8072

73+
/**
74+
* Encodes data into a barcode.
75+
* NOTE: not well supported on Android
76+
* @param {string} type Type of encoding
77+
* @param {any} data Data to encode
78+
* @returns {Promise<any>}
79+
*/
80+
encode(type: string, data: any): Promise<any> {
81+
return new Promise((resolve, reject) => {
82+
resolve();
83+
});
84+
}
85+
}
Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
11
import { FirebaseDynamicLinks } from '@ionic-native/firebase-dynamic-links';
2+
import { Observable } from 'rxjs/Observable';
3+
import { Observer } from 'rxjs/Observer';
24

3-
export interface DynamicLinksOptions {
4-
title: string;
5-
message: string;
6-
deepLink?: string;
7-
callToActionText?: string;
5+
export interface IDynamicLink {
6+
matchType: 'Weak' | 'Strong';
7+
deepLink: string;
88
}
99

1010
export class FirebaseDynamicLinksMocks extends FirebaseDynamicLinks {
11-
/**
11+
/**
1212
* Registers callback that is triggered on each dynamic link click.
13-
* @return {Promise<any>} Returns a promise
13+
* @return {Observable<IDynamicLink>} Returns an observable
1414
*/
15-
onDynamicLink(): Promise<any> {
16-
return new Promise((resolve, reject) => {
17-
resolve();
18-
});
19-
};
20-
/**
21-
* Display invitation dialog.
22-
* @param options {DynamicLinksOptions} Some param to configure something
23-
* @return {Promise<any>} Returns a promise
24-
*/
25-
sendInvitation(options: DynamicLinksOptions): Promise<any> {
26-
return new Promise((resolve, reject) => {
27-
resolve();
15+
onDynamicLink(): Observable<IDynamicLink> {
16+
return Observable.create((observer: Observer<any>) => {
17+
let response: IDynamicLink;
18+
observer.next( response );
19+
observer.complete();
2820
});
2921
};
3022
}

src/@ionic-native-mocks/plugins/health/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ export class HealthMock extends Health {
228228
* @param queryOptions {HealthQueryOptions}
229229
* @return {Promise<HealthData>}
230230
*/
231-
query(queryOptions: HealthQueryOptions): Promise<HealthData> {
232-
let response: HealthData;
231+
query(queryOptions: HealthQueryOptions): Promise<HealthData[]> {
232+
let response: HealthData[];
233233
return new Promise((resolve, reject) => {
234234
resolve(response);
235235
});

src/@ionic-native-mocks/plugins/native-geocoder/index.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ export class NativeGeocoderMock extends NativeGeocoder {
77
* @param longitude {number} The longitude
88
* @return {Promise<any>}
99
*/
10-
reverseGeocode(latitude: number, longitude: number): Promise<NativeGeocoderReverseResult> {
11-
let response: NativeGeocoderReverseResult;
10+
reverseGeocode(latitude: number, longitude: number, options?: NativeGeocoderOptions): Promise<NativeGeocoderReverseResult[]> {
11+
let response: NativeGeocoderReverseResult[];
1212
return new Promise((resolve, reject) => {
1313
resolve(response);
1414
});
@@ -18,8 +18,8 @@ export class NativeGeocoderMock extends NativeGeocoder {
1818
* @param addressString {string} The address to be geocoded
1919
* @return {Promise<any>}
2020
*/
21-
forwardGeocode(addressString: string): Promise<NativeGeocoderForwardResult> {
22-
let response: NativeGeocoderForwardResult;
21+
orwardGeocode(addressString: string, options?: NativeGeocoderOptions): Promise<NativeGeocoderForwardResult[]> {
22+
let response: NativeGeocoderForwardResult[];
2323
return new Promise((resolve, reject) => {
2424
resolve(response);
2525
});
@@ -79,3 +79,22 @@ export interface NativeGeocoderForwardResult {
7979
*/
8080
longitude: string;
8181
}
82+
83+
export interface NativeGeocoderOptions {
84+
/**
85+
* The locale to use when returning the address information.
86+
* If set to 'false' the locale will always be 'en_US'.
87+
* Default is 'true'
88+
*/
89+
useLocale: boolean;
90+
/**
91+
* The default locale to use when returning the address information.
92+
* e.g.: 'fa-IR' or 'de_DE'.
93+
*/
94+
defaultLocale?: string;
95+
/**
96+
* The maximum number of result to return (max is 5).
97+
* Default is 1
98+
*/
99+
maxResults: number;
100+
}

0 commit comments

Comments
 (0)