1/* 2 * Copyright (c) 2021 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 mockTag() { 19 const NfcATagMock = { 20 getTagInfo: function (...args) { 21 console.warn("NfcATag.getTagInfo interface mocked in the Previewer." + 22 "How this interface works on the Previewer may be different from that on a real device.") 23 return TagInfoMock; 24 }, 25 connectTag: function (...args) { 26 console.warn("NfcATag.connectTag interface mocked in the Previewer." + 27 "How this interface works on the Previewer may be different from that on a real device.") 28 return paramMock.paramBooleanMock; 29 }, 30 reset: function (...args) { 31 console.warn("NfcATag.reset interface mocked in the Previewer." + 32 "How this interface works on the Previewer may be different from that on a real device.") 33 }, 34 isTagConnected: function (...args) { 35 console.warn("NfcATag.isTagConnected interface mocked in the Previewer." + 36 "How this interface works on the Previewer may be different from that on a real device.") 37 return paramMock.paramBooleanMock; 38 }, 39 setSendDataTimeout: function (...args) { 40 console.warn("NfcATag.setSendDataTimeout interface mocked in the Previewer." + 41 "How this interface works on the Previewer may be different from that on a real device.") 42 return paramMock.paramBooleanMock; 43 }, 44 getSendDataTimeout: function (...args) { 45 console.warn("NfcATag.getSendDataTimeout interface mocked in the Previewer." + 46 "How this interface works on the Previewer may be different from that on a real device.") 47 return paramMock.paramNumberMock; 48 }, 49 sendData: function (...args) { 50 console.warn("NfcATag.sendData interface mocked in the Previewer." + 51 "How this interface works on the Previewer may be different from that on a real device.") 52 const len = args.length 53 if (typeof args[len - 1] === 'function') { 54 args[len - 1].call(this, paramMock.businessErrorMock, [paramMock.paramNumberMock]); 55 } else { 56 return new Promise((resolve, reject) => { 57 resolve([paramMock.paramNumberMock]); 58 }) 59 } 60 }, 61 getMaxSendLength: function (...args) { 62 console.warn("NfcATag.getMaxSendLength interface mocked in the Previewer." + 63 "How this interface works on the Previewer may be different from that on a real device.") 64 return paramMock.paramNumberMock; 65 }, 66 getSak: function (...args) { 67 console.warn("NfcATag.getSak interface mocked in the Previewer." + 68 "How this interface works on the Previewer may be different from that on a real device.") 69 return paramMock.paramNumberMock; 70 }, 71 getAtqa: function () { 72 console.warn("NfcATag.getAtqa interface mocked in the Previewer." + 73 "How this interface works on the Previewer may be different from that on a real device.") 74 return [paramMock.paramNumberMock]; 75 }, 76 } 77 const NfcBTagMock = { 78 getTagInfo: function (...args) { 79 console.warn("NfcBTag.getTagInfo interface mocked in the Previewer." + 80 "How this interface works on the Previewer may be different from that on a real device.") 81 return TagInfoMock; 82 }, 83 connectTag: function (...args) { 84 console.warn("NfcBTag.connectTag interface mocked in the Previewer." + 85 "How this interface works on the Previewer may be different from that on a real device.") 86 return paramMock.paramBooleanMock; 87 }, 88 reset: function (...args) { 89 console.warn("NfcBTag.reset interface mocked in the Previewer." + 90 "How this interface works on the Previewer may be different from that on a real device.") 91 }, 92 isTagConnected: function (...args) { 93 console.warn("NfcBTag.isTagConnected interface mocked in the Previewer." + 94 "How this interface works on the Previewer may be different from that on a real device.") 95 return paramMock.paramBooleanMock; 96 }, 97 setSendDataTimeout: function (...args) { 98 console.warn("NfcBTag.setSendDataTimeout interface mocked in the Previewer." + 99 "How this interface works on the Previewer may be different from that on a real device.") 100 return paramMock.paramBooleanMock; 101 }, 102 getSendDataTimeout: function (...args) { 103 console.warn("NfcBTag.getSendDataTimeout interface mocked in the Previewer." + 104 "How this interface works on the Previewer may be different from that on a real device.") 105 return paramMock.paramNumberMock; 106 }, 107 sendData: function (...args) { 108 console.warn("NfcBTag.sendData interface mocked in the Previewer." + 109 "How this interface works on the Previewer may be different from that on a real device.") 110 const len = args.length 111 if (typeof args[len - 1] === 'function') { 112 args[len - 1].call(this, paramMock.businessErrorMock, [paramMock.paramNumberMock]); 113 } else { 114 return new Promise((resolve, reject) => { 115 resolve([paramMock.paramNumberMock]); 116 }) 117 } 118 }, 119 getMaxSendLength: function (...args) { 120 console.warn("NfcBTag.getMaxSendLength interface mocked in the Previewer." + 121 "How this interface works on the Previewer may be different from that on a real device.") 122 return paramMock.paramNumberMock; 123 }, 124 getRespAppData: function (...args) { 125 console.warn("NfcBTag.getRespAppData interface mocked in the Previewer." + 126 "How this interface works on the Previewer may be different from that on a real device.") 127 return [paramMock.paramNumberMock]; 128 }, 129 getRespProtocol: function () { 130 console.warn("NfcBTag.getRespProtocol interface mocked in the Previewer." + 131 "How this interface works on the Previewer may be different from that on a real device.") 132 return [paramMock.paramNumberMock]; 133 }, 134 } 135 const NfcFTagMock = { 136 getTagInfo: function (...args) { 137 console.warn("NfcFTag.getTagInfo interface mocked in the Previewer." + 138 "How this interface works on the Previewer may be different from that on a real device.") 139 return TagInfoMock; 140 }, 141 connectTag: function (...args) { 142 console.warn("NfcFTag.connectTag interface mocked in the Previewer." + 143 "How this interface works on the Previewer may be different from that on a real device.") 144 return paramMock.paramBooleanMock; 145 }, 146 reset: function (...args) { 147 console.warn("NfcFTag.reset interface mocked in the Previewer." + 148 "How this interface works on the Previewer may be different from that on a real device.") 149 }, 150 isTagConnected: function (...args) { 151 console.warn("NfcFTag.isTagConnected interface mocked in the Previewer." + 152 "How this interface works on the Previewer may be different from that on a real device.") 153 return paramMock.paramBooleanMock; 154 }, 155 setSendDataTimeout: function (...args) { 156 console.warn("NfcFTag.setSendDataTimeout interface mocked in the Previewer." + 157 "How this interface works on the Previewer may be different from that on a real device.") 158 return paramMock.paramBooleanMock; 159 }, 160 getSendDataTimeout: function (...args) { 161 console.warn("NfcFTag.getSendDataTimeout interface mocked in the Previewer." + 162 "How this interface works on the Previewer may be different from that on a real device.") 163 return paramMock.paramNumberMock; 164 }, 165 sendData: function (...args) { 166 console.warn("NfcFTag.sendData interface mocked in the Previewer." + 167 "How this interface works on the Previewer may be different from that on a real device.") 168 const len = args.length 169 if (typeof args[len - 1] === 'function') { 170 args[len - 1].call(this, paramMock.businessErrorMock, [paramMock.paramNumberMock]); 171 } else { 172 return new Promise((resolve, reject) => { 173 resolve([paramMock.paramNumberMock]); 174 }) 175 } 176 }, 177 getMaxSendLength: function (...args) { 178 console.warn("NfcFTag.getMaxSendLength interface mocked in the Previewer." + 179 "How this interface works on the Previewer may be different from that on a real device.") 180 return paramMock.paramNumberMock; 181 }, 182 getSystemCode: function (...args) { 183 console.warn("NfcFTag.getSystemCode interface mocked in the Previewer." + 184 "How this interface works on the Previewer may be different from that on a real device.") 185 return [paramMock.paramNumberMock]; 186 }, 187 getPmm: function () { 188 console.warn("NfcFTag.getPmm interface mocked in the Previewer." + 189 "How this interface works on the Previewer may be different from that on a real device.") 190 return [paramMock.paramNumberMock]; 191 }, 192 } 193 const NfcVTagMock = { 194 getTagInfo: function (...args) { 195 console.warn("NfcVTag.getTagInfo interface mocked in the Previewer." + 196 "How this interface works on the Previewer may be different from that on a real device.") 197 return TagInfoMock; 198 }, 199 connectTag: function (...args) { 200 console.warn("NfcVTag.connectTag interface mocked in the Previewer." + 201 "How this interface works on the Previewer may be different from that on a real device.") 202 return paramMock.paramBooleanMock; 203 }, 204 reset: function (...args) { 205 console.warn("NfcVTag.reset interface mocked in the Previewer." + 206 "How this interface works on the Previewer may be different from that on a real device.") 207 }, 208 isTagConnected: function (...args) { 209 console.warn("NfcVTag.isTagConnected interface mocked in the Previewer." + 210 "How this interface works on the Previewer may be different from that on a real device.") 211 return paramMock.paramBooleanMock; 212 }, 213 setSendDataTimeout: function (...args) { 214 console.warn("NfcVTag.setSendDataTimeout interface mocked in the Previewer." + 215 "How this interface works on the Previewer may be different from that on a real device.") 216 return paramMock.paramBooleanMock; 217 }, 218 getSendDataTimeout: function (...args) { 219 console.warn("NfcVTag.getSendDataTimeout interface mocked in the Previewer." + 220 "How this interface works on the Previewer may be different from that on a real device.") 221 return paramMock.paramNumberMock; 222 }, 223 sendData: function (...args) { 224 console.warn("NfcVTag.sendData interface mocked in the Previewer." + 225 "How this interface works on the Previewer may be different from that on a real device.") 226 const len = args.length 227 if (typeof args[len - 1] === 'function') { 228 args[len - 1].call(this, paramMock.businessErrorMock, [paramMock.paramNumberMock]); 229 } else { 230 return new Promise((resolve, reject) => { 231 resolve([paramMock.paramNumberMock]); 232 }) 233 } 234 }, 235 getMaxSendLength: function (...args) { 236 console.warn("NfcVTag.getMaxSendLength interface mocked in the Previewer." + 237 "How this interface works on the Previewer may be different from that on a real device.") 238 return paramMock.paramNumberMock; 239 }, 240 getResponseFlags: function (...args) { 241 console.warn("NfcVTag.getResponseFlags interface mocked in the Previewer." + 242 "How this interface works on the Previewer may be different from that on a real device.") 243 return paramMock.paramNumberMock 244 }, 245 getDsfId: function () { 246 console.warn("NfcVTag.getDsfId interface mocked in the Previewer." + 247 "How this interface works on the Previewer may be different from that on a real device.") 248 return paramMock.paramNumberMock 249 }, 250 } 251 const tag = { 252 getNfcATag: function (...args) { 253 console.warn("nfc.tag.getNfcATag interface mocked in the Previewer. How this interface works on the" + 254 " Previewer may be different from that on a real device.") 255 return NfcATagMock; 256 }, 257 getNfcBTag: function (...args) { 258 console.warn("nfc.tag.getNfcBTag interface mocked in the Previewer. How this interface works on the" + 259 " Previewer may be different from that on a real device.") 260 return NfcBTagMock; 261 }, 262 getNfcFTag: function (...args) { 263 console.warn("nfc.tag.getNfcFTag interface mocked in the Previewer. How this interface works on the" + 264 " Previewer may be different from that on a real device.") 265 return NfcFTagMock; 266 }, 267 getNfcVTag: function (...args) { 268 console.warn("nfc.tag.getNfcVTag interface mocked in the Previewer. How this interface works on the" + 269 " Previewer may be different from that on a real device.") 270 return NfcVTagMock; 271 }, 272 } 273 return tag 274}