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