• 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 mockInputConsumer() {
19  const KeyOptions = {
20    preKeys: [param.paramNumberMock],
21    finalKey: "[PC preview] unknown finalKey",
22    isFinalKeyDown: "[PC preview] unknown isFinalKeyDown",
23    finalKeyDownDuration: "[PC preview] unknown finalKeyDownDuration",
24  }
25  const EventType = ['key']
26  const inputConsumer = {
27    on: function (...args) {
28        console.warn("inputConsumer.on interface mocked in the Previewer. How this interface works on the" +
29        " Previewer may be different from that on a real device.");
30        const len = args.length;
31        if (len !== 3) {
32            console.warn("Must be three parameters");
33            return;
34        }
35        if (EventType.indexOf(args[0]) === -1) {
36            console.warn("the first parameter must be 'key'");
37            return;
38        }
39        if (typeof args[1] != 'object') {
40            console.warn("the second parameter type must be 'object'");
41            return;
42        }
43        if (typeof args[2] != 'function') {
44            console.warn("the third parameter type must be 'function'");
45            return;
46        }
47        args[2].call(this, args[1]);
48    },
49    off: function (...args) {
50        console.warn("inputConsumer.off interface mocked in the Previewer. How this interface works on the" +
51        " Previewer may be different from that on a real device.");
52        const len = args.length;
53        if (len < 2 || len > 3) {
54            console.warn("a maximum of two parameters");
55            return;
56        }
57        if (EventType.indexOf(args[0]) === -1) {
58            console.warn("first parameter must be 'key'")
59            return;
60        }
61        if (typeof args[1] != 'object') {
62            console.warn("second parameter type must be 'object'");
63            return;
64        }
65        if (len === 3) {
66            if (typeof args[2] != 'function') {
67                console.warn("the third parameter type must be 'function'");
68                return;
69            }
70        }
71    }
72  }
73  return inputConsumer;
74}