UNPKG

@shko.online/componentframework-mock

Version:

Mocking library to help with testing PowerApps Component Framework Components

99 lines (97 loc) 2.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeviceMock = void 0; var _sinon = require("sinon"); /* Copyright (c) 2022 Betim Beja and Shko Online LLC Licensed under the MIT license. */ class DeviceMock { constructor() { this.captureAudio = void 0; this.captureImage = void 0; this.captureVideo = void 0; this.getBarcodeValue = void 0; this.getCurrentPosition = void 0; this.pickFile = void 0; this.captureAudio = (0, _sinon.stub)(); this.captureAudio.callsFake(() => { return new Promise(resolve => { resolve({ fileContent: 'demo', fileName: 'fakeFile.wav', fileSize: 200, mimeType: 'audio/wav' }); }); }); this.captureImage = (0, _sinon.stub)(); this.captureImage.callsFake(options => { return new Promise(resolve => { resolve({ fileContent: 'demo', fileName: 'fakeFile.png', fileSize: 200, mimeType: 'image/png' }); }); }); this.captureVideo = (0, _sinon.stub)(); this.captureVideo.callsFake(() => { return new Promise(resolve => { resolve({ fileContent: 'demo', fileName: 'fakeFile.mp4', fileSize: 2000, mimeType: 'video/mp4' }); }); }); this.getBarcodeValue = (0, _sinon.stub)(); this.getBarcodeValue.callsFake(() => { return new Promise(resolve => { resolve('SHKO-ONLINE'); }); }); this.getCurrentPosition = (0, _sinon.stub)(); const currentPositionPromise = new Promise(resolve => { resolve({ coords: { accuracy: 141, latitude: 41.3415145, longitude: 19.7769355, altitude: 0, altitudeAccuracy: 0, heading: 0, speed: 0 }, timestamp: new Date() }); }); this.getCurrentPosition.returns(currentPositionPromise); this.pickFile = (0, _sinon.stub)(); const pickFilePromise = new Promise(resolve => { resolve({ accept: ' ', allowMultipleFiles: false, maximumAllowedFileSize: 1 }); }); this.pickFile.callsFake(options => { return new Promise(resolve => { const configuredOptions = options || { accept: 'image' }; resolve([{ fileContent: 'demo', fileName: 'fakeFile.png', fileSize: 200, mimeType: 'image/png' }]); }); }); } } exports.DeviceMock = DeviceMock;