UNPKG

@shko.online/componentframework-mock

Version:

Mocking library to help with testing PowerApps Component Framework Components

92 lines (91 loc) 2.37 kB
/* Copyright (c) 2022 Betim Beja and Shko Online LLC Licensed under the MIT license. */ import { stub } from 'sinon'; export 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 = stub(); this.captureAudio.callsFake(() => { return new Promise(resolve => { resolve({ fileContent: 'demo', fileName: 'fakeFile.wav', fileSize: 200, mimeType: 'audio/wav' }); }); }); this.captureImage = stub(); this.captureImage.callsFake(options => { return new Promise(resolve => { resolve({ fileContent: 'demo', fileName: 'fakeFile.png', fileSize: 200, mimeType: 'image/png' }); }); }); this.captureVideo = stub(); this.captureVideo.callsFake(() => { return new Promise(resolve => { resolve({ fileContent: 'demo', fileName: 'fakeFile.mp4', fileSize: 2000, mimeType: 'video/mp4' }); }); }); this.getBarcodeValue = stub(); this.getBarcodeValue.callsFake(() => { return new Promise(resolve => { resolve('SHKO-ONLINE'); }); }); this.getCurrentPosition = 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 = 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' }]); }); }); } }