show-toast.test.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  2. const isAndroid = platformInfo.startsWith('android')
  3. const isIOS = platformInfo.startsWith('ios')
  4. const isHarmony = platformInfo.startsWith('harmony')
  5. const isApp = isAndroid || isIOS || isHarmony
  6. const isWeb = platformInfo.startsWith('web')
  7. describe('API-toast', () => {
  8. let page;
  9. const screeShotParams = {
  10. deviceShot: true,
  11. fullPage: true
  12. }
  13. beforeAll(async () => {
  14. page = await program.reLaunch('/pages/API/show-toast/show-toast')
  15. await page.waitFor("view");
  16. if (isApp) {
  17. const windowInfo = await program.callUniMethod('getWindowInfo');
  18. // android 端 app-webview 时顶部安全区高度为0,所以统一设置为60
  19. const topSafeArea = windowInfo.safeAreaInsets.top;
  20. screeShotParams.area = {
  21. x: 0,
  22. y: topSafeArea + 44
  23. }
  24. }
  25. });
  26. async function toScreenshot(imgName) {
  27. const image = await program.screenshot(screeShotParams);
  28. expect(image).toSaveImageSnapshot({customSnapshotIdentifier() {
  29. return imgName
  30. }})
  31. await page.waitFor(500);
  32. }
  33. it("onload-toast-test", async () => {
  34. await toScreenshot('toast-onload')
  35. })
  36. it("icon-toast-test", async () => {
  37. const icons = await page.$$('.radio-icon')
  38. for (let i = 0; i < icons.length; i++) {
  39. await icons[i].tap()
  40. const iconText = await icons[i].text()
  41. await page.callMethod('toast1Tap')
  42. await page.waitFor(100);
  43. await toScreenshot(`${iconText}-toast`)
  44. }
  45. })
  46. it("icon=none-mask=true-toast-test", async () => {
  47. await page.setData({maskSelect: true})
  48. await page.callMethod('toast3Tap')
  49. await page.waitFor(300);
  50. await toScreenshot('icon=none-mask=true-toast-image')
  51. })
  52. it("image-toast-test", async () => {
  53. await page.setData({imageSelect: true})
  54. await page.waitFor(300);
  55. await page.callMethod('toast1Tap')
  56. await page.waitFor(300);
  57. await toScreenshot('toast-image')
  58. })
  59. it("duration-toast-test", async () => {
  60. await page.setData({intervalSelect: 4000})
  61. await page.callMethod('toast1Tap')
  62. await page.waitFor(2000);
  63. await toScreenshot('toast-duration-2000')
  64. await page.waitFor(1000);
  65. await page.callMethod('hideToast')
  66. await page.waitFor(300);
  67. await toScreenshot('toast-duration-end')
  68. })
  69. if(isWeb){
  70. return
  71. }
  72. it("position-toast-test", async () => {
  73. const positions = await page.$$('.radio-position')
  74. for (let i = 0; i < positions.length; i++) {
  75. await positions[i].tap()
  76. const positionsText = await positions[i].attribute('value')
  77. await page.callMethod('toast2Tap')
  78. await page.waitFor(100);
  79. await toScreenshot(`toast-position-${positionsText}`)
  80. }
  81. })
  82. });