1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import { paramMock } from "../utils" 17 18export function mockQueue() { 19 const paramQueue = { 20 paramAnyMock: '[PC Preview] unknow any', 21 paramIterMock: '[PC Preview] unknow IterableIterator' 22 } 23 const QueueClass = class Queue { 24 constructor(...args) { 25 console.warn('util.Queue interface mocked in the Previewer. How this interface works on the Previewer' + 26 ' may be different from that on a real device.'); 27 this.length = '[PC preview] unknow length'; 28 this.add = function (...args) { 29 console.warn("Queue.add interface mocked in the Previewer. How this interface works on the Previewer" + 30 " may be different from that on a real device.") 31 return paramMock.paramBooleanMock; 32 }; 33 this.getFirst = function (...args) { 34 console.warn("Queue.getFirst interface mocked in the Previewer. How this interface works on the Previewer" + 35 " may be different from that on a real device.") 36 return paramQueue.paramAnyMock; 37 }; 38 this.pop = function (...args) { 39 console.warn("Queue.pop interface mocked in the Previewer. How this interface works on the Previewer" + 40 " may be different from that on a real device.") 41 return paramQueue.paramAnyMock; 42 }; 43 this.forEach = function (...args) { 44 console.warn("Queue.forEach interface mocked in the Previewer. How this interface works on the Previewer" + 45 " may be different from that on a real device.") 46 if (typeof args[0] === 'function') { 47 args[0].call(this, paramMock.businessErrorMock) 48 } 49 }; 50 this[Symbol.iterator] = function (...args) { 51 console.warn("Queue.[Symbol.iterator] interface mocked in the Previewer. How this interface works on the Previewer" + 52 " may be different from that on a real device.") 53 let index = 0; 54 const IteratorMock = { 55 next: () => { 56 if (index < 1) { 57 index++; 58 return { 59 value: paramQueue.paramAnyMock, 60 done: false 61 }; 62 } else { 63 return { 64 done: true 65 }; 66 } 67 } 68 }; 69 return IteratorMock; 70 } 71 } 72 } 73 return QueueClass; 74}