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 } 51 [Symbol.iterator]() { 52 console.warn("Queue.[Symbol.iterator] interface mocked in the Previewer. How this interface works on the Previewer" + 53 " may be different from that on a real device.") 54 let index = 0; 55 const IteratorMock = { 56 next: () => { 57 if (index < 1) { 58 index++; 59 return { 60 value: paramQueue.paramAnyMock, 61 done: false 62 }; 63 } else { 64 return { 65 done: true 66 }; 67 } 68 } 69 }; 70 return IteratorMock; 71 } 72 } 73 return QueueClass; 74}