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 mockList() { 19 const paramList = { 20 paramAnyMock: '[PC Preview] unknow any', 21 paramListMock: '[PC Preview] unknow List', 22 paramIterMock: '[PC Preview] unknow IterableIterator' 23 } 24 const ListClass = class List { 25 constructor(...args) { 26 console.warn('util.List interface mocked in the Previewer. How this interface works on the Previewer' + 27 ' may be different from that on a real device.'); 28 this.length = '[PC preview] unknow length'; 29 this.add = function (...args) { 30 console.warn("List.add interface mocked in the Previewer. How this interface works on the Previewer" + 31 " may be different from that on a real device.") 32 return paramMock.paramBooleanMock; 33 }; 34 this.insert = function (...args) { 35 console.warn("List.insert interface mocked in the Previewer. How this interface works on the Previewer" + 36 " may be different from that on a real device.") 37 }; 38 this.get = function (...args) { 39 console.warn("List.get interface mocked in the Previewer. How this interface works on the Previewer" + 40 " may be different from that on a real device.") 41 return paramList.paramAnyMock; 42 }; 43 this.has = function (...args) { 44 console.warn("List.has interface mocked in the Previewer. How this interface works on the Previewer" + 45 " may be different from that on a real device.") 46 return paramMock.paramBooleanMock; 47 }; 48 this.getIndexOf = function (...args) { 49 console.warn("List.getIndexOf interface mocked in the Previewer. How this interface works on the Previewer" + 50 " may be different from that on a real device.") 51 return paramMock.paramNumberMock; 52 }; 53 this.removeByIndex = function (...args) { 54 console.warn("List.removeByIndex interface mocked in the Previewer. How this interface works on the Previewer" + 55 " may be different from that on a real device.") 56 return paramList.paramAnyMock; 57 }; 58 this.remove = function (...args) { 59 console.warn("List.remove interface mocked in the Previewer. How this interface works on the Previewer" + 60 " may be different from that on a real device.") 61 return paramMock.paramBooleanMock; 62 }; 63 this.getLastIndexOf = function (...args) { 64 console.warn("List.getLastIndexOf interface mocked in the Previewer. How this interface works on the Previewer" + 65 " may be different from that on a real device.") 66 return paramMock.paramNumberMock; 67 }; 68 this.getFirst = function (...args) { 69 console.warn("List.getFirst interface mocked in the Previewer. How this interface works on the Previewer" + 70 " may be different from that on a real device.") 71 return paramList.paramAnyMock; 72 }; 73 this.getLast = function (...args) { 74 console.warn("List.getLast interface mocked in the Previewer. How this interface works on the Previewer" + 75 " may be different from that on a real device.") 76 return paramList.paramAnyMock; 77 }; 78 this.set = function (...args) { 79 console.warn("List.set interface mocked in the Previewer. How this interface works on the Previewer" + 80 " may be different from that on a real device.") 81 return paramList.paramAnyMock; 82 }; 83 this.equal = function (...args) { 84 console.warn("List.equal interface mocked in the Previewer. How this interface works on the Previewer" + 85 " may be different from that on a real device.") 86 return paramMock.paramNumberMock; 87 }; 88 this.forEach = function (...args) { 89 console.warn("List.forEach interface mocked in the Previewer. How this interface works on the Previewer" + 90 " may be different from that on a real device.") 91 if (typeof args[0] === 'function') { 92 args[0].call(this, paramMock.businessErrorMock) 93 } 94 }; 95 this.sort = function (...args) { 96 console.warn("List.sort interface mocked in the Previewer. How this interface works on the Previewer" + 97 " may be different from that on a real device.") 98 if (typeof args[0] === 'function') { 99 args[0].call(this, paramMock.businessErrorMock) 100 } 101 }; 102 this.clear = function (...args) { 103 console.warn("List.clear interface mocked in the Previewer. How this interface works on the Previewer" + 104 " may be different from that on a real device.") 105 }; 106 this.getSubList = function (...args) { 107 console.warn("List.getSubList interface mocked in the Previewer. How this interface works on the Previewer" + 108 " may be different from that on a real device.") 109 return paramList.paramListMock; 110 }; 111 this.replaceAllElements = function (...args) { 112 console.warn("List.replaceAllElements interface mocked in the Previewer. How this interface works on the Previewer" + 113 " may be different from that on a real device.") 114 if (typeof args[0] === 'function') { 115 args[0].call(this, paramMock.businessErrorMock, paramLinkedList.paramAnyMock) 116 } 117 }; 118 this.convertToArray = function (...args) { 119 console.warn("List.convertToArray interface mocked in the Previewer. How this interface works on the Previewer" + 120 " may be different from that on a real device.") 121 return paramMock.paramArrayMock; 122 }; 123 this.isEmpty = function (...args) { 124 console.warn("LinkedList.isEmpty interface mocked in the Previewer. How this interface works on the Previewer" + 125 " may be different from that on a real device.") 126 return paramMock.paramBooleanMock; 127 }; 128 this[Symbol.iterator] = function (...args) { 129 console.warn("List.[Symbol.iterator] interface mocked in the Previewer. How this interface works on the Previewer" + 130 " may be different from that on a real device.") 131 let index = 0; 132 const IteratorMock = { 133 next: () => { 134 if (index < 1) { 135 index++; 136 return { 137 value: paramList.paramAnyMock, 138 done: false 139 }; 140 } else { 141 return { 142 done: true 143 }; 144 } 145 } 146 }; 147 return IteratorMock; 148 } 149 } 150 } 151 return ListClass; 152}