onLoad.test.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. jest.setTimeout(20000);
  2. const PAGE_PATH = "/pages/API/navigator/new-page/onLoad";
  3. const INTERMEDIATE_PAGE_PATH = "/pages/API/navigator/new-page/new-page-1";
  4. const TARGET_PAGE_PATH = "/pages/API/navigator/new-page/new-page-3";
  5. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  6. const isIos = platformInfo.startsWith('ios')
  7. const isMP = platformInfo.startsWith('mp')
  8. const isAndroid = platformInfo.startsWith('android')
  9. const isHarmony = platformInfo.startsWith('harmony')
  10. const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true'
  11. let page;
  12. describe("onLoad", () => {
  13. if (isMP || isHarmony) {
  14. it('mp not support', () => {
  15. expect(1).toBe(1)
  16. })
  17. return
  18. }
  19. if (
  20. isIos &&
  21. (platformInfo.indexOf('15.5') != -1 ||
  22. platformInfo.indexOf('14.5') != -1 ||
  23. platformInfo.indexOf('13.7') != -1 ||
  24. platformInfo.indexOf('12.4') != -1)
  25. ) {
  26. // TODO: 排查 ios 不兼容版本 测试异常原因
  27. it('ios 15.5 14.5 13.7 12.4 测试异常', () => {
  28. expect(1).toBe(1)
  29. })
  30. return
  31. }
  32. let topSafeArea = 0;
  33. beforeAll(async () => {
  34. const windowInfo = await program.callUniMethod('getWindowInfo');
  35. topSafeArea = windowInfo.safeAreaInsets.top;
  36. })
  37. it("adjustData", async () => {
  38. page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
  39. await page.waitFor('view');
  40. await page.callMethod("navigateToOnLoadWithType", "adjustData");
  41. await page.waitFor(1000);
  42. const image = await program.screenshot({
  43. fullPage: true
  44. });
  45. expect(image).toSaveImageSnapshot();
  46. });
  47. it("navigateTo", async () => {
  48. page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
  49. await page.waitFor('view');
  50. await page.callMethod("navigateToOnLoadWithType", "navigateTo");
  51. await page.waitFor(1000);
  52. page = await program.currentPage();
  53. expect(page.path).toBe(TARGET_PAGE_PATH.substring(1));
  54. });
  55. it("navigateBack", async () => {
  56. if (isAndroid && !isAppWebView) {
  57. page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
  58. await page.waitFor('view');
  59. await page.callMethod("navigateToOnLoadWithType", "navigateBack");
  60. await page.waitFor('view');
  61. page = await program.currentPage();
  62. expect(page.path).toBe(INTERMEDIATE_PAGE_PATH.substring(1));
  63. }
  64. });
  65. it("redirectTo", async () => {
  66. page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
  67. await page.waitFor('view');
  68. await page.callMethod("navigateToOnLoadWithType", "redirectTo");
  69. await page.waitFor(100);
  70. page = await program.currentPage();
  71. expect(page.path).toBe(TARGET_PAGE_PATH.substring(1));
  72. });
  73. it("reLaunch", async () => {
  74. page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
  75. await page.waitFor('view');
  76. await page.callMethod("navigateToOnLoadWithType", "reLaunch");
  77. await page.waitFor(100);
  78. page = await program.currentPage();
  79. expect(page.path).toBe(TARGET_PAGE_PATH.substring(1));
  80. });
  81. it("switchTab", async () => {
  82. page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
  83. await page.waitFor('view');
  84. await page.callMethod("navigateToOnLoadWithType", "switchTab");
  85. await page.waitFor(100);
  86. page = await program.currentPage();
  87. expect(page.path).toBe("pages/tabBar/component");
  88. });
  89. it("showToast", async () => {
  90. page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
  91. await page.waitFor("view");
  92. await page.callMethod("navigateToOnLoadWithType", "showToast");
  93. await page.waitFor(1000);
  94. const image = await program.screenshot({
  95. deviceShot: true,
  96. area: {
  97. x: 0,
  98. y: topSafeArea + 44,
  99. },
  100. });
  101. expect(image).toSaveImageSnapshot({
  102. failureThreshold: 0.05,
  103. failureThresholdType: "percent",
  104. });
  105. await page.waitFor(2000);
  106. });
  107. it("showLoading", async () => {
  108. page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
  109. await page.waitFor("view");
  110. await page.callMethod("navigateToOnLoadWithType", "showLoading");
  111. await page.waitFor(1000);
  112. const image = await program.screenshot({
  113. deviceShot: true,
  114. area: {
  115. x: 0,
  116. y: topSafeArea + 44,
  117. },
  118. });
  119. expect(image).toSaveImageSnapshot({
  120. failureThreshold: 0.05,
  121. failureThresholdType: "percent",
  122. });
  123. await page.waitFor(2000);
  124. });
  125. it("showModal", async () => {
  126. page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
  127. await page.waitFor("view");
  128. await page.callMethod("navigateToOnLoadWithType", "showModal");
  129. await page.waitFor(1000);
  130. const image = await program.screenshot({
  131. deviceShot: true,
  132. area: {
  133. x: 0,
  134. y: topSafeArea + 44,
  135. },
  136. });
  137. expect(image).toSaveImageSnapshot({
  138. failureThreshold: 0.05,
  139. failureThresholdType: "percent",
  140. });
  141. });
  142. it('onLoad 参数 decode', async () => {
  143. page = await program.reLaunch(PAGE_PATH);
  144. await page.waitFor("view");
  145. const TEXT = '中文测试'
  146. uni.navigateTo({
  147. url: INTERMEDIATE_PAGE_PATH + '?data=' + encodeURIComponent(TEXT),
  148. success() {
  149. }
  150. })
  151. await page.waitFor(1000);
  152. page = await program.currentPage();
  153. const data = await page.data();
  154. expect(data.data).toBe(TEXT);
  155. })
  156. });