| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
import testUtilsDom from "@web/../tests/legacy_tests/helpers/test_utils_dom"; |
| 11 |
import testUtilsFields from "@web/../tests/legacy_tests/helpers/test_utils_fields"; |
| 12 |
import testUtilsMock from "@web/../tests/legacy_tests/helpers/test_utils_mock"; |
| 13 |
|
| 14 |
function deprecated(fn, type) { |
| 15 |
return function () { |
| 16 |
const msg = `Helper 'testUtils.${fn.name}' is deprecated. ` + |
| 17 |
`Please use 'testUtils.${type}.${fn.name}' instead.`; |
| 18 |
console.warn(msg); |
| 19 |
return fn.apply(this, arguments); |
| 20 |
}; |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
function makeTestPromise() { |
| 30 |
let resolve; |
| 31 |
let reject; |
| 32 |
const promise = new Promise(function (_resolve, _reject) { |
| 33 |
resolve = _resolve; |
| 34 |
reject = _reject; |
| 35 |
}); |
| 36 |
promise.resolve = function () { |
| 37 |
resolve.apply(null, arguments); |
| 38 |
return promise; |
| 39 |
}; |
| 40 |
promise.reject = function () { |
| 41 |
reject.apply(null, arguments); |
| 42 |
return promise; |
| 43 |
}; |
| 44 |
return promise; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
function makeTestPromiseWithAssert(assert, str) { |
| 58 |
const prom = makeTestPromise(); |
| 59 |
prom.then(() => assert.step('ok ' + str)).catch(function () { }); |
| 60 |
prom.catch(() => assert.step('ko ' + str)); |
| 61 |
return prom; |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
async function nextMicrotaskTick() { |
| 71 |
return Promise.resolve(); |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
export async function nextTick() { |
| 83 |
return testUtilsDom.returnAfterNextAnimationFrame(); |
| 84 |
} |
| 85 |
|
| 86 |
export const mock = { |
| 87 |
intercept: testUtilsMock.intercept, |
| 88 |
patch: testUtilsMock.patch, |
| 89 |
patchDate: testUtilsMock.patchDate, |
| 90 |
unpatch: testUtilsMock.unpatch, |
| 91 |
getView: testUtilsMock.getView, |
| 92 |
}; |
| 93 |
|
| 94 |
export const dom = { |
| 95 |
dragAndDrop: testUtilsDom.dragAndDrop, |
| 96 |
find: testUtilsDom.findItem, |
| 97 |
click: testUtilsDom.click, |
| 98 |
clickFirst: testUtilsDom.clickFirst, |
| 99 |
triggerEvents: testUtilsDom.triggerEvents, |
| 100 |
triggerEvent: testUtilsDom.triggerEvent, |
| 101 |
}; |
| 102 |
|
| 103 |
export const fields = { |
| 104 |
editInput: testUtilsFields.editInput, |
| 105 |
editAndTrigger: testUtilsFields.editAndTrigger, |
| 106 |
triggerKeydown: testUtilsFields.triggerKeydown, |
| 107 |
}; |
| 108 |
|
| 109 |
export default { |
| 110 |
mock, |
| 111 |
dom, |
| 112 |
fields, |
| 113 |
|
| 114 |
makeTestPromise: makeTestPromise, |
| 115 |
makeTestPromiseWithAssert: makeTestPromiseWithAssert, |
| 116 |
nextMicrotaskTick: nextMicrotaskTick, |
| 117 |
nextTick: nextTick, |
| 118 |
|
| 119 |
|
| 120 |
dragAndDrop: deprecated(testUtilsDom.dragAndDrop, 'dom'), |
| 121 |
getView: deprecated(testUtilsMock.getView, 'mock'), |
| 122 |
intercept: deprecated(testUtilsMock.intercept, 'mock'), |
| 123 |
openDatepicker: deprecated(testUtilsDom.openDatepicker, 'dom'), |
| 124 |
patch: deprecated(testUtilsMock.patch, 'mock'), |
| 125 |
patchDate: deprecated(testUtilsMock.patchDate, 'mock'), |
| 126 |
unpatch: deprecated(testUtilsMock.unpatch, 'mock'), |
| 127 |
}; |