@iotize/ionic
Version:
Iotize specific building blocks on top of @ionic/angular.
258 lines (249 loc) • 10 kB
JavaScript
import { DOCUMENT, CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { Injectable, NgZone, NgModule } from '@angular/core';
import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
import { NFC } from '@awesome-cordova-plugins/nfc/ngx';
import { Platform } from '@ionic/angular';
import { ProtocolFactoryService, TaskManagerUiModule, LibCommonModule, TAP_INFO_RESOLVER_CONFIG, TAP_CONNECTION_OPTIONS_PROVIDER, TAP_WIFI_SCANNER, TAP_BLE_SCANNER, TAP_NETWORK_SCANNER, TAP_EXECUTE_TAP_ACTION_SERVICE, TapAdministrationService } from '@iotize/ionic';
import { defaultInfoResolverConfig } from '@iotize/ionic/config';
import { BehaviorSubject, Subject, of, never } from 'rxjs';
import { sleep as sleep$1 } from '@iotize/common/utility';
import { AbstractVariable } from '@iotize/tap/data';
class TestingScanner {
constructor() {
this.scanning = new BehaviorSubject(false);
this._results$ = new Subject();
this._results = [];
}
get isScanning() {
return this.scanning.value;
}
get results() {
return this._results$.asObservable();
}
async start(option) {
this.clearResults();
await sleep$1(100);
if (!this.isScanning) {
this.scanning.next(true);
}
}
async stop() {
await sleep$1(100);
this.scanning.next(false);
}
addResult(result) {
this._results.push(result);
this._results$.next(this._results);
}
clearResults() {
this._results = [];
this._results$.next(this._results);
}
}
class BLEScannerTestingService extends TestingScanner {
}
/** @nocollapse */ BLEScannerTestingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: BLEScannerTestingService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
/** @nocollapse */ BLEScannerTestingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: BLEScannerTestingService });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: BLEScannerTestingService, decorators: [{
type: Injectable
}] });
class ProtocolFactoryTestingService {
constructor() { }
create(meta) {
throw new Error(`Unsupported protocol type "${meta.type}"`);
}
isValid(meta) {
return false;
}
}
/** @nocollapse */ ProtocolFactoryTestingService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ProtocolFactoryTestingService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
/** @nocollapse */ ProtocolFactoryTestingService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ProtocolFactoryTestingService });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: ProtocolFactoryTestingService, decorators: [{
type: Injectable
}], ctorParameters: function () { return []; } });
class ScannerNotAvailable {
constructor(message) {
this.message = message;
this.scanning = of(false);
this.isScanning = false;
this.results = never();
}
start(option) {
return Promise.reject(this.message);
}
stop() {
return Promise.reject(this.message);
}
}
const ProtocolFactoryTestingServiceProvider = {
provide: ProtocolFactoryService,
useClass: ProtocolFactoryTestingService,
};
function scannerNotAvailableFactory(name) {
const factory = () => {
const scanner = new ScannerNotAvailable(`${name} scanner is not available for this test`);
return scanner;
};
return factory;
}
class ExecuteTapActionTestingService {
async executeTapAction(callable) {
return await callable();
}
}
class IotizeIonicTestingModule {
static forRoot(options) {
// const providers: Provider[] = [];
const overwritesProvides = [];
if (options?.platform) {
overwritesProvides.push({
provide: Platform,
useFactory: (doc, ngZone) => {
return new TestingPlatform(doc, ngZone, options?.platform);
},
deps: [DOCUMENT, NgZone],
});
}
return {
ngModule: IotizeIonicTestingModule,
providers: [
// ...providers,
...overwritesProvides,
],
};
}
}
/** @nocollapse */ IotizeIonicTestingModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: IotizeIonicTestingModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
/** @nocollapse */ IotizeIonicTestingModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.10", ngImport: i0, type: IotizeIonicTestingModule, exports: [CommonModule,
ReactiveFormsModule,
FormsModule,
RouterTestingModule,
TaskManagerUiModule,
LibCommonModule] });
/** @nocollapse */ IotizeIonicTestingModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: IotizeIonicTestingModule, providers: [
BLEScannerTestingService,
ProtocolFactoryTestingServiceProvider,
{
provide: TAP_INFO_RESOLVER_CONFIG,
useValue: defaultInfoResolverConfig,
},
NFC,
{
provide: TAP_CONNECTION_OPTIONS_PROVIDER,
useValue: {
encryption: undefined,
nfcPairing: false,
refreshSessionState: true,
switchProtocol: false,
},
},
{
provide: TAP_WIFI_SCANNER,
useFactory: scannerNotAvailableFactory('Wi-Fi'),
},
{
provide: TAP_BLE_SCANNER,
useClass: BLEScannerTestingService,
},
{
provide: TAP_NETWORK_SCANNER,
useFactory: scannerNotAvailableFactory('Network'),
},
{
provide: TAP_EXECUTE_TAP_ACTION_SERVICE,
useClass: ExecuteTapActionTestingService,
},
TapAdministrationService,
], imports: [CommonModule,
ReactiveFormsModule,
FormsModule,
RouterTestingModule,
TaskManagerUiModule,
LibCommonModule] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: IotizeIonicTestingModule, decorators: [{
type: NgModule,
args: [{
declarations: [],
providers: [
BLEScannerTestingService,
ProtocolFactoryTestingServiceProvider,
{
provide: TAP_INFO_RESOLVER_CONFIG,
useValue: defaultInfoResolverConfig,
},
NFC,
{
provide: TAP_CONNECTION_OPTIONS_PROVIDER,
useValue: {
encryption: undefined,
nfcPairing: false,
refreshSessionState: true,
switchProtocol: false,
},
},
{
provide: TAP_WIFI_SCANNER,
useFactory: scannerNotAvailableFactory('Wi-Fi'),
},
{
provide: TAP_BLE_SCANNER,
useClass: BLEScannerTestingService,
},
{
provide: TAP_NETWORK_SCANNER,
useFactory: scannerNotAvailableFactory('Network'),
},
{
provide: TAP_EXECUTE_TAP_ACTION_SERVICE,
useClass: ExecuteTapActionTestingService,
},
TapAdministrationService,
],
imports: [],
exports: [
CommonModule,
ReactiveFormsModule,
FormsModule,
RouterTestingModule,
TaskManagerUiModule,
LibCommonModule,
],
}]
}] });
class TestingPlatform extends Platform {
constructor(doc, zone, platformName) {
super(doc, zone);
this.platformName = platformName;
}
is(platformName) {
return platformName === this.platformName;
}
}
class WifiScannerTestingService extends TestingScanner {
}
async function sleep(ms) {
return new Promise((resolve) => setTimeout((value) => resolve(value), ms));
}
class VariableInteractionTesting extends AbstractVariable {
get id() {
return this.options?.identifier || 'Unamed variable';
}
constructor(options) {
super();
this.options = options;
this._rawValue = Uint8Array.from([0]);
}
async readRawInner() {
return this._rawValue;
}
async writeRaw(value) {
this._rawValue = value;
}
}
/**
* Generated bundle index. Do not edit.
*/
export { BLEScannerTestingService, IotizeIonicTestingModule, ProtocolFactoryTestingService, ProtocolFactoryTestingServiceProvider, VariableInteractionTesting, WifiScannerTestingService, scannerNotAvailableFactory, sleep };
//# sourceMappingURL=iotize-ionic-testing.mjs.map