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 18const warnMessage = 19 ' interface mocked in the Previewer. How this interface works on the' + 20 ' Previewer may be different from that on a real device.' 21 22export const ResizeDirection = { 23 LEFT: 0, 24 RIGHT: 1, 25 UP: 2, 26 DOWN: 3, 27 LEFT_UP: 4, 28 LEFT_DOWN: 5, 29 RIGHT_UP: 6, 30 RIGHT_DOWN: 7 31} 32 33export const MatchPattern = { 34 EQUALS: 0, 35 CONTAINS: 1, 36 STARTS_WITH: 2, 37 ENDS_WITH: 3 38} 39 40export const WindowMode = { 41 FULLSCREEN: 0, 42 PRIMARY: 1, 43 SECONDARY: 2, 44 FLOATING: 3 45} 46 47export const Point = { 48 X: '[PC Preview] unknown X', 49 Y: '[PC Preview] unknown Y' 50} 51 52export const Rect = { 53 leftX: '[PC Preview] unknown leftX', 54 topY: '[PC Preview] unknown topY', 55 rightX: '[PC Preview] unknown rightX', 56 bottomY: '[PC Preview] unknown bottomY' 57} 58 59export const WindowFilter = { 60 bundleName: '[PC Preview] unknown bundleName', 61 title: '[PC Preview] unknown title', 62 focused: '[PC Preview] unknown focused', 63 actived: '[PC Preview] unknown actived' 64} 65 66const ByClass = class ByMock { 67 constructor() { 68 console.warn('uitest.By.constructor' + warnMessage); 69 this.id = function(...args) { 70 console.warn('uitest.By.id' + warnMessage) 71 return new ByClass() 72 }; 73 this.text = function(...args) { 74 console.warn('uitest.By.text' + warnMessage) 75 return new ByClass() 76 }; 77 this.key = function(...args) { 78 console.warn('uitest.By.key' + warnMessage) 79 return new ByClass() 80 }; 81 this.type = function(...args) { 82 console.warn('uitest.By.type' + warnMessage) 83 return new ByClass() 84 }; 85 this.enabled = function(...args) { 86 console.warn('uitest.By.enabled' + warnMessage) 87 return new ByClass() 88 }; 89 this.focused = function(...args) { 90 console.warn('uitest.By.focused' + warnMessage) 91 return new ByClass() 92 }; 93 this.selected = function(...args) { 94 console.warn('uitest.By.selected' + warnMessage) 95 return new ByClass() 96 }; 97 this.clickable = function(...args) { 98 console.warn('uitest.By.clickable' + warnMessage) 99 return new ByClass() 100 }; 101 this.enabled = function(...args) { 102 console.warn('uitest.By.enabled' + warnMessage) 103 return new ByClass() 104 }; 105 this.longClickable = function(...args) { 106 console.warn('uitest.By.longClickable' + warnMessage) 107 return new ByClass() 108 }; 109 this.scrollable = function(...args) { 110 console.warn('uitest.By.scrollable' + warnMessage) 111 return new ByClass() 112 }; 113 this.checkable = function(...args) { 114 console.warn('uitest.By.checkable' + warnMessage) 115 return new ByClass() 116 }; 117 this.checked = function(...args) { 118 console.warn('uitest.By.checked' + warnMessage) 119 return new ByClass() 120 }; 121 this.isBefore = function(...args) { 122 console.warn('uitest.By.isBefore' + warnMessage) 123 return new ByClass() 124 }; 125 this.isAfter = function(...args) { 126 console.warn('uitest.By.isAfter' + warnMessage) 127 return new ByClass() 128 }; 129 } 130} 131 132const UiDriverClass = class UiDriverMock { 133 constructor() { 134 console.warn('uitest.UiDriver.constructor' + warnMessage); 135 this.delayMs = function(...args) { 136 console.warn('uitest.UiDriver.delayMs' + warnMessage) 137 return new Promise((resolve) => { 138 resolve() 139 }); 140 }; 141 this.findComponent = function(...args) { 142 console.warn('uitest.UiDriver.findComponent' + warnMessage) 143 return new Promise((resolve) => { 144 resolve(new UiComponentClass()) 145 }); 146 }; 147 this.findWindow = function(...args) { 148 console.warn('uitest.UiDriver.findWindow' + warnMessage) 149 return new Promise((resolve) => { 150 resolve(new UiWindowClass()) 151 }); 152 }; 153 this.findComponents = function(...args) { 154 console.warn('uitest.UiDriver.findComponents' + warnMessage) 155 return new Promise((resolve) => { 156 resolve(new Array(new UiComponentClass())) 157 }); 158 }; 159 this.waitForComponent = function(...args) { 160 console.warn('uitest.UiDriver.waitForComponent' + warnMessage) 161 return new Promise((resolve) => { 162 resolve(new UiComponentClass()) 163 }); 164 }; 165 this.screenCap = function(...args) { 166 console.warn('uitest.UiDriver.screenCap' + warnMessage) 167 return new Promise((resolve) => { 168 resolve(paramMock.paramBooleanMock) 169 }); 170 }; 171 this.assertComponentExist = function(...args) { 172 console.warn('uitest.UiDriver.assertComponentExist' + warnMessage) 173 return new Promise((resolve) => { 174 resolve() 175 }); 176 }; 177 this.pressBack = function(...args) { 178 console.warn('uitest.UiDriver.pressBack' + warnMessage) 179 return new Promise((resolve) => { 180 resolve() 181 }); 182 }; 183 this.triggerKey = function(...args) { 184 console.warn('uitest.UiDriver.triggerKey' + warnMessage) 185 return new Promise((resolve) => { 186 resolve() 187 }); 188 }; 189 this.triggerCombineKeys = function(...args) { 190 console.warn('uitest.UiDriver.triggerCombineKeys' + warnMessage) 191 return new Promise((resolve) => { 192 resolve() 193 }); 194 }; 195 this.click = function(...args) { 196 console.warn('uitest.UiDriver.click' + warnMessage) 197 return new Promise((resolve) => { 198 resolve() 199 }); 200 }; 201 this.longClick = function(...args) { 202 console.warn('uitest.UiDriver.longClick' + warnMessage) 203 return new Promise((resolve) => { 204 resolve() 205 }); 206 }; 207 this.doubleClick = function(...args) { 208 console.warn('uitest.UiDriver.doubleClick' + warnMessage) 209 return new Promise((resolve) => { 210 resolve() 211 }); 212 }; 213 this.swipe = function(...args) { 214 console.warn('uitest.UiDriver.swipe' + warnMessage) 215 return new Promise((resolve) => { 216 resolve() 217 }); 218 }; 219 this.drag = function(...args) { 220 console.warn('uitest.UiDriver.drag' + warnMessage) 221 return new Promise((resolve) => { 222 resolve() 223 }); 224 }; 225 } 226} 227 228UiDriverClass.create = function () { 229 console.warn('uitest.UiDriver.create' + warnMessage) 230 return new UiDriverClass() 231} 232 233const UiComponentClass = class UiComponentMock { 234 constructor() { 235 console.warn('uitest.UiComponent.constructor' + warnMessage); 236 this.getId = function(...args) { 237 console.warn('uitest.UiComponent.getId' + warnMessage) 238 return new Promise((resolve) => { 239 resolve(paramMock.paramNumberMock) 240 }); 241 }; 242 this.getText = function(...args) { 243 console.warn('uitest.UiComponent.getText' + warnMessage) 244 return new Promise((resolve) => { 245 resolve(paramMock.paramStringMock) 246 }); 247 }; 248 this.getKey = function(...args) { 249 console.warn('uitest.UiComponent.getKey' + warnMessage) 250 return new Promise((resolve) => { 251 resolve(paramMock.paramStringMock) 252 }); 253 }; 254 this.getType = function(...args) { 255 console.warn('uitest.UiComponent.getType' + warnMessage) 256 return new Promise((resolve) => { 257 resolve(paramMock.paramStringMock) 258 }); 259 }; 260 this.isEnabled = function(...args) { 261 console.warn('uitest.UiComponent.isEnabled' + warnMessage) 262 return new Promise((resolve) => { 263 resolve(paramMock.paramBooleanMock) 264 }); 265 }; 266 this.isFocused = function(...args) { 267 console.warn('uitest.UiComponent.isFocused' + warnMessage) 268 return new Promise((resolve) => { 269 resolve(paramMock.paramBooleanMock) 270 }); 271 }; 272 this.isSelected = function(...args) { 273 console.warn('uitest.UiComponent.isSelected' + warnMessage) 274 return new Promise((resolve) => { 275 resolve(paramMock.paramBooleanMock) 276 }); 277 }; 278 this.isClickable = function(...args) { 279 console.warn('uitest.UiComponent.isClickable' + warnMessage) 280 return new Promise((resolve) => { 281 resolve(paramMock.paramBooleanMock) 282 }); 283 }; 284 this.isLongClickable = function(...args) { 285 console.warn('uitest.UiComponent.isLongClickable' + warnMessage) 286 return new Promise((resolve) => { 287 resolve(paramMock.paramBooleanMock) 288 }); 289 }; 290 this.isScrollable = function(...args) { 291 console.warn('uitest.UiComponent.isScrollable' + warnMessage) 292 return new Promise((resolve) => { 293 resolve(paramMock.paramBooleanMock) 294 }); 295 }; 296 this.isCheckable = function(...args) { 297 console.warn('uitest.UiComponent.isCheckable' + warnMessage) 298 return new Promise((resolve) => { 299 resolve(paramMock.paramBooleanMock) 300 }); 301 }; 302 this.isChecked = function(...args) { 303 console.warn('uitest.UiComponent.isChecked' + warnMessage) 304 return new Promise((resolve) => { 305 resolve(paramMock.paramBooleanMock) 306 }); 307 }; 308 this.getBounds = function(...args) { 309 console.warn('uitest.UiComponent.getBounds' + warnMessage) 310 return new Promise((resolve) => { 311 resolve(Rect) 312 }); 313 }; 314 this.getBoundsCenter = function(...args) { 315 console.warn('uitest.UiComponent.getBoundsCenter' + warnMessage) 316 return new Promise((resolve) => { 317 resolve(Point) 318 }); 319 }; 320 this.click = function(...args) { 321 console.warn('uitest.UiComponent.click' + warnMessage) 322 return new Promise((resolve) => { 323 resolve() 324 }); 325 }; 326 this.longClick = function(...args) { 327 console.warn('uitest.UiComponent.longClick' + warnMessage) 328 return new Promise((resolve) => { 329 resolve() 330 }); 331 }; 332 this.doubleClick = function(...args) { 333 console.warn('uitest.UiComponent.doubleClick' + warnMessage) 334 return new Promise((resolve) => { 335 resolve() 336 }); 337 }; 338 this.scrollToTop = function(...args) { 339 console.warn('uitest.UiComponent.scrollToTop' + warnMessage) 340 return new Promise((resolve) => { 341 resolve() 342 }); 343 }; 344 this.scrollToBottom = function(...args) { 345 console.warn('uitest.UiComponent.scrollToBottom' + warnMessage) 346 return new Promise((resolve) => { 347 resolve() 348 }); 349 }; 350 this.inputText = function(...args) { 351 console.warn('uitest.UiComponent.inputText' + warnMessage) 352 return new Promise((resolve) => { 353 resolve() 354 }); 355 }; 356 this.clearText = function(...args) { 357 console.warn('uitest.UiComponent.clearText' + warnMessage) 358 return new Promise((resolve) => { 359 resolve() 360 }); 361 }; 362 this.scrollSearch = function(...args) { 363 console.warn('uitest.UiComponent.scrollSearch' + warnMessage) 364 return new Promise((resolve) => { 365 resolve(new UiComponentClass()) 366 }); 367 }; 368 this.dragTo = function(...args) { 369 console.warn('uitest.UiComponent.dragTo' + warnMessage) 370 return new Promise((resolve) => { 371 resolve() 372 }); 373 }; 374 this.pinchOut = function(...args) { 375 console.warn('uitest.UiComponent.pinchOut' + warnMessage) 376 return new Promise((resolve) => { 377 resolve() 378 }); 379 }; 380 this.pinchIn = function(...args) { 381 console.warn('uitest.UiComponent.pinchIn' + warnMessage) 382 return new Promise((resolve) => { 383 resolve() 384 }); 385 }; 386 } 387} 388 389const UiWindowClass = class UiWindowMock { 390 constructor() { 391 console.warn('uitest.UiWindow.constructor' + warnMessage); 392 this.getBundleName = function(...args) { 393 console.warn('uitest.UiWindow.getBundleName' + warnMessage) 394 return new Promise((resolve) => { 395 resolve(paramMock.paramStringMock) 396 }); 397 }; 398 this.getBounds = function(...args) { 399 console.warn('uitest.UiWindow.getBounds' + warnMessage) 400 return new Promise((resolve) => { 401 resolve(Rect) 402 }); 403 }; 404 this.getTitle = function(...args) { 405 console.warn('uitest.UiWindow.getTitle' + warnMessage) 406 return new Promise((resolve) => { 407 resolve(paramMock.paramStringMock) 408 }); 409 }; 410 this.getWindowMode = function(...args) { 411 console.warn('uitest.UiWindow.getWindowMode' + warnMessage) 412 return new Promise((resolve) => { 413 resolve(WindowMode) 414 }); 415 }; 416 this.isFocused = function(...args) { 417 console.warn('uitest.UiWindow.isFocused' + warnMessage) 418 return new Promise((resolve) => { 419 resolve(paramMock.paramBooleanMock) 420 }); 421 }; 422 this.isActived = function(...args) { 423 console.warn('uitest.UiWindow.isActived' + warnMessage) 424 return new Promise((resolve) => { 425 resolve(paramMock.paramBooleanMock) 426 }); 427 }; 428 this.focus = function(...args) { 429 console.warn('uitest.UiWindow.focus' + warnMessage) 430 return new Promise((resolve) => { 431 resolve(paramMock.paramBooleanMock) 432 }); 433 }; 434 this.moveTo = function(...args) { 435 console.warn('uitest.UiWindow.moveTo' + warnMessage) 436 return new Promise((resolve) => { 437 resolve(paramMock.paramBooleanMock) 438 }); 439 }; 440 this.resize = function(...args) { 441 console.warn('uitest.UiWindow.resize' + warnMessage) 442 return new Promise((resolve) => { 443 resolve(paramMock.paramBooleanMock) 444 }); 445 }; 446 this.split = function(...args) { 447 console.warn('uitest.UiWindow.split' + warnMessage) 448 return new Promise((resolve) => { 449 resolve(paramMock.paramBooleanMock) 450 }); 451 }; 452 this.maximize = function(...args) { 453 console.warn('uitest.UiWindow.maximize' + warnMessage) 454 return new Promise((resolve) => { 455 resolve(paramMock.paramBooleanMock) 456 }); 457 }; 458 this.resume = function(...args) { 459 console.warn('uitest.UiWindow.resume' + warnMessage) 460 return new Promise((resolve) => { 461 resolve(paramMock.paramBooleanMock) 462 }); 463 }; 464 this.minimize = function(...args) { 465 console.warn('uitest.UiWindow.minimize' + warnMessage) 466 return new Promise((resolve) => { 467 resolve(paramMock.paramBooleanMock) 468 }); 469 }; 470 this.close = function(...args) { 471 console.warn('uitest.UiWindow.close' + warnMessage) 472 return new Promise((resolve) => { 473 resolve(paramMock.paramBooleanMock) 474 }); 475 }; 476 }; 477} 478 479export function mockUiTest() { 480 const module = { 481 ResizeDirection: ResizeDirection, 482 MatchPattern: MatchPattern, 483 WindowMode: WindowMode, 484 Point: Point, 485 Rect: Rect, 486 WindowFilter: WindowFilter, 487 BY: new ByClass(), 488 UiDriver: UiDriverClass, 489 UiComponent: UiComponentClass, 490 UiWindow: UiWindowClass 491 }; 492 return module 493}