show-action-sheet.test.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. const isMP = platformInfo.startsWith('mp')
  8. const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true'
  9. describe('showActionSheet', () => {
  10. let topSafeArea = 0;
  11. let page;
  12. let screenShotOptions = {};
  13. async function showActionSheet(page) {
  14. const btn = await page.$('#btn-action-sheet-show')
  15. await btn.tap()
  16. await page.waitFor(1000);
  17. }
  18. async function screenshot() {
  19. const image = await program.screenshot(screenShotOptions);
  20. expect(image).toSaveImageSnapshot();
  21. }
  22. beforeAll(async () => {
  23. page = await program.reLaunch('/pages/tabBar/API')
  24. await page.waitFor('view');
  25. const windowInfo = await program.callUniMethod('getWindowInfo');
  26. // android 端 app-webview 时顶部安全区高度为0,所以统一设置为60
  27. topSafeArea = windowInfo.safeAreaInsets.top;
  28. page = await program.navigateTo('/pages/API/show-action-sheet/show-action-sheet')
  29. await page.waitFor('view');
  30. if (isApp && !isAppWebView) {
  31. if(isAndroid || isIos){
  32. await page.callMethod('setThemeAuto')
  33. }
  34. screenShotOptions = {
  35. deviceShot: true,
  36. area: {
  37. x: 0,
  38. y: topSafeArea + 44
  39. },
  40. }
  41. } else if (isWeb){
  42. screenShotOptions = {
  43. fullPage: true
  44. }
  45. }
  46. });
  47. it("onload showActionSheet", async () => {
  48. await page.waitFor(isWeb ? 3000 : 1000);
  49. await screenshot();
  50. // 非交互关闭应触发 fail 回调
  51. if (!isMP) {
  52. const originLifeCycleNum = await page.callMethod('getLifeCycleNum');
  53. await program.navigateBack();
  54. await page.waitFor(1000);
  55. page = await program.navigateTo('/pages/API/show-action-sheet/show-action-sheet')
  56. const newLifeCycleNum = await page.callMethod('getLifeCycleNum');
  57. expect(newLifeCycleNum).toBe(originLifeCycleNum + 2);
  58. }
  59. })
  60. it("有标题", async () => {
  61. await page.setData({
  62. showErrorToast:false,
  63. current: 0,
  64. })
  65. await showActionSheet(page);
  66. await screenshot();
  67. })
  68. it("有标题 长内容", async () => {
  69. await page.setData({
  70. itemContentLarge:true,
  71. })
  72. await showActionSheet(page);
  73. await screenshot();
  74. })
  75. it("有标题 超过6个item", async () => {
  76. await page.setData({
  77. itemContentLarge:false,
  78. itemNumLargeSelect:true,
  79. })
  80. await showActionSheet(page);
  81. await screenshot();
  82. })
  83. it("有标题 长内容 自定义 itemColor", async () => {
  84. await page.setData({
  85. itemContentLarge: true,
  86. itemNumLargeSelect: false,
  87. itemColorCustom: true,
  88. })
  89. await showActionSheet(page);
  90. await screenshot();
  91. })
  92. it("无标题", async () => {
  93. await page.setData({
  94. current: 1,
  95. itemContentLarge:false,
  96. itemColorCustom:false,
  97. })
  98. await showActionSheet(page);
  99. await screenshot();
  100. })
  101. it("长标题", async () => {
  102. await page.setData({
  103. current: 2,
  104. })
  105. await showActionSheet(page);
  106. await screenshot();
  107. })
  108. if (!isMP) {
  109. it("custom titleColor cancelText cancelColor backgroundColor", async () => {
  110. await page.setData({
  111. titleColorCustom: true,
  112. cancelTextCustom: true,
  113. cancelColorCustom: true,
  114. backgroundColorCustom: true,
  115. })
  116. await showActionSheet(page);
  117. await page.waitFor(1000)
  118. await screenshot();
  119. })
  120. }
  121. it("showActionSheet 并在回调中再次 showActionSheet", async () => {
  122. await page.callMethod('showActionSheetAndShowAgainInCallback')
  123. await page.waitFor(1000);
  124. await screenshot();
  125. if (isApp) {
  126. await program.tap({
  127. x: 200,
  128. y: 700,
  129. })
  130. } else if (isWeb) {
  131. await page.callMethod('closeWebActionSheet')
  132. }
  133. await page.waitFor(1000);
  134. await screenshot();
  135. })
  136. if (!isMP) {
  137. it("hideActionSheet", async () => {
  138. await page.callMethod('hideActionSheet')
  139. await page.waitFor(1000);
  140. await screenshot();
  141. })
  142. }
  143. afterAll(async () => {
  144. if(isApp && !isAppWebView){
  145. await page.callMethod('resetTheme')
  146. }
  147. });
  148. });