UNPKG

@shko.online/componentframework-mock

Version:

Mocking library to help with testing PowerApps Component Framework Components

100 lines (98 loc) 2.92 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(() => Promise.resolve({ fileContent: 'demo', fileName: 'fakeFile.wav', fileSize: 200, mimeType: 'audio/wav' })); this.captureImage = (0, _sinon.stub)(); this.captureImage.callsFake(options => { options = options ?? { allowEdit: false, width: 1024, height: 768, preferFrontCamera: false, quality: 100 }; return Promise.resolve({ fileContent: 'demo', fileName: 'fakeFile.png', fileSize: options.width * options.height * 4, // Rough estimation of file size based on dimensions (RGBA) mimeType: 'image/png' }); }); this.captureVideo = (0, _sinon.stub)(); this.captureVideo.callsFake(() => Promise.resolve({ fileContent: 'demo', fileName: 'fakeFile.mp4', fileSize: 2000, mimeType: 'video/mp4' })); this.getBarcodeValue = (0, _sinon.stub)(); this.getBarcodeValue.callsFake(() => Promise.resolve('SHKO-ONLINE')); this.getCurrentPosition = (0, _sinon.stub)(); this.getCurrentPosition.callsFake(() => Promise.resolve({ coords: { accuracy: 141, latitude: 41.3415145, longitude: 19.7769355, altitude: 0, altitudeAccuracy: 0, heading: 0, speed: 0 }, timestamp: new Date() })); this.pickFile = (0, _sinon.stub)(); this.pickFile.callsFake(options => { return new Promise((resolve, reject) => { const configuredOptions = options || { accept: 'image' }; if (configuredOptions.accept === 'image') { return resolve([{ fileContent: 'demo', fileName: 'fakeFile.png', fileSize: 200, mimeType: 'image/png' }]); } else if (configuredOptions.accept === 'audio') { return resolve([{ fileContent: 'demo', fileName: 'fakeFile.wav', fileSize: 200, mimeType: 'audio/wav' }]); } else if (configuredOptions.accept === 'video') { return resolve([{ fileContent: 'demo', fileName: 'fakeFile.mp4', fileSize: 2000, mimeType: 'video/mp4' }]); } return reject(new Error('Unsupported file type')); }); }); } } exports.DeviceMock = DeviceMock;