From ac138957a5d1c7b40c20614d12dc9c1f97a90b9a Mon Sep 17 00:00:00 2001 From: Chris Griffith Date: Thu, 6 Jul 2017 19:52:29 -0700 Subject: [PATCH] More Mocks admob admob-free app-preferences app-rate app-version background-geolocation badge base64 base64-to-gallery battery-status file gyroscope in-app-browser local-notifications phonegap-local-notification push screen-orientation secure-storage --- CHANGELOG.md | 31 + package.json | 2 +- .../plugins/admob-free/index.ts | 229 +++++ .../plugins/admob/index.ts | 209 +++++ .../plugins/app-preferences/index.ts | 100 ++ .../plugins/app-rate/index.ts | 92 ++ .../plugins/app-version/index.ts | 40 + .../plugins/background-geolocation/index.ts | 500 ++++++++++ .../plugins/badge/index.ts | 70 ++ .../plugins/base64-to-gallery/index.ts | 15 + .../plugins/base64/index.ts | 14 + .../plugins/battery-status/index.ts | 50 + src/@ionic-native-mocks/plugins/file/index.ts | 876 ++++++++++++++++++ .../plugins/gyroscope/index.ts | 59 ++ .../plugins/in-app-browser/index.ts | 143 +++ .../plugins/local-notifications/index.ts | 284 ++++++ .../phonegap-local-notification/index.ts | 46 + src/@ionic-native-mocks/plugins/push/index.ts | 188 ++++ .../plugins/screen-orientation/index.ts | 46 + .../plugins/secure-storage/index.ts | 78 ++ 20 files changed, 3071 insertions(+), 1 deletion(-) create mode 100644 CHANGELOG.md create mode 100644 src/@ionic-native-mocks/plugins/admob-free/index.ts create mode 100644 src/@ionic-native-mocks/plugins/admob/index.ts create mode 100644 src/@ionic-native-mocks/plugins/app-preferences/index.ts create mode 100644 src/@ionic-native-mocks/plugins/app-rate/index.ts create mode 100644 src/@ionic-native-mocks/plugins/app-version/index.ts create mode 100644 src/@ionic-native-mocks/plugins/background-geolocation/index.ts create mode 100644 src/@ionic-native-mocks/plugins/badge/index.ts create mode 100644 src/@ionic-native-mocks/plugins/base64-to-gallery/index.ts create mode 100644 src/@ionic-native-mocks/plugins/base64/index.ts create mode 100644 src/@ionic-native-mocks/plugins/battery-status/index.ts create mode 100644 src/@ionic-native-mocks/plugins/file/index.ts create mode 100644 src/@ionic-native-mocks/plugins/gyroscope/index.ts create mode 100644 src/@ionic-native-mocks/plugins/in-app-browser/index.ts create mode 100644 src/@ionic-native-mocks/plugins/local-notifications/index.ts create mode 100644 src/@ionic-native-mocks/plugins/phonegap-local-notification/index.ts create mode 100644 src/@ionic-native-mocks/plugins/push/index.ts create mode 100644 src/@ionic-native-mocks/plugins/screen-orientation/index.ts create mode 100644 src/@ionic-native-mocks/plugins/secure-storage/index.ts diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..eabf93c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,31 @@ + +## [1.0.2](https://github.com/chrisgriffith/ionic-native-mocks) (2017-07-05) + +### Features +Inital Release +- actions-sheets +- barcode-scanner +- ble +- bluetooth-serial +- calendar +- camera +- contacts +- date-picker +- db-meter +- device-motion +- device-orientation +- device +- dialog +- email-composer +- geolocation +- globalization +- image-picker +- keyboard +- network +- social-sharing +- splash-screen +- sqlite +- status-bar +- toast +- touch-id +- vibration \ No newline at end of file diff --git a/package.json b/package.json index cc3e604..9d36bfe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ionic-native-mocks", - "version": "1.0.2", + "version": "1.0.3", "description": "Mocks for Ionic Native for Cordova and Ionic with TypeScript, ES6+, Promise and Observable support", "homepage": "https://ionicframework.com/", "author": "Chris Griffith (https://aj-sofwtare.com)", diff --git a/src/@ionic-native-mocks/plugins/admob-free/index.ts b/src/@ionic-native-mocks/plugins/admob-free/index.ts new file mode 100644 index 0000000..5a6f1ff --- /dev/null +++ b/src/@ionic-native-mocks/plugins/admob-free/index.ts @@ -0,0 +1,229 @@ +import { AdMobFree } from '@ionic-native/admob-free'; +import { Observable } from 'rxjs/Observable'; +import { Observer } from 'rxjs/Observer'; +import 'rxjs/add/observable/fromEvent'; + +export interface AdMobFreeBannerConfig { + /** + * Ad Unit ID + */ + id?: string; + /** + * Receiving test ad + */ + isTesting?: boolean; + /** + * Auto show ad when loaded + */ + autoShow?: boolean; + /** + * Set to true, to put banner at top + */ + bannerAtTop?: boolean; + /** + * Set to true, to allow banner overlap WebView + */ + overlap?: boolean; + /** + * Set to true to avoid ios7 status bar overlap + */ + offsetTopBar?: boolean; + /** + * Banner size + */ + size?: string; +} +export interface AdMobFreeInterstitialConfig { + /** + * Ad Unit ID + */ + id?: string; + /** + * Receiving test ad + */ + isTesting?: boolean; + /** + * Auto show ad when loaded + */ + autoShow?: boolean; +} +export interface AdMobFreeRewardVideoConfig { + /** + * Ad Unit ID + */ + id?: string; + /** + * Receiving test ad + */ + isTesting?: boolean; + /** + * Auto show ad when loaded + */ + autoShow?: boolean; +} + +export class AdMobFreeMock extends AdMobFree { + /** + * Convenience object to get event names + * @type {Object} + */ + events: any; + /** + * Watch an event + * @param event {string} event name + * @return {Observable} + */ + on(event: string): Observable { + return Observable.create((observer: Observer) => { + observer.next(''); + observer.complete(); + }); + }; + /** + * Returns the AdMobFreeBanner object + * @type {AdMobFreeBanner} + */ + banner: AdMobFreeBanner; + /** + * Returns the AdMobFreeInterstitial object + * @type {AdMobFreeInterstitial} + */ + interstitial: AdMobFreeInterstitial; + /** + * Returns the AdMobFreeRewardVideo object + * @type {AdMobFreeRewardVideo} + */ + rewardVideo: AdMobFreeRewardVideo; +} +/** + * @hidden + */ +export class AdMobFreeBanner { + /** + * Update config. + * @param options + * @return {AdMobFreeBannerConfig} + */ + config(options: AdMobFreeBannerConfig): AdMobFreeBannerConfig { + let config: AdMobFreeBannerConfig; + return config; + }; + /** + * Hide the banner. + * @return {Promise} + */ + hide(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Create banner. + * @return {Promise} + */ + prepare(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Remove the banner. + * @return {Promise} + */ + remove(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Show the banner. + * @return {Promise} + */ + show(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; +} +/** + * @hidden + */ +export class AdMobFreeInterstitial { + /** + * Update config. + * @param options + * @return {AdMobFreeInterstitialConfig} + */ + config(options: AdMobFreeInterstitialConfig): AdMobFreeInterstitialConfig { + let config: AdMobFreeInterstitialConfig; + return config; + }; + /** + * Check if interstitial is ready + * @return {Promise} + */ + isReady(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Prepare interstitial + * @return {Promise} + */ + prepare(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Show the interstitial + * @return {Promise} + */ + show(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; +} +/** + * @hidden + */ +export class AdMobFreeRewardVideo { + /** + * Update config. + * @param options + * @return {AdMobFreeRewardVideoConfig} + */ + config(options: AdMobFreeRewardVideoConfig): AdMobFreeRewardVideoConfig { + let config: AdMobFreeRewardVideoConfig; + return config; + }; + /** + * Check if reward video is ready + * @return {Promise} + */ + isReady(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Prepare reward video + * @return {Promise} + */ + prepare(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Show the reward video + * @return {Promise} + */ + show(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; +} diff --git a/src/@ionic-native-mocks/plugins/admob/index.ts b/src/@ionic-native-mocks/plugins/admob/index.ts new file mode 100644 index 0000000..53a7d0b --- /dev/null +++ b/src/@ionic-native-mocks/plugins/admob/index.ts @@ -0,0 +1,209 @@ +import { AdMob } from '@ionic-native/admob'; +import { Observable } from 'rxjs/Observable'; +import { Observer } from 'rxjs/Observer'; + +export declare type AdSize = 'SMART_BANNER' | 'BANNER' | 'MEDIUM_RECTANGLE' | 'FULL_BANNER' | 'LEADERBOARD' | 'SKYSCRAPER' | 'CUSTOM'; +export interface AdMobOptions { + /** + * Banner ad ID + */ + adId?: string; + /** + * Banner Ad Size, defaults to `SMART_BANNER`. IT can be: `SMART_BANNER`, `BANNER`, `MEDIUM_RECTANGLE`, `FULL_BANNER`, `LEADERBOARD`, `SKYSCRAPER`, or `CUSTOM` + */ + adSize?: AdSize; + /** + * Banner width, valid when `adSize` is set to `CUSTOM` + */ + width?: number; + /** + * Banner height, valid when `adSize` is set to `CUSTOM` + */ + height?: number; + /** + * Allow banner to overlap webview, or else it will push webview up or down to avoid overlap. Defaults to false. + */ + overlap?: boolean; + /** + * Position of banner ad. Defaults to `TOP_CENTER`. You can use the `AdMob.AD_POSITION` property to select other values. + */ + position?: number; + /** + * X in pixels. Valid when `position` is set to `POS_XY` + */ + x?: number; + /** + * Y in pixels. Valid when `position` is set to `POS_XY` + */ + y?: number; + /** + * Set to true to receive test ad for testing purposes + */ + isTesting?: boolean; + /** + * Auto show interstitial ad when loaded. Set to false if hope to control the show timing with prepareInterstitial/showInterstitial + */ + autoShow?: boolean; + /** + * Re-create the banner on web view orientation change (not screen orientation), or else just move the banner. Default:true. + */ + orientationRenew?: boolean; + /** + * Set extra color style for Ad + */ + adExtras?: AdExtras; + /** + * License key for the plugin + */ + license?: any; +} +export interface AdExtras { + color_bg: string; + color_bg_top: string; + color_border: string; + color_link: string; + color_text: string; + color_url: string; +} + +export class AdMobMock extends AdMob { + AD_POSITION: { + NO_CHANGE: number; + TOP_LEFT: number; + TOP_CENTER: number; + TOP_RIGHT: number; + LEFT: number; + CENTER: number; + RIGHT: number; + BOTTOM_LEFT: number; + BOTTOM_CENTER: number; + BOTTOM_RIGHT: number; + POS_XY: number; + }; + /** + * Create a banner + * @param adIdOrOptions {string | AdMobOptions} Ad ID or Options + * @returns {Promise} Returns a Promise that resolves when the banner is created + */ + createBanner(adIdOrOptions: string | AdMobOptions): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Destroy the banner, remove it from screen. + */ + removeBanner(): void { }; + /** + * Show banner at position + * @param position {number} Position. Use `AdMob.AD_POSITION` to set values. + */ + showBanner(position: number): void { }; + /** + * Show banner at custom position + * @param x {number} Offset from screen left. + * @param y {number} Offset from screen top. + */ + showBannerAtXY(x: number, y: number): void { }; + /** + * Hide the banner, remove it from screen, but can show it later + */ + hideBanner(): void { }; + /** + * Prepare interstitial banner + * @param adIdOrOptions {string | AdMobOptions} Ad ID or Options + * @returns {Promise} Returns a Promise that resolves when interstitial is prepared + */ + prepareInterstitial(adIdOrOptions: string | AdMobOptions): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Show interstitial ad when it's ready + */ + showInterstitial(): void { }; + /** + * Prepare a reward video ad + * @param adIdOrOptions {string | AdMobOptions} Ad ID or Options + * @returns {Promise} Returns a Promise that resolves when the ad is prepared + */ + prepareRewardVideoAd(adIdOrOptions: string | AdMobOptions): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Show a reward video ad + */ + showRewardVideoAd(): void { }; + /** + * Sets the values for configuration and targeting + * @param options {AdMobOptions} Options + * @returns {Promise} Returns a Promise that resolves when the options have been set + */ + setOptions(options: AdMobOptions): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Get user ad settings + * @returns {Promise} Returns a promise that resolves with the ad settings + */ + getAdSettings(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Triggered when failed to receive Ad + * @returns {Observable} + */ + onAdFailLoad(): Observable { + return Observable.create((observer: Observer) => { + observer.next(''); + observer.complete(); + }); + }; + /** + * Triggered when Ad received + * @returns {Observable} + */ + onAdLoaded(): Observable { + return Observable.create((observer: Observer) => { + observer.next(''); + observer.complete(); + }); + }; + /** + * Triggered when Ad will be showed on screen + * @returns {Observable} + */ + onAdPresent(): Observable { + return Observable.create((observer: Observer) => { + observer.next(''); + observer.complete(); + }); + }; + /** + * Triggered when user click the Ad, and will jump out of your App + * @returns {Observable} + */ + onAdLeaveApp(): Observable { + return Observable.create((observer: Observer) => { + observer.next(''); + observer.complete(); + }); + }; + /** + * Triggered when dismiss the Ad and back to your App + * @returns {Observable} + */ + onAdDismiss(): Observable { + return Observable.create((observer: Observer) => { + observer.next(''); + observer.complete(); + }); + }; +} diff --git a/src/@ionic-native-mocks/plugins/app-preferences/index.ts b/src/@ionic-native-mocks/plugins/app-preferences/index.ts new file mode 100644 index 0000000..d9cc5cf --- /dev/null +++ b/src/@ionic-native-mocks/plugins/app-preferences/index.ts @@ -0,0 +1,100 @@ +import { AppPreferences } from '@ionic-native/app-preferences'; +import { Observable } from 'rxjs/Observable'; +import { Observer } from 'rxjs/Observer'; + +export class AppPreferencesMock extends AppPreferences { + /** + * Get a preference value + * + * @param {string} dict Dictionary for key (OPTIONAL) + * @param {string} key Key + * @return {Promise} Returns a promise + */ + fetch(dict: string, key?: string): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Set a preference value + * + * @param {string} dict Dictionary for key (OPTIONAL) + * @param {string} key Key + * @param {any} value Value + * @return {Promise} Returns a promise + */ + store(dict: string, key: string, value?: any): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + } + /** + * Remove value from preferences + * + * @param {string} dict Dictionary for key (OPTIONAL) + * @param {string} key Key + * @return {Promise} Returns a promise + */ + remove(dict: string, key?: string): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Clear preferences + * + * @return {Promise} Returns a promise + */ + clearAll(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Show native preferences interface + * + * @return {Promise} Returns a promise + */ + show(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Show native preferences interface + * + * @param {boolean} subscribe true value to subscribe, false - unsubscribe + * @return {Observable} Returns an observable + */ + watch(subscribe: boolean): Observable { + return Observable.create((observer: Observer) => { + observer.next(''); + observer.complete(); + }); + }; + /** + * Return named configuration context + * In iOS you'll get a suite configuration, on Android — named file + * Supports: Android, iOS + * @param {string} suiteName suite name + * @returns {Object} Custom object, bound to that suite + */ + suite(suiteName: string): any {}; + iosSuite(suiteName: string): any {}; + /** + * Return cloud synchronized configuration context + * Currently supports Windows and iOS/macOS + * @returns {Object} Custom object, bound to that suite + */ + cloudSync(): Object { + return new Object; + }; + /** + * Return default configuration context + * Currently supports Windows and iOS/macOS + * @returns {Object} Custom Object, bound to that suite + */ + defaults(): Object { + return new Object; + }; +} diff --git a/src/@ionic-native-mocks/plugins/app-rate/index.ts b/src/@ionic-native-mocks/plugins/app-rate/index.ts new file mode 100644 index 0000000..26b438a --- /dev/null +++ b/src/@ionic-native-mocks/plugins/app-rate/index.ts @@ -0,0 +1,92 @@ +import { AppRate } from '@ionic-native/app-rate'; +export interface AppRatePreferences { + /** + * Custom BCP 47 language tag + */ + useLanguage?: string; + /** + * Custom application title + */ + displayAppName?: string; + /** + * Show dialog again when application version will be updated. Defaults to `true` + */ + promptAgainForEachNewVersion?: boolean; + /** + * count of runs of application before dialog will be displayed. Defaults to `3` + */ + usesUntilPrompt?: number; + /** + * leave app or no when application page opened in app store (now supported only for iOS). Defaults to `false` + */ + openStoreInApp?: boolean; + /** + * use custom view for rate dialog. Defaults to `false` + */ + useCustomRateDialog?: boolean; + /** + * Custom locale object + */ + customLocale?: any; + /** + * Callbacks for events + */ + callbacks?: AppRateCallbacks; + /** + * App Store URLS + */ + storeAppURL?: AppUrls; +} +export interface AppRateCallbacks { + /** + * call back function. called when user clicked on rate-dialog buttons + */ + onButtonClicked?: Function; + /** + * call back function. called when rate-dialog showing + */ + onRateDialogShow?: Function; + /** + * call back function. called when user clicked on negative feedback + */ + handleNegativeFeedback?: Function; +} +export interface AppUrls { + /** + * application id in AppStore + */ + ios?: string; + /** + * application URL in GooglePlay + */ + android?: string; + /** + * application URL in Windows Store + */ + windows?: string; + /** + * application URL in AppWorld + */ + blackberry?: string; + /** + * application URL in WindowsStore + */ + windows8?: string; +} + +export class AppRateMock extends AppRate { + /** + * Configure various settings for the Rating View. + * See table below for options + */ + preferences: AppRatePreferences; + /** + * Prompts the user for rating + * @param {boolean} immediately Show the rating prompt immediately. + */ + promptForRating(immediately: boolean): void { }; + /** + * Immediately send the user to the app store rating page + */ + navigateToAppStore(): void { }; +} diff --git a/src/@ionic-native-mocks/plugins/app-version/index.ts b/src/@ionic-native-mocks/plugins/app-version/index.ts new file mode 100644 index 0000000..c3cb15d --- /dev/null +++ b/src/@ionic-native-mocks/plugins/app-version/index.ts @@ -0,0 +1,40 @@ +import { AppVersion } from '@ionic-native/app-version'; + +export class AppVersionMock extends AppVersion { + /** + * Returns the name of the app + * @returns {Promise} + */ + getAppName(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Returns the package name of the app + * @returns {Promise} + */ + getPackageName(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Returns the build identifier of the app + * @returns {Promise} + */ + getVersionCode(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Returns the version of the app + * @returns {Promise} + */ + getVersionNumber(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; +} diff --git a/src/@ionic-native-mocks/plugins/background-geolocation/index.ts b/src/@ionic-native-mocks/plugins/background-geolocation/index.ts new file mode 100644 index 0000000..b3effa7 --- /dev/null +++ b/src/@ionic-native-mocks/plugins/background-geolocation/index.ts @@ -0,0 +1,500 @@ +import { BackgroundGeolocation } from '@ionic-native/background-geolocation'; +import { Observable } from 'rxjs/Observable'; +import { Observer } from 'rxjs/Observer'; + +export interface BackgroundGeolocationResponse { + /** + * ID of location as stored in DB (or null) + */ + locationId: number; + /** + * Service provider + */ + serviceProvider: string; + /** + * true if location recorded as part of debug + */ + debug: boolean; + /** + * UTC time of this fix, in milliseconds since January 1, 1970. + */ + time: number; + /** + * latitude, in degrees. + */ + latitude: number; + /** + * longitude, in degrees. + */ + longitude: number; + /** + * estimated accuracy of this location, in meters. + */ + accuracy: number; + /** + * speed if it is available, in meters/second over ground. + */ + speed: number; + /** + * altitude if available, in meters above the WGS 84 reference ellipsoid. + */ + altitude: number; + /** + * accuracy of the altitude if available. + */ + altitudeAccuracy: number; + /** + * bearing, in degrees. + */ + bearing: number; + /** + * A Coordinates object defining the current location + */ + coords: Coordinates; + /** + * A timestamp representing the time at which the location was retrieved. + */ + timestamp: number; +} +export interface BackgroundGeolocationConfig { + /** + * Desired accuracy in meters. Possible values [0, 10, 100, 1000]. The lower + * the number, the more power devoted to GeoLocation resulting in higher + * accuracy readings. 1000 results in lowest power drain and least accurate + * readings. @see Apple docs (https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instp/CLLocationManager/desiredAccuracy) + */ + desiredAccuracy: number; + /** + * Stationary radius in meters. When stopped, the minimum distance the device + * must move beyond the stationary location for aggressive background-tracking + * to engage. + */ + stationaryRadius: number; + /** + * When enabled, the plugin will emit sounds for life-cycle events of + * background-geolocation! See debugging sounds table. + */ + debug?: boolean; + /** + * The minimum distance (measured in meters) a device must move horizontally + * before an update event is generated. @see Apple docs. (https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/occ/instp/CLLocationManager/distanceFilter) + */ + distanceFilter: number; + /** + * IOS, ANDROID ONLY + * Enable this in order to force a stop() when the application terminated + * (e.g. on iOS, double-tap home button, swipe away the app).o + * + * Defaults to true + */ + stopOnTerminate?: boolean; + /** + + * ANDROID ONLY + + * Start background service on device boot. + + * + * Defaults to false + + */ + startOnBoot?: boolean; + /** + + * ANDROID ONLY + + * If false location service will not be started in foreground and no notification will be shown. + * + * Defaults to true + + */ + startForeground?: boolean; + /** + * ANDROID ONLY + * When using BackgroundGeolocation.LocationProvider.ANDROID_DISTANCE_FILTER_PROVIDER: + * The minimum time interval between location updates in milliseconds. + * @see Android docs (http://developer.android.com/reference/android/location/LocationManager.html#requestLocationUpdates(long,%20float,%20android.location.Criteria,%20android.app.PendingIntent)) + * and the MS doc (http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.geolocation.geolocator.reportinterval) + * for more information + * When using BackgroundGeolocation.LocationProvider.ANDROID_ACTIVITY_PROVIDER: + * Rate in milliseconds at which your app prefers to receive location updates. + * @see Android docs (https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#getInterval()) + */ + interval?: number; + /** + * ANDROID ONLY + * Custom notification title in the drawer. + */ + notificationTitle?: string; + /** + * ANDROID ONLY + * Custom notification text in the drawer. + */ + notificationText?: string; + /** + * ANDROID ONLY + * The accent color to use for notification. Eg. #4CAF50. + */ + notificationIconColor?: string; + /** + + * ANDROID ONLY + + * The filename of a custom notification icon. See android quirks. + + * NOTE: Only available for API Level >=21. + + */ + notificationIconLarge?: string; + /** + + * ANDROID ONLY + + * The filename of a custom notification icon. See android quirks. + + * NOTE: Only available for API Level >=21. + + */ + notificationIconSmall?: string; + /** + * ANDROID ONLY + * Set location service provider @see wiki (https://github.com/mauron85/cordova-plugin-background-geolocation/wiki/Android-providers) + */ + locationProvider?: number; + /** + * IOS ONLY + * [AutomotiveNavigation, OtherNavigation, Fitness, Other] Presumably, + * this affects iOS GPS algorithm. @see Apple docs for more information + * (https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/occ/instp/CLLocationManager/activityType) + */ + activityType?: string; + /** + + * IOS ONLY + + * Pauses location updates when app is paused + + * + * Defaults to true + + */ + pauseLocationUpdates?: boolean; + /** + + * Server url where to send HTTP POST with recorded locations + + * @see https://github.com/mauron85/cordova-plugin-background-geolocation#http-locations-posting + + */ + url?: string; + /** + + * Server url where to send fail to post locations + + * @see https://github.com/mauron85/cordova-plugin-background-geolocation#http-locations-posting + + */ + syncUrl?: string; + /** + * Specifies how many previously failed locations will be sent to server at once + + * + * Defaults to 100 + + */ + syncThreshold?: number; + /** + + * Optional HTTP headers sent along in HTTP request + + */ + httpHeaders?: any; + /** + * IOS ONLY + + * Switch to less accurate significant changes and region monitory when in background (default) + * + * Defaults to 100 + + */ + saveBatteryOnBackground?: boolean; + /** + + * Limit maximum number of locations stored into db + + * + * Defaults to 10000 + + */ + maxLocations?: number; + /** + * ANDROID ONLY with BackgroundGeolocation.LocationProvider.ANDROID_ACTIVITY_PROVIDER + * + * Fastest rate in milliseconds at which your app can handle location updates. + * @see Android docs (https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.html#getFastestInterval()) + */ + fastestInterval?: number; + /** + * ANDROID ONLY with BackgroundGeolocation.LocationProvider.ANDROID_ACTIVITY_PROVIDER + * + * Rate in milliseconds at which activity recognition occurs. Larger values will result in fewer activity detections while improving battery life. + */ + activitiesInterval?: number; + /** + * ANDROID ONLY with BackgroundGeolocation.LocationProvider.ANDROID_ACTIVITY_PROVIDER + * + * stop() is forced, when the STILL activity is detected (default is true) + */ + stopOnStillActivity?: boolean; +} + +export class BackgroundGeolocatioMock extends BackgroundGeolocation { + /** + + * Set location service provider @see https://github.com/mauron85/cordova-plugin-background-geolocation/wiki/Android-providers + + * + * Possible values: + * ANDROID_DISTANCE_FILTER_PROVIDER: 0, + + * ANDROID_ACTIVITY_PROVIDER: 1 + + * + * @enum {number} + + */ + LocationProvider: any; + /** + * Desired accuracy in meters. Possible values [0, 10, 100, 1000]. + + * The lower the number, the more power devoted to GeoLocation resulting in higher accuracy readings. + + * 1000 results in lowest power drain and least accurate readings. + + * + * Possible values: + * HIGH: 0 + + * MEDIUM: 10 + + * LOW: 100 + + * PASSIVE: 1000 + * + * enum {number} + + */ + Accuracy: any; + /** + + * Used in the switchMode function + + * + * Possible values: + * BACKGROUND: 0 + * FOREGROUND: 1 + + * + * @enum {number} + + */ + Mode: any; + /** + * Configure the plugin. + * + * @param options {BackgroundGeolocationConfig} options An object of type Config + * @return {Observable} + */ + configure(options: BackgroundGeolocationConfig): Observable { + return Observable.create((observer: Observer) => { + let response: BackgroundGeolocationResponse; + observer.next( response ); + observer.complete(); + }); + }; + /** + * Turn ON the background-geolocation system. + * The user will be tracked whenever they suspend the app. + * @returns {Promise} + */ + start(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Turn OFF background-tracking + * @returns {Promise} + */ + stop(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Inform the native plugin that you're finished, the background-task may be completed + * @returns {Promise} + */ + finish(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Force the plugin to enter "moving" or "stationary" state + * @param isMoving {boolean} + * @returns {Promise} + */ + changePace(isMoving: boolean): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Setup configuration + * @param options {BackgroundGeolocationConfig} + * @returns {Promise} + */ + setConfig(options: BackgroundGeolocationConfig): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Returns current stationaryLocation if available. null if not + * @returns {Promise} + */ + getStationaryLocation(): Promise { + let response: BackgroundGeolocationResponse; + return new Promise((resolve, reject) => { + resolve( response ) ; + }); + }; + /** + * Add a stationary-region listener. Whenever the devices enters "stationary-mode", + * your #success callback will be executed with #location param containing #radius of region + * @returns {Promise} + */ + onStationary(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Check if location is enabled on the device + * @returns {Promise} Returns a promise with int argument that takes values 0, 1 (true). + */ + isLocationEnabled(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Display app settings to change permissions + */ + showAppSettings(): void { }; + /** + * Display device location settings + */ + showLocationSettings(): void { }; + /** + * Method can be used to detect user changes in location services settings. + * If user enable or disable location services then success callback will be executed. + * In case or error (SettingNotFoundException) fail callback will be executed. + * @returns {Promise} + */ + watchLocationMode(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Stop watching for location mode changes. + * @returns {Promise} + */ + stopWatchingLocationMode(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Method will return all stored locations. + * Locations are stored when: + * - config.stopOnTerminate is false and main activity was killed + * by the system + * or + * - option.debug is true + * @returns {Promise} + */ + getLocations(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + + * Method will return locations, which has not been yet posted to server. NOTE: Locations does contain locationId. + + * @returns {Promise} + */ + getValidLocations(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Delete stored location by given locationId. + * @param locationId {number} + * @returns {Promise} + */ + deleteLocation(locationId: number): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Delete all stored locations. + * @returns {Promise} + */ + deleteAllLocations(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Normally plugin will handle switching between BACKGROUND and FOREGROUND mode itself. + * Calling switchMode you can override plugin behavior and force plugin to switch into other mode. + * + * In FOREGROUND mode plugin uses iOS local manager to receive locations and behavior is affected by option.desiredAccuracy and option.distanceFilter. + * In BACKGROUND mode plugin uses significant changes and region monitoring to receive locations and uses option.stationaryRadius only. + + * + * BackgroundGeolocation.Mode.FOREGROUND + * BackgroundGeolocation.Mode.BACKGROUND + + ** + * @param modeId {number} + * @returns {Promise} + */ + switchMode(modeId: number): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + + * Return all logged events. Useful for plugin debugging. Parameter limit limits number of returned entries. + + * @see https://github.com/mauron85/cordova-plugin-background-geolocation/tree/v2.2.1#debugging for more information. + + * + * @param limit {number} Limits the number of entries + + * @returns {Promise} + */ + getLogEntries(limit: number): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; +} diff --git a/src/@ionic-native-mocks/plugins/badge/index.ts b/src/@ionic-native-mocks/plugins/badge/index.ts new file mode 100644 index 0000000..8063c9d --- /dev/null +++ b/src/@ionic-native-mocks/plugins/badge/index.ts @@ -0,0 +1,70 @@ +import { Badge } from '@ionic-native/badge'; + +export class BadgeMOck extends Badge { + /** + * Clear the badge of the app icon. + * @returns {Promise} + */ + clear(): Promise { + return new Promise((resolve, reject) => { + resolve(true); + }); + }; + /** + * Set the badge of the app icon. + * @param {number} badgeNumber The new badge number. + * @returns {Promise} + */ + set(badgeNumber: number): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Get the badge of the app icon. + * @returns {Promise} + */ + get(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Increase the badge number. + * @param {number} increaseBy Count to add to the current badge number + * @returns {Promise} + */ + increase(increaseBy: number): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Decrease the badge number. + * @param {number} decreaseBy Count to subtract from the current badge number + * @returns {Promise} + */ + decrease(decreaseBy: number): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Determine if the app has permission to show badges. + * @returns {Promise} + */ + hasPermission(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Register permission to set badge notifications + * @returns {Promise} + */ + registerPermission(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; +} diff --git a/src/@ionic-native-mocks/plugins/base64-to-gallery/index.ts b/src/@ionic-native-mocks/plugins/base64-to-gallery/index.ts new file mode 100644 index 0000000..1e39be6 --- /dev/null +++ b/src/@ionic-native-mocks/plugins/base64-to-gallery/index.ts @@ -0,0 +1,15 @@ +import { Base64ToGallery } from '@ionic-native/base64-to-gallery'; + +export class Base64ToGalleryMock extends Base64ToGallery { + /** + * Converts a base64 string to an image file in the device gallery + * @param {string} data The actual base64 string that you want to save + * @param {any} [options] An object with properties: prefix: string, mediaScanner: boolean. Prefix will be prepended to the filename. If true, mediaScanner runs Media Scanner on Android and saves to Camera Roll on iOS; if false, saves to Library folder on iOS. + * @returns {Promise} returns a promise that resolves when the image is saved. + */ + base64ToGallery(data: string, options?: { prefix?: string; mediaScanner?: boolean; }): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; +} diff --git a/src/@ionic-native-mocks/plugins/base64/index.ts b/src/@ionic-native-mocks/plugins/base64/index.ts new file mode 100644 index 0000000..bf2def3 --- /dev/null +++ b/src/@ionic-native-mocks/plugins/base64/index.ts @@ -0,0 +1,14 @@ +import { Base64 } from '@ionic-native/base64'; + +export class Base64Mock extends Base64 { + /** + * This function encodes base64 of any file + * @param {string} filePath Absolute file path + * @return {Promise} Returns a promise that resolves when the file is successfully encoded + */ + encodeFile(filePath: string): Promise { + return new Promise((resolve, reject) => { + resolve(''); + }); + }; +} diff --git a/src/@ionic-native-mocks/plugins/battery-status/index.ts b/src/@ionic-native-mocks/plugins/battery-status/index.ts new file mode 100644 index 0000000..d6373b6 --- /dev/null +++ b/src/@ionic-native-mocks/plugins/battery-status/index.ts @@ -0,0 +1,50 @@ +import { BatteryStatus } from '@ionic-native/battery-status'; +import { Observable } from 'rxjs/Observable'; +import { Observer } from 'rxjs/Observer'; + +export interface BatteryStatusResponse { + /** + * The battery charge percentage + */ + level: number; + /** + * A boolean that indicates whether the device is plugged in + */ + isPlugged: boolean; +} + +export class BatteryStatusMock extends BatteryStatus { + /** + * Watch the change in battery level + * @returns {Observable} Returns an observable that pushes a status object + */ + onChange(): Observable { + let response: BatteryStatusResponse; + return Observable.create((observer: Observer) => { + observer.next(response); + observer.complete(); + }); + }; + /** + * Watch when the battery level goes low + * @returns {Observable} Returns an observable that pushes a status object + */ + onLow(): Observable { + let response: BatteryStatusResponse; + return Observable.create((observer: Observer) => { + observer.next(response); + observer.complete(); + }); + }; + /** + * Watch when the battery level goes to critial + * @returns {Observable} Returns an observable that pushes a status object + */ + onCritical(): Observable { + let response: BatteryStatusResponse; + return Observable.create((observer: Observer) => { + observer.next(response); + observer.complete(); + }); + }; +} diff --git a/src/@ionic-native-mocks/plugins/file/index.ts b/src/@ionic-native-mocks/plugins/file/index.ts new file mode 100644 index 0000000..c136ef6 --- /dev/null +++ b/src/@ionic-native-mocks/plugins/file/index.ts @@ -0,0 +1,876 @@ +import { File } from '@ionic-native/file'; + +export interface IFile extends Blob { + /** + * Name of the file, without path information + */ + name: string; + /** + * Last modified date + */ + lastModified: number; + /** + * Last modified date + */ + lastModifiedDate: number; + /** + * Size in bytes + */ + size: number; + /** + * File mime type + */ + type: string; + localURL: string; + start: number; + end: number; + /** + * Returns a "slice" of the file. Since Cordova Files don't contain the actual + * content, this really returns a File with adjusted start and end. + * Slices of slices are supported. + * @param start {Number} The index at which to start the slice (inclusive). + * @param end {Number} The index at which to end the slice (exclusive). + */ + slice(start: number, end: number): Blob; +} +export interface LocalFileSystem { + /** + * Used for storage with no guarantee of persistence. + */ + TEMPORARY: number; + /** + * Used for storage that should not be removed by the user agent without application or user permission. + */ + PERSISTENT: number; + /** + * Requests a filesystem in which to store application data. + * @param type Whether the filesystem requested should be persistent, as defined above. Use one of TEMPORARY or PERSISTENT. + * @param size This is an indicator of how much storage space, in bytes, the application expects to need. + * @param successCallback The callback that is called when the user agent provides a filesystem. + * @param errorCallback A callback that is called when errors happen, or when the request to obtain the filesystem is denied. + */ + requestFileSystem(type: number, size: number, successCallback: FileSystemCallback, errorCallback?: ErrorCallback): void; + /** + * Allows the user to look up the Entry for a file or directory referred to by a local URL. + * @param url A URL referring to a local file in a filesystem accessable via this API. + * @param successCallback A callback that is called to report the Entry to which the supplied URL refers. + * @param errorCallback A callback that is called when errors happen, or when the request to obtain the Entry is denied. + */ + resolveLocalFileSystemURL(url: string, successCallback: EntryCallback, errorCallback?: ErrorCallback): void; + /** + * see requestFileSystem. + */ + webkitRequestFileSystem(type: number, size: number, successCallback: FileSystemCallback, errorCallback?: ErrorCallback): void; +} +export interface Metadata { + /** + * This is the time at which the file or directory was last modified. + * @readonly + */ + modificationTime: Date; + /** + * The size of the file, in bytes. This must return 0 for directories. + * @readonly + */ + size: number; +} +export interface Flags { + /** + * Used to indicate that the user wants to create a file or directory if it was not previously there. + */ + create?: boolean; + /** + * By itself, exclusive must have no effect. Used with create, it must cause getFile and getDirectory to fail if the target path already exists. + */ + exclusive?: boolean; +} +/** + * This export interface represents a file system. + */ +export interface FileSystem { + /** + * This is the name of the file system. The specifics of naming filesystems is unspecified, but a name must be unique across the list of exposed file systems. + * @readonly + */ + name: string; + /** + * The root directory of the file system. + * @readonly + */ + root: DirectoryEntry; + toJSON(): string; + encodeURIPath(path: string): string; +} +export interface Entry { + /** + * Entry is a file. + */ + isFile: boolean; + /** + * Entry is a directory. + */ + isDirectory: boolean; + /** + * Look up metadata about this entry. + * @param successCallback A callback that is called with the time of the last modification. + * @param errorCallback ErrorCallback A callback that is called when errors happen. + */ + getMetadata(successCallback: MetadataCallback, errorCallback?: ErrorCallback): void; + /** + * Set the metadata of the entry. + * @param successCallback {Function} is called with a Metadata object + * @param errorCallback {Function} is called with a FileError + * @param metadataObject {Metadata} keys and values to set + */ + setMetadata(successCallback: MetadataCallback, errorCallback: ErrorCallback, metadataObject: Metadata): void; + /** + * The name of the entry, excluding the path leading to it. + */ + name: string; + /** + * The full absolute path from the root to the entry. + */ + fullPath: string; + /** + * The file system on which the entry resides. + */ + filesystem: FileSystem; + /** + * an alternate URL which can be used by native webview controls, for example media players. + */ + nativeURL: string; + /** + * Move an entry to a different location on the file system. It is an error to try to: + * + * + *
  • move a directory inside itself or to any child at any depth;
  • + *
  • move an entry into its parent if a name different from its current one isn't provided;
  • + *
  • move a file to a path occupied by a directory;
  • + *
  • move a directory to a path occupied by a file;
  • + *
  • move any element to a path occupied by a directory which is not empty.
  • + *
      + * + * A move of a file on top of an existing file must attempt to delete and replace that file. + * A move of a directory on top of an existing empty directory must attempt to delete and replace that directory. + */ + moveTo(parent: DirectoryEntry, newName?: string, successCallback?: EntryCallback, errorCallback?: ErrorCallback): void; + /** + * Copy an entry to a different location on the file system. It is an error to try to: + * + *
        + *
      • copy a directory inside itself or to any child at any depth;
      • + *
      • copy an entry into its parent if a name different from its current one isn't provided;
      • + *
      • copy a file to a path occupied by a directory;
      • + *
      • copy a directory to a path occupied by a file;
      • + *
      • copy any element to a path occupied by a directory which is not empty.
      • + *
      • A copy of a file on top of an existing file must attempt to delete and replace that file.
      • + *
      • A copy of a directory on top of an existing empty directory must attempt to delete and replace that directory.
      • + *
      + * + * Directory copies are always recursive--that is, they copy all contents of the directory. + */ + copyTo(parent: DirectoryEntry, newName?: string, successCallback?: EntryCallback, errorCallback?: ErrorCallback): void; + /** + * Returns a URL that can be used to identify this entry. Unlike the URN defined in [FILE-API-ED], it has no specific expiration; as it describes a location on disk, it should be valid at least as long as that location exists. + */ + toURL(): string; + /** + * Return a URL that can be passed across the bridge to identify this entry. + * @return string URL that can be passed across the bridge to identify this entry + */ + toInternalURL(): string; + /** + * Deletes a file or directory. It is an error to attempt to delete a directory that is not empty. It is an error to attempt to delete the root directory of a filesystem. + * @param successCallback A callback that is called on success. + * @param errorCallback A callback that is called when errors happen. + */ + remove(successCallback: VoidCallback, errorCallback?: ErrorCallback): void; + /** + * Look up the parent DirectoryEntry containing this Entry. If this Entry is the root of its filesystem, its parent is itself. + * @param successCallback A callback that is called to return the parent Entry. + * @param errorCallback A callback that is called when errors happen. + */ + getParent(successCallback: DirectoryEntryCallback, errorCallback?: ErrorCallback): void; +} +/** + * This export interface represents a directory on a file system. + */ +export interface DirectoryEntry extends Entry { + /** + * Creates a new DirectoryReader to read Entries from this Directory. + */ + createReader(): DirectoryReader; + /** + * Creates or looks up a file. + * @param path Either an absolute path or a relative path from this DirectoryEntry to the file to be looked up or created. It is an error to attempt to create a file whose immediate parent does not yet exist. + * @param options + *
        + *
      • If create and exclusive are both true, and the path already exists, getFile must fail.
      • + *
      • If create is true, the path doesn't exist, and no other error occurs, getFile must create it as a zero-length file and return a corresponding FileEntry.
      • + *
      • If create is not true and the path doesn't exist, getFile must fail.
      • + *
      • If create is not true and the path exists, but is a directory, getFile must fail.
      • + *
      • Otherwise, if no other error occurs, getFile must return a FileEntry corresponding to path.
      • + *
      + * @param successCallback A callback that is called to return the File selected or created. + * @param errorCallback A callback that is called when errors happen. + */ + getFile(path: string, options?: Flags, successCallback?: FileEntryCallback, errorCallback?: ErrorCallback): void; + /** + * Creates or looks up a directory. + * @param path Either an absolute path or a relative path from this DirectoryEntry to the directory to be looked up or created. It is an error to attempt to create a directory whose immediate parent does not yet exist. + * @param options + *
        + *
      • If create and exclusive are both true and the path already exists, getDirectory must fail.
      • + *
      • If create is true, the path doesn't exist, and no other error occurs, getDirectory must create and return a corresponding DirectoryEntry.
      • + *
      • If create is not true and the path doesn't exist, getDirectory must fail.
      • + *
      • If create is not true and the path exists, but is a file, getDirectory must fail.
      • + *
      • Otherwise, if no other error occurs, getDirectory must return a DirectoryEntry corresponding to path.
      • + *
      + * @param successCallback A callback that is called to return the DirectoryEntry selected or created. + * @param errorCallback A callback that is called when errors happen. + * + */ + getDirectory(path: string, options?: Flags, successCallback?: DirectoryEntryCallback, errorCallback?: ErrorCallback): void; + /** + * Deletes a directory and all of its contents, if any. In the event of an error [e.g. trying to delete a directory that contains a file that cannot be removed], some of the contents of the directory may be deleted. It is an error to attempt to delete the root directory of a filesystem. + * @param successCallback A callback that is called on success. + * @param errorCallback A callback that is called when errors happen. + */ + removeRecursively(successCallback: VoidCallback, errorCallback?: ErrorCallback): void; +} +/** + * This export interface lets a user list files and directories in a directory. If there are no additions to or deletions from a directory between the first and last call to readEntries, and no errors occur, then: + *
        + *
      • A series of calls to readEntries must return each entry in the directory exactly once.
      • + *
      • Once all entries have been returned, the next call to readEntries must produce an empty array.
      • + *
      • If not all entries have been returned, the array produced by readEntries must not be empty.
      • + *
      • The entries produced by readEntries must not include the directory itself ["."] or its parent [".."].
      • + *
      + */ +export interface DirectoryReader { + localURL: string; + hasReadEntries: boolean; + /** + * Read the next block of entries from this directory. + * @param successCallback Called once per successful call to readEntries to deliver the next previously-unreported set of Entries in the associated Directory. If all Entries have already been returned from previous invocations of readEntries, successCallback must be called with a zero-length array as an argument. + * @param errorCallback A callback indicating that there was an error reading from the Directory. + */ + readEntries(successCallback: EntriesCallback, errorCallback?: ErrorCallback): void; +} +/** + * This export interface represents a file on a file system. + */ +export interface FileEntry extends Entry { + /** + * Creates a new FileWriter associated with the file that this FileEntry represents. + * @param successCallback A callback that is called with the new FileWriter. + * @param errorCallback A callback that is called when errors happen. + */ + createWriter(successCallback: FileWriterCallback, errorCallback?: ErrorCallback): void; + /** + * Returns a File that represents the current state of the file that this FileEntry represents. + * @param successCallback A callback that is called with the File. + * @param errorCallback A callback that is called when errors happen. + */ + file(successCallback: FileCallback, errorCallback?: ErrorCallback): void; +} +/** + * When requestFileSystem() succeeds, the following callback is made. + */ +export interface FileSystemCallback { + /** + * @param filesystem The file systems to which the app is granted access. + */ + (filesystem: FileSystem): void; +} +/** + * This export interface is the callback used to look up Entry objects. + */ +export interface EntryCallback { + /** + * @param entry + */ + (entry: Entry): void; +} +/** + * This export interface is the callback used to look up FileEntry objects. + */ +export interface FileEntryCallback { + /** + * @param entry + */ + (entry: FileEntry): void; +} +/** + * This export interface is the callback used to look up DirectoryEntry objects. + */ +export interface DirectoryEntryCallback { + /** + * @param entry + */ + (entry: DirectoryEntry): void; +} +/** + * When readEntries() succeeds, the following callback is made. + */ +export interface EntriesCallback { + (entries: Entry[]): void; +} +/** + * This export interface is the callback used to look up file and directory metadata. + */ +export interface MetadataCallback { + (metadata: Metadata): void; +} +/** + * This export interface is the callback used to create a FileWriter. + */ +export interface FileWriterCallback { + (fileWriter: FileWriter): void; +} +/** + * This export interface is the callback used to obtain a File. + */ +export interface FileCallback { + (file: IFile): void; +} +/** + * This export interface is the generic callback used to indicate success of an asynchronous method. + */ +export interface VoidCallback { + (): void; +} +/** + * When an error occurs, the following callback is made. + */ +export interface ErrorCallback { + (err: FileError): void; +} +export interface RemoveResult { + success: boolean; + fileRemoved: Entry; +} +/** @hidden */ +export declare class FileSaver extends EventTarget { + /** + * When the FileSaver constructor is called, the user agent must return a new FileSaver object with readyState set to INIT. + * This constructor must be visible when the script's global object is either a Window object or an object implementing the WorkerUtils interface. + */ + constructor(data: Blob); + /** + * When the abort method is called, user agents must run the steps below: + *
        + *
      1. If readyState == DONE or readyState == INIT, terminate this overall series of steps without doing anything else.
      2. + *
      3. Set readyState to DONE.
      4. + *
      5. If there are any tasks from the object's FileSaver task source in one of the task queues, then remove those tasks.
      6. + *
      7. Terminate the write algorithm being processed.
      8. + *
      9. Set the error attribute to a DOMError object of type "AbortError".
      10. + *
      11. Fire a progress event called abort
      12. + *
      13. Fire a progress event called writeend
      14. + *
      15. Terminate this algorithm.
      16. + *
      + */ + abort(): void; + /** + * The blob is being written. + * @readonly + */ + INIT: number; + /** + * The object has been constructed, but there is no pending write. + * @readonly + */ + WRITING: number; + /** + * The entire Blob has been written to the file, an error occurred during the write, or the write was aborted using abort(). The FileSaver is no longer writing the blob. + * @readonly + */ + DONE: number; + /** + * The FileSaver object can be in one of 3 states. The readyState attribute, on getting, must return the current state, which must be one of the following values: + *
        + *
      • INIT
      • + *
      • WRITING
      • + *
      • DONE
      • + *
          + * @readonly + */ + readyState: number; + /** + * The last error that occurred on the FileSaver. + * @readonly + */ + error: Error; + /** + * Handler for writestart events + */ + onwritestart: (event: ProgressEvent) => void; + /** + * Handler for progress events. + */ + onprogress: (event: ProgressEvent) => void; + /** + * Handler for write events. + */ + onwrite: (event: ProgressEvent) => void; + /** + * Handler for abort events. + */ + onabort: (event: ProgressEvent) => void; + /** + * Handler for error events. + */ + onerror: (event: ProgressEvent) => void; + /** + * Handler for writeend events. + */ + onwriteend: (event: ProgressEvent) => void; +} +/** + * @hidden + * This interface expands on the FileSaver interface to allow for multiple write actions, rather than just saving a single Blob. + */ +export declare class FileWriter extends FileSaver { + /** + * The byte offset at which the next write to the file will occur. This must be no greater than length. + * A newly-created FileWriter must have position set to 0. + */ + position: number; + /** + * The length of the file. If the user does not have read access to the file, this must be the highest byte offset at which the user has written. + */ + length: number; + /** + * Write the supplied data to the file at position. + * @param data The blob to write. + */ + write(data: ArrayBuffer | Blob | string): void; + /** + * Seek sets the file position at which the next write will occur. + * @param offset If nonnegative, an absolute byte offset into the file. If negative, an offset back from the end of the file. + */ + seek(offset: number): void; + /** + * Changes the length of the file to that specified. If shortening the file, data beyond the new length must be discarded. If extending the file, the existing data must be zero-padded up to the new length. + * @param size The size to which the length of the file is to be adjusted, measured in bytes. + */ + truncate(size: number): void; +} +export interface IWriteOptions { + replace?: boolean; + append?: boolean; + truncate?: number; +} +/** @hidden */ +export declare class FileError { + constructor(code: number); + static NOT_FOUND_ERR: number; + static SECURITY_ERR: number; + static ABORT_ERR: number; + static NOT_READABLE_ERR: number; + static ENCODING_ERR: number; + static NO_MODIFICATION_ALLOWED_ERR: number; + static INVALID_STATE_ERR: number; + static SYNTAX_ERR: number; + static INVALID_MODIFICATION_ERR: number; + static QUOTA_EXCEEDED_ERR: number; + static TYPE_MISMATCH_ERR: number; + static PATH_EXISTS_ERR: number; + /** Error code */ + code: number; + message: string; +} +/** @hidden */ +export declare class FileReader { + static EMPTY: number; + static LOADING: number; + static DONE: number; + static READ_CHUNK_SIZE: number; + readyState: number; + error: Error; + result: string | ArrayBuffer; + onloadstart: (evt: ProgressEvent) => void; + onprogress: (evt: ProgressEvent) => void; + onload: (evt: ProgressEvent) => void; + onerror: (evt: ProgressEvent) => void; + onloadend: (evt: ProgressEvent) => void; + onabort: (evt: ProgressEvent) => void; + abort(): void; + readAsText(fe: IFile, encoding?: string): void; + readAsDataURL(fe: IFile): void; + readAsBinaryString(fe: IFile): void; + readAsArrayBuffer(fe: IFile): void; + /** + * @hidden + */ + [key: string]: any; +} + + +export class FileMock extends File { + /** + * Read-only directory where the application is installed. + */ + applicationDirectory: string; + /** + * Read-only directory where the application is installed. + */ + applicationStorageDirectory: string; + /** + * Where to put app-specific data files. + */ + dataDirectory: string; + /** + * Cached files that should survive app restarts. + * Apps should not rely on the OS to delete files in here. + */ + cacheDirectory: string; + /** + * Android: the application space on external storage. + */ + externalApplicationStorageDirectory: string; + /** + * Android: Where to put app-specific data files on external storage. + */ + externalDataDirectory: string; + /** + * Android: the application cache on external storage. + */ + externalCacheDirectory: string; + /** + * Android: the external storage (SD card) root. + */ + externalRootDirectory: string; + /** + * iOS: Temp directory that the OS can clear at will. + */ + tempDirectory: string; + /** + * iOS: Holds app-specific files that should be synced (e.g. to iCloud). + */ + syncedDataDirectory: string; + /** + * iOS: Files private to the app, but that are meaningful to other applications (e.g. Office files) + */ + documentsDirectory: string; + /** + * BlackBerry10: Files globally available to all apps + */ + sharedDirectory: string; + cordovaFileError: any; + /** + * Get free disk space in Bytes + * @returns {Promise} Returns a promise that resolves with the remaining free disk space in Bytes + */ + getFreeDiskSpace(): Promise { + return new Promise((resolve, reject) => { + resolve(1); + }); + }; + /** + * Check if a directory exists in a certain path, directory. + * + * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above + * @param {string} dir Name of directory to check + * @returns {Promise} Returns a Promise that resolves to true if the directory exists or rejects with an error. + */ + checkDir(path: string, dir: string): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Creates a new directory in the specific path. + * The replace boolean value determines whether to replace an existing directory with the same name. + * If an existing directory exists and the replace value is false, the promise will fail and return an error. + * + * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above + * @param {string} dirName Name of directory to create + * @param {boolean} replace If true, replaces file with same name. If false returns error + * @returns {Promise} Returns a Promise that resolves with a DirectoryEntry or rejects with an error. + */ + createDir(path: string, dirName: string, replace: boolean): Promise { + let response: DirectoryEntry; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Remove a directory at a given path. + * + * @param {string} path The path to the directory + * @param {string} dirName The directory name + * @returns {Promise} Returns a Promise that resolves to a RemoveResult or rejects with an error. + */ + removeDir(path: string, dirName: string): Promise { + let response: RemoveResult; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Move a directory to a given path. + * + * @param {string} path The source path to the directory + * @param {string} dirName The source directory name + * @param {string} newPath The destionation path to the directory + * @param {string} newDirName The destination directory name + * @returns {Promise} Returns a Promise that resolves to the new DirectoryEntry object or rejects with an error. + */ + moveDir(path: string, dirName: string, newPath: string, newDirName: string): Promise { + let response: DirectoryEntry; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Copy a directory in various methods. If destination directory exists, will fail to copy. + * + * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above + * @param {string} dirName Name of directory to copy + * @param {string} newPath Base FileSystem of new location + * @param {string} newDirName New name of directory to copy to (leave blank to remain the same) + * @returns {Promise} Returns a Promise that resolves to the new Entry object or rejects with an error. + */ + copyDir(path: string, dirName: string, newPath: string, newDirName: string): Promise { + let response: Entry; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * List files and directory from a given path. + * + * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above + * @param {string} dirName Name of directory + * @returns {Promise} Returns a Promise that resolves to an array of Entry objects or rejects with an error. + */ + listDir(path: string, dirName: string): Promise { + let response: Array = []; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Removes all files and the directory from a desired location. + * + * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above + * @param {string} dirName Name of directory + * @returns {Promise} Returns a Promise that resolves with a RemoveResult or rejects with an error. + */ + removeRecursively(path: string, dirName: string): Promise { + let response: RemoveResult; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Check if a file exists in a certain path, directory. + * + * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above + * @param {string} file Name of file to check + * @returns {Promise} Returns a Promise that resolves with a boolean or rejects with an error. + */ + checkFile(path: string, file: string): Promise { + return new Promise((resolve, reject) => { + resolve(true); + }); + }; + /** + * Creates a new file in the specific path. + * The replace boolean value determines whether to replace an existing file with the same name. + * If an existing file exists and the replace value is false, the promise will fail and return an error. + * + * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above + * @param {string} fileName Name of file to create + * @param {boolean} replace If true, replaces file with same name. If false returns error + * @returns {Promise} Returns a Promise that resolves to a FileEntry or rejects with an error. + */ + createFile(path: string, fileName: string, replace: boolean): Promise { + let response: FileEntry; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Removes a file from a desired location. + * + * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above + * @param {string} fileName Name of file to remove + * @returns {Promise} Returns a Promise that resolves to a RemoveResult or rejects with an error. + */ + removeFile(path: string, fileName: string): Promise { + let response: RemoveResult; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** Write a new file to the desired location. + * + * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above + * @param {string} fileName path relative to base path + * @param {string | Blob} text content or blob to write + * @param {IWriteOptions} options replace file if set to true. See WriteOptions for more information. + * @returns {Promise} Returns a Promise that resolves to updated file entry or rejects with an error. + */ + writeFile(path: string, fileName: string, text: string | Blob | ArrayBuffer, options?: IWriteOptions): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** Write content to FileEntry. + * + * @hidden + * @param {FileEntry} fe file entry object + * @param {string | Blob} text content or blob to write + * @param {IWriteOptions} options replace file if set to true. See WriteOptions for more information. + * @returns {Promise} Returns a Promise that resolves to updated file entry or rejects with an error. + */ + // private writeFileEntry(fe, text, options); + /** Write to an existing file. + * + * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above + * @param {string} fileName path relative to base path + * @param {string | Blob} text content or blob to write + * @returns {Promise} Returns a Promise that resolves or rejects with an error. + */ + writeExistingFile(path: string, fileName: string, text: string | Blob): Promise { + return; + // return new Promise((resolve, reject) => { + // resolve(); + // }); + }; + /** + * Read the contents of a file as text. + * + * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above + * @param {string} file Name of file, relative to path. + * @returns {Promise} Returns a Promise that resolves with the contents of the file as string or rejects with an error. + */ + readAsText(path: string, file: string): Promise { + return new Promise((resolve, reject) => { + resolve(''); + }); + }; + /** + * Read file and return data as a base64 encoded data url. + * A data url is of the form: + * data: [][;base64], + + * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above + * @param {string} file Name of file, relative to path. + * @returns {Promise} Returns a Promise that resolves with the contents of the file as data URL or rejects with an error. + */ + readAsDataURL(path: string, file: string): Promise { + return new Promise((resolve, reject) => { + resolve(''); + }); + }; + /** + * Read file and return data as a binary data. + * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above + * @param {string} file Name of file, relative to path. + * @returns {Promise} Returns a Promise that resolves with the contents of the file as string rejects with an error. + */ + readAsBinaryString(path: string, file: string): Promise { + return new Promise((resolve, reject) => { + resolve(''); + }); + }; + /** + * Read file and return data as an ArrayBuffer. + * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above + * @param {string} file Name of file, relative to path. + * @returns {Promise} Returns a Promise that resolves with the contents of the file as ArrayBuffer or rejects with an error. + */ + readAsArrayBuffer(path: string, file: string): Promise { + let response: ArrayBuffer; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + + // private readFile(path, file, readAs) ; + /** + * Move a file to a given path. + * + * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above + * @param {string} fileName Name of file to move + * @param {string} newPath Base FileSystem of new location + * @param {string} newFileName New name of file to move to (leave blank to remain the same) + * @returns {Promise} Returns a Promise that resolves to the new Entry or rejects with an error. + */ + moveFile(path: string, fileName: string, newPath: string, newFileName: string): Promise { + let response: Entry; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Copy a file in various methods. If file exists, will fail to copy. + * + * @param {string} path Base FileSystem. Please refer to the iOS and Android filesystems above + * @param {string} fileName Name of file to copy + * @param {string} newPath Base FileSystem of new location + * @param {string} newFileName New name of file to copy to (leave blank to remain the same) + * @returns {Promise} Returns a Promise that resolves to an Entry or rejects with an error. + */ + copyFile(path: string, fileName: string, newPath: string, newFileName: string): Promise { + let response: Entry; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * @hidden + */ + // private fillErrorMessage(err) ; + /** + * Resolves a local file system URL + * @param fileUrl {string} file system url + * @returns {Promise} + */ + resolveLocalFilesystemUrl(fileUrl: string): Promise { + let response: Entry; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Resolves a local directory url + * @param directoryUrl {string} directory system url + * @returns {Promise} + */ + resolveDirectoryUrl(directoryUrl: string): Promise { + let response: DirectoryEntry; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Get a directory + * @param directoryEntry {DirectoryEntry} Directory entry, obtained by resolveDirectoryUrl method + * @param directoryName {string} Directory name + * @param flags {Flags} Options + * @returns {Promise} + */ + getDirectory(directoryEntry: DirectoryEntry, directoryName: string, flags: Flags): Promise { + let response: DirectoryEntry; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Get a file + * @param directoryEntry {DirectoryEntry} Directory entry, obtained by resolveDirectoryUrl method + * @param fileName {string} File name + * @param flags {Flags} Options + * @returns {Promise} + */ + getFile(directoryEntry: DirectoryEntry, fileName: string, flags: Flags): Promise { + let response: FileEntry; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; +} diff --git a/src/@ionic-native-mocks/plugins/gyroscope/index.ts b/src/@ionic-native-mocks/plugins/gyroscope/index.ts new file mode 100644 index 0000000..36502d3 --- /dev/null +++ b/src/@ionic-native-mocks/plugins/gyroscope/index.ts @@ -0,0 +1,59 @@ +import { Gyroscope } from '@ionic-native/gyroscope'; +import { Observable } from 'rxjs/Observable'; +import { Observer } from 'rxjs/Observer'; +/** + * @hidden + */ +export interface GyroscopeOrientation { + /** + * Represent x-axis + */ + x: number; + /** + * Represent y-axis + */ + y: number; + /** + * Represent z-axis + */ + z: number; + /** + * Represent timestamp of sensor read. Default is 10000ms + */ + timestamp: number; +} +/** + * @hidden + */ +export interface GyroscopeOptions { + /** + * Represent how often (in milliseconds) sensor should be read. Default is 10000 ms + */ + frequency: number; +} + +export class GyroscopeMock extends Gyroscope { + /** + * Watching for gyroscope sensor changes + * @param {GyroscopeOptions} [options] + * @return {Observable} Returns an Observable that resolves GyroscopeOrientation + */ + watch(options?: GyroscopeOptions): Observable { + let response: GyroscopeOrientation; + return Observable.create((observer: Observer) => { + observer.next(response); + observer.complete(); + }); + }; + /** + * Get current data from gyroscope sensor + * @param {GyroscopeOptions} [options] + * @return {Promise} Returns a promise that resolves GyroscopeOrientation + */ + getCurrent(options?: GyroscopeOptions): Promise { + let response: GyroscopeOrientation; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; +} diff --git a/src/@ionic-native-mocks/plugins/in-app-browser/index.ts b/src/@ionic-native-mocks/plugins/in-app-browser/index.ts new file mode 100644 index 0000000..520317d --- /dev/null +++ b/src/@ionic-native-mocks/plugins/in-app-browser/index.ts @@ -0,0 +1,143 @@ +import { InAppBrowser, InAppBrowserObject } from '@ionic-native/in-app-browser'; +import { Observable } from 'rxjs/Observable'; +import { Observer } from 'rxjs/Observer'; + +export interface InAppBrowserOptions { + /** Set to yes or no to turn the InAppBrowser's location bar on or off. */ + location?: 'yes' | 'no'; + /** Set to yes to create the browser and load the page, but not show it. The loadstop event fires when loading is complete. + * Omit or set to no (default) to have the browser open and load normally. */ + hidden?: 'yes' | 'no'; + /** Set to yes to have the browser's cookie cache cleared before the new window is opened. */ + clearcache?: 'yes'; + /** Set to yes to have the session cookie cache cleared before the new window is opened. */ + clearsessioncache?: 'yes'; + /** (Android Only) set to yes to show Android browser's zoom controls, set to no to hide them. Default value is yes. */ + zoom?: 'yes' | 'no'; + /** Set to yes to use the hardware back button to navigate backwards through the InAppBrowser's history. + * If there is no previous page, the InAppBrowser will close. The default value is yes, so you must set it to no if you want the back button to simply close the InAppBrowser. */ + hardwareback?: 'yes' | 'no'; + /** Set to yes to prevent HTML5 audio or video from autoplaying (defaults to no). */ + mediaPlaybackRequiresUserAction?: 'yes' | 'no'; + /** (Android Only) Set to yes to make InAppBrowser WebView to pause/resume with the app to stop background audio (this may be required to avoid Google Play issues) */ + shouldPauseOnSuspend?: 'yes' | 'no'; + /** (iOS Only) Set to a string to use as the Done button's caption. Note that you need to localize this value yourself. */ + closebuttoncaption?: string; + /** (iOS Only) Set to yes or no (default is no). Turns on/off the UIWebViewBounce property. */ + disallowoverscroll?: 'yes' | 'no'; + /** (iOS Only) Set to yes or no to turn the toolbar on or off for the InAppBrowser (defaults to yes) */ + toolbar?: 'yes' | 'no'; + /** (iOS Only) Set to yes or no to prevent viewport scaling through a meta tag (defaults to no). */ + enableViewportScale?: 'yes' | 'no'; + /** (iOS Only) Set to yes or no to allow in-line HTML5 media playback, displaying within the browser window rather than a device-specific playback interface. + * The HTML's video element must also include the webkit-playsinline attribute (defaults to no) */ + allowInlineMediaPlayback?: 'yes' | 'no'; + /** (iOS Only) Set to yes or no to open the keyboard when form elements receive focus via JavaScript's focus() call (defaults to yes). */ + keyboardDisplayRequiresUserAction?: 'yes' | 'no'; + /** (iOS Only) Set to yes or no to wait until all new view content is received before being rendered (defaults to no). */ + suppressesIncrementalRendering?: 'yes' | 'no'; + /** (iOS Only) Set to pagesheet, formsheet or fullscreen to set the presentation style (defaults to fullscreen). */ + presentationstyle?: 'pagesheet' | 'formsheet' | 'fullscreen'; + /** (iOS Only) Set to fliphorizontal, crossdissolve or coververtical to set the transition style (defaults to coververtical). */ + transitionstyle?: 'fliphorizontal' | 'crossdissolve' | 'coververtical'; + /** (iOS Only) Set to top or bottom (default is bottom). Causes the toolbar to be at the top or bottom of the window. */ + toolbarposition?: 'top' | 'bottom'; + /** (Windows only) Set to yes to create the browser control without a border around it. + * Please note that if location=no is also specified, there will be no control presented to user to close IAB window. */ + fullscreen?: 'yes'; + /** + * @hidden + */ + [key: string]: any; +} +export interface InAppBrowserEvent extends Event { + /** the eventname, either loadstart, loadstop, loaderror, or exit. */ + type: string; + /** the URL that was loaded. */ + url: string; + /** the error code, only in the case of loaderror. */ + code: number; + /** the error message, only in the case of loaderror. */ + message: string; +} +/** + * @hidden + */ +export class InAppBrowserObjectMock extends InAppBrowserObject { + /** + * Opens a URL in a new InAppBrowser instance, the current browser instance, or the system browser. + * @param {string} url The URL to load. + * @param {string} [target="self"] The target in which to load the URL, an optional parameter that defaults to _self. + * _self: Opens in the WebView if the URL is in the white list, otherwise it opens in the InAppBrowser. + * _blank: Opens in the InAppBrowser. + * _system: Opens in the system's web browser. + * @param {string | InAppBrowserOptions} [options] Options for the InAppBrowser. Optional, defaulting to: location=yes. + * The options string must not contain any blank space, and each feature's + * name/value pairs must be separated by a comma. Feature names are case insensitive. + */ + constructor(url: string, target?: string, options?: string | InAppBrowserOptions) { + super( url, target, options ); + }; + /** + * Displays an InAppBrowser window that was opened hidden. Calling this has no effect + * if the InAppBrowser was already visible. + */ + show(): void { }; + /** + * Closes the InAppBrowser window. + */ + close(): void { }; + /** + * Hides an InAppBrowser window that is currently shown. Calling this has no effect + * if the InAppBrowser was already hidden. + */ + hide(): void { }; + /** + * Injects JavaScript code into the InAppBrowser window. + * @param script {Object} Details of the script to run, specifying either a file or code key. + * @returns {Promise} + */ + executeScript(script: { file?: string; code?: string; }): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Injects CSS into the InAppBrowser window. + * @param css {Object} Details of the script to run, specifying either a file or code key. + * @returns {Promise} + */ + insertCSS(css: { file?: string; code?: string; }): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * A method that allows you to listen to events happening in the browser. + * @param event {string} Name of the event + * @returns {Observable} Returns back an observable that will listen to the event on subscribe, and will stop listening to the event on unsubscribe. + */ + on(event: string): Observable { + let response: InAppBrowserEvent; + return Observable.create((observer: Observer) => { + observer.next(response); + observer.complete(); + }); + }; +} + +export class InAppBrowserMock extends InAppBrowser { + /** + * Opens a URL in a new InAppBrowser instance, the current browser instance, or the system browser. + * @param url {string} The URL to load. + * @param target {string} The target in which to load the URL, an optional parameter that defaults to _self. + * @param options {string} Options for the InAppBrowser. Optional, defaulting to: location=yes. + * The options string must not contain any blank space, and each feature's + * name/value pairs must be separated by a comma. Feature names are case insensitive. + * @returns {InAppBrowserObject} + */ + create(url: string, target?: string, options?: string | InAppBrowserOptions): InAppBrowserObjectMock { + let response = new InAppBrowserObjectMock(url); + return response; + }; +} diff --git a/src/@ionic-native-mocks/plugins/local-notifications/index.ts b/src/@ionic-native-mocks/plugins/local-notifications/index.ts new file mode 100644 index 0000000..8e76bd1 --- /dev/null +++ b/src/@ionic-native-mocks/plugins/local-notifications/index.ts @@ -0,0 +1,284 @@ +import { LocalNotifications } from '@ionic-native/local-notifications'; + +export interface ILocalNotification { + /** + * A unique identifier required to clear, cancel, update or retrieve the local notification in the future + * Default: 0 + */ + id?: number; + /** + * First row of the notification + * Default: Empty string (iOS) or the app name (Android) + */ + title?: string; + /** + * Second row of the notification + * Default: Empty string + */ + text?: string; + /** + * The interval at which to reschedule the local notification. That can be a value of second, minute, hour, day, week, month or year + * Default: 0 (which means that the system triggers the local notification once) + */ + every?: string; + /** + * The date and time when the system should deliver the local notification. If the specified value is nil or is a date in the past, the local notification is delivered immediately. + * Default: now ~ new Date() + */ + at?: any; + firstAt?: any; + /** + * The number currently set as the badge of the app icon in Springboard (iOS) or at the right-hand side of the local notification (Android) + * Default: 0 (which means don't show a number) + */ + badge?: number; + /** + * Uri of the file containing the sound to play when an alert is displayed + * Default: res://platform_default + */ + sound?: string; + /** + * Arbitrary data, objects will be encoded to JSON string + * Default: null + */ + data?: any; + /** + * ANDROID ONLY + * Uri of the icon that is shown in the ticker and notification + * Default: res://icon + */ + icon?: string; + /** + * ANDROID ONLY + * Uri of the resource (only res://) to use in the notification layouts. Different classes of devices may return different sizes + * Default: res://ic_popup_reminder + */ + smallIcon?: string; + /** + * ANDROID ONLY + * RGB value for the background color of the smallIcon. + * Default: Androids COLOR_DEFAULT, which will vary based on Android version. + */ + color?: string; + /** + * ANDROID ONLY + * Ongoing notifications differ from regular notifications in the following ways: + * - They are sorted above the regular notifications in the notification panel + * - They do not have an 'X' close button, and are not affected by the "Clear all" button + * Default: false + */ + ongoing?: boolean; + /** + * ANDROID ONLY + * ARGB value that you would like the LED on the device to blink + * Default: FFFFFF + */ + led?: string; + /** + * Notification priority. + */ + priority?: number; +} + +export class LocalNotificationsMocks extends LocalNotifications { + /** + * Schedules a single or multiple notifications + * @param options {Notification | Array} optional + */ + schedule(options?: ILocalNotification | Array): void { }; + /** + * Updates a previously scheduled notification. Must include the id in the options parameter. + * @param options {ILocalNotification} optional + */ + update(options?: ILocalNotification): void { }; + /** + * Clears single or multiple notifications + * @param notificationId {any} A single notification id, or an array of notification ids. + * @returns {Promise} Returns a promise when the notification had been cleared + */ + clear(notificationId: any): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Clears all notifications + * @returns {Promise} Returns a promise when all notifications have cleared + */ + clearAll(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Cancels single or multiple notifications + * @param notificationId {any} A single notification id, or an array of notification ids. + * @returns {Promise} Returns a promise when the notification is canceled + */ + cancel(notificationId: any): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Cancels all notifications + * @returns {Promise} Returns a promise when all notifications are canceled + */ + cancelAll(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Checks presence of a notification + * @param notificationId {number} + * @returns {Promise} + */ + isPresent(notificationId: number): Promise { + let response: Boolean; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Checks is a notification is scheduled + * @param notificationId {number} + * @returns {Promise} + */ + isScheduled(notificationId: number): Promise { + let response: Boolean; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Checks if a notification is triggered + * @param notificationId {number} + * @returns {Promise} + */ + isTriggered(notificationId: number): Promise { + let response: Boolean; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Get all the notification ids + * @returns {Promise>} + */ + getAllIds(): Promise> { + let response: Array = []; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Get the ids of triggered notifications + * @returns {Promise>} + */ + getTriggeredIds(): Promise> { + let response: Array = []; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Get the ids of scheduled notifications + * @returns {Promise>} Returns a promise + */ + getScheduledIds(): Promise> { + let response: Array = []; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Get a notification object + * @param notificationId {any} The id of the notification to get + * @returns {Promise} + */ + get(notificationId: any): Promise { + let response: ILocalNotification; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Get a scheduled notification object + * @param notificationId {any} The id of the notification to get + * @returns {Promise} + */ + getScheduled(notificationId: any): Promise { + let response: ILocalNotification; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Get a triggered notification object + * @param notificationId The id of the notification to get + * @returns {Promise} + */ + getTriggered(notificationId: any): Promise { + let response: ILocalNotification; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Get all notification objects + * @returns {Promise>} + */ + getAll(): Promise> { + let response: Array = []; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Get all scheduled notification objects + * @returns {Promise>} + */ + getAllScheduled(): Promise> { + let response: Array = []; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Get all triggered notification objects + * @returns {Promise>} + */ + getAllTriggered(): Promise> { + let response: Array = []; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Register permission to show notifications if not already granted. + * @returns {Promise} + */ + registerPermission(): Promise { + let response: Boolean; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Informs if the app has the permission to show notifications. + * @returns {Promise} + */ + hasPermission(): Promise { + let response: Boolean; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Sets a callback for a specific event + * @param eventName The name of the event. Available events: schedule, trigger, click, update, clear, clearall, cancel, cancelall + * @param callback Call back function. All events return notification and state parameter. clear and clearall return state parameter only. + */ + on(eventName: string, callback: any): void { }; +} diff --git a/src/@ionic-native-mocks/plugins/phonegap-local-notification/index.ts b/src/@ionic-native-mocks/plugins/phonegap-local-notification/index.ts new file mode 100644 index 0000000..d56d6d2 --- /dev/null +++ b/src/@ionic-native-mocks/plugins/phonegap-local-notification/index.ts @@ -0,0 +1,46 @@ +import { PhonegapLocalNotification, PLNObject } from '@ionic-native/phonegap-local-notification'; + +export interface LocalNotificationOptions { + /** + * Sets the direction of the notification. One of "auto", "ltr" or "rtl" + */ + dir?: string; + /** + * Sets the language of the notification + */ + lang?: string; + /** + * Sets the body of the notification + */ + body?: string; + /** + * Sets the identifying tag of the notification + */ + tag?: string; + /** + * Sets the icon of the notification + */ + icon?: string; +} + +export class PhonegapLocalNotificationMock extends PhonegapLocalNotification { + /** + * A global object that lets you interact with the Notification API. + * @param title {string} Title of the local notification. + * @param Options {LocalNotificationOptions} An object containing optional property/value pairs. + * @returns {PLNObject} + */ + create(title: string, options: LocalNotificationOptions): PLNObject { + let response: PLNObject = new PLNObject(title, options); + return response; + }; + /** + * requests permission from the user to show a local notification. + * @returns {Promise} + */ + requestPermission(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; +} diff --git a/src/@ionic-native-mocks/plugins/push/index.ts b/src/@ionic-native-mocks/plugins/push/index.ts new file mode 100644 index 0000000..4648c7a --- /dev/null +++ b/src/@ionic-native-mocks/plugins/push/index.ts @@ -0,0 +1,188 @@ +import { Push, PushObject } from '@ionic-native/push'; + +export declare type EventResponse = RegistrationEventResponse & NotificationEventResponse & Error; +export interface RegistrationEventResponse { + /** + * The registration ID provided by the 3rd party remote push service. + */ + registrationId: string; +} +export interface NotificationEventResponse { + /** + * The text of the push message sent from the 3rd party service. + */ + message: string; + /** + * The optional title of the push message sent from the 3rd party service. + */ + title?: string; + /** + * The number of messages to be displayed in the badge iOS or message count in the notification shade in Android. + * For windows, it represents the value in the badge notification which could be a number or a status glyph. + */ + count: string; + /** + * The name of the sound file to be played upon receipt of the notification. + */ + sound: string; + /** + * The path of the image file to be displayed in the notification. + */ + image: string; + /** + * An optional collection of data sent by the 3rd party push service that does not fit in the above properties. + */ + additionalData: NotificationEventAdditionalData & any; +} +/** + * Loosened up with a dictionary notation, but all non-defined properties need to use (map['prop']) notation + * + * Ideally the developer would overload (merged declaration) this or create a new interface that would extend this one + * so that he could specify any custom code without having to use array notation (map['prop']) for all of them. + */ +export interface NotificationEventAdditionalData { + [name: string]: any; + /** + * Whether the notification was received while the app was in the foreground + */ + foreground?: boolean; + collapse_key?: string; + coldstart?: boolean; + from?: string; + notId?: string; +} +export interface IOSPushOptions { + /** + * Maps to the project number in the Google Developer Console. Setting this + * uses GCM for notifications instead of native. + */ + senderID?: string; + /** + * Whether to use prod or sandbox GCM setting. + */ + gcmSandbox?: boolean | string; + /** + * If true the device shows an alert on receipt of notification. + * **Note**: the value you set this option to the first time you call the init + * method will be how the application always acts. Once this is set + * programmatically in the init method it can only be changed manually by the + * user in Settings>Notifications>App Name. This is normal iOS behaviour. + */ + alert?: boolean | string; + /** + * If true the device sets the badge number on receipt of notification. + * **Note**: the value you set this option to the first time you call the init + * method will be how the application always acts. Once this is set + * programmatically in the init method it can only be changed manually by the + * user in Settings>Notifications>App Name. This is normal iOS behaviour. + */ + badge?: boolean | string; + /** + * If true the device plays a sound on receipt of notification. + * **Note**: the value you set this option to the first time you call the init + * method will be how the application always acts. Once this is set + * programmatically in the init method it can only be changed manually by the + * user in Settings>Notifications>App Name. This is normal iOS behaviour. + */ + sound?: boolean | string; + /** + * If true the badge will be cleared on app startup. + */ + clearBadge?: boolean | string; + /** + * If the array contains one or more strings each string will be used to + * subscribe to a GcmPubSub topic. + * **Note**: only usable in conjunction with `senderID`. + */ + topics?: string[]; + /** + * The data required in order to enable Action Buttons for iOS. + * Action Buttons on iOS - https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md#action-buttons-1 + */ + categories?: CategoryArray; +} +export interface CategoryArray { + [name: string]: CategoryAction; +} +export interface CategoryAction { + yes?: CategoryActionData; + no?: CategoryActionData; + maybe?: CategoryActionData; +} +export interface CategoryActionData { + callback: string; + title: string; + foreground: boolean; + destructive: boolean; +} +export interface AndroidPushOptions { + /** + * Maps to the project number in the Google Developer Console. + */ + senderID: string; + /** + * The name of a drawable resource to use as the small-icon. The name should + * not include the extension. + */ + icon?: string; + /** + * Sets the background color of the small icon on Android 5.0 and greater. + * [Supported Formats](http://developer.android.com/intl/ru/reference/android/graphics/Color.html#parseColor(java.lang.String)) + */ + iconColor?: string; + /** + * If true it plays the sound specified in the push data or the default system + * sound. + */ + sound?: boolean | string; + /** + * If true the device vibrates on receipt of notification. + */ + vibrate?: boolean | string; + /** + * If true the icon badge will be cleared on init and before push messages are processed. + */ + clearBadge?: boolean | string; + /** + * If true the app clears all pending notifications when it is closed. + */ + clearNotifications?: boolean | string; + /** + * If true will always show a notification, even when the app is on the + * foreground. + */ + forceShow?: boolean | string; + /** + * If the array contains one or more strings each string will be used to + * subscribe to a GcmPubSub topic. + */ + topics?: string[]; +} +export interface PushOptions { + ios?: IOSPushOptions; + android?: AndroidPushOptions; + windows?: any; +} +export declare type PushEvent = 'registration' | 'error' | 'notification'; + +export class PushMock extends Push { + /** + * Init push notifications + * @param options {PushOptions} + * @return {PushObject} + */ + init(options: PushOptions): PushObject { + let response: PushObject = new PushObject( options ); + return response; + }; + /** + * Check whether the push notification permission has been granted. + * @return {Promise<{isEnabled: boolean}>} Returns a Promise that resolves with an object with one property: isEnabled, a boolean that indicates if permission has been granted. + */ + hasPermission(): Promise<{ isEnabled: boolean; }> { + let response: Boolean; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; +} diff --git a/src/@ionic-native-mocks/plugins/screen-orientation/index.ts b/src/@ionic-native-mocks/plugins/screen-orientation/index.ts new file mode 100644 index 0000000..a40ec2c --- /dev/null +++ b/src/@ionic-native-mocks/plugins/screen-orientation/index.ts @@ -0,0 +1,46 @@ +import { ScreenOrientation } from '@ionic-native/screen-orientation'; +import { Observable } from 'rxjs/Observable'; +import { Observer } from 'rxjs/Observer'; + +export class ScreenOrientationMock extends ScreenOrientation { + /** + * Convenience enum for possible orientations + */ + ORIENTATIONS: { + PORTRAIT_PRIMARY: string; + PORTRAIT_SECONDARY: string; + LANDSCAPE_PRIMARY: string; + LANDSCAPE_SECONDARY: string; + PORTRAIT: string; + LANDSCAPE: string; + ANY: string; + }; + /** + * Listen to orientation change event + * @return {Observable} + */ + onChange(): Observable { + return Observable.create((observer: Observer) => { + observer.complete(); + }); + }; + /** + * Lock the orientation to the passed value. + * See below for accepted values + * @param orientation {string} The orientation which should be locked. Accepted values see table above. + * @return {Promise} + */ + lock(orientation: string): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Unlock and allow all orientations. + */ + unlock(): void { }; + /** + * Get the current orientation of the device. + */ + type: string; +} diff --git a/src/@ionic-native-mocks/plugins/secure-storage/index.ts b/src/@ionic-native-mocks/plugins/secure-storage/index.ts new file mode 100644 index 0000000..9be501d --- /dev/null +++ b/src/@ionic-native-mocks/plugins/secure-storage/index.ts @@ -0,0 +1,78 @@ +import { SecureStorage, SecureStorageObject } from '@ionic-native/secure-storage'; + +export class SecureStorageObjectMock extends SecureStorageObject { + constructor(_objectInstance: any) { super(_objectInstance); }; + /** + * Gets a stored item + * @param key {string} + * @returns {Promise} + */ + get(key: string): Promise { + return new Promise((resolve, reject) => { + resolve(''); + }); + }; + /** + * Stores a value + * @param key {string} + * @param value {string} + * @returns {Promise} + */ + set(key: string, value: string): Promise { + return new Promise((resolve, reject) => { + resolve(''); + }); + }; + /** + * Removes a single stored item + * @param key {string} + * @returns {Promise} returns a promise that resolves with the key that was removed + */ + remove(key: string): Promise { + return new Promise((resolve, reject) => { + resolve(''); + }); + }; + /** + * Get all references from the storage. + * @returns {Promise} returns a promise that resolves with array of keys storage + */ + keys(): Promise> { + let response: Array = []; + return new Promise((resolve, reject) => { + resolve(response); + }); + }; + /** + * Clear all references from the storage. + * @returns {Promise} + */ + clear(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; + /** + * Brings up the screen-lock settings + * @returns {Promise} + */ + secureDevice(): Promise { + return new Promise((resolve, reject) => { + resolve(); + }); + }; +} + +export class SecureStorageMock extends SecureStorage { + /** + * Creates a namespaced storage. + * @param store {string} + * @returns {Promise} + */ + create(store: string): Promise { + let response: SecureStorageObjectMock = new SecureStorageObjectMock(store); + return new Promise((resolve, reject) => { + resolve(response); + }); + }; +}