navbar-lite.test.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 CURRENT_PAGE_PATH = "/pages/template/navbar-lite/navbar-lite";
  7. describe("setCustomNavigationBarColor", () => {
  8. let page;
  9. let originLifeCycleNum;
  10. const isAndroid = process.env.UNI_OS_NAME === "android";
  11. const screenShotArea = {
  12. x: 342,
  13. y:18,
  14. width: 40,
  15. height: 20
  16. };
  17. if (isIos) {
  18. screenShotArea.x = 310
  19. screenShotArea.y = 20
  20. screenShotArea.width = 40
  21. screenShotArea.height = 20
  22. } else if (platformInfo.startsWith('android 6')) {
  23. screenShotArea.x = 204
  24. screenShotArea.width = 34
  25. screenShotArea.height = 16
  26. } else if (platformInfo.startsWith('android 12')) {
  27. screenShotArea.x = 336
  28. screenShotArea.y = 3
  29. screenShotArea.width = 50
  30. screenShotArea.height = 20
  31. } else if (isHarmony) {
  32. screenShotArea.x = 295
  33. screenShotArea.y = 14
  34. screenShotArea.width = 40
  35. screenShotArea.height = 20
  36. }
  37. beforeAll(async () => {
  38. page = await program.navigateTo(CURRENT_PAGE_PATH);
  39. await page.waitFor('view');
  40. originLifeCycleNum = await page.callMethod("getLifeCycleNum");
  41. });
  42. afterAll(async () => {
  43. await page.callMethod("setLifeCycleNum", originLifeCycleNum);
  44. const lifeCycleNum = await page.callMethod("getLifeCycleNum");
  45. expect(lifeCycleNum).toBe(originLifeCycleNum);
  46. });
  47. it("setNavigationBarColor2", async () => {
  48. await page.callMethod("setNavigationBarColor2");
  49. await page.waitFor(1000);
  50. if (isApp) {
  51. const image = await program.screenshot({
  52. deviceShot: true,
  53. area: screenShotArea,
  54. });
  55. expect(image).toSaveImageSnapshot();
  56. }
  57. const lifeCycleNum = await page.callMethod("getLifeCycleNum");
  58. expect(lifeCycleNum - originLifeCycleNum).toBe(2);
  59. });
  60. it("setNavigationBarColor1", async () => {
  61. await page.callMethod("setNavigationBarColor1");
  62. await page.waitFor(1000);
  63. if (isAndroid) {
  64. const image = await program.screenshot({
  65. deviceShot: true,
  66. area: screenShotArea,
  67. });
  68. expect(image).toSaveImageSnapshot();
  69. }
  70. const lifeCycleNum = await page.callMethod("getLifeCycleNum");
  71. expect(lifeCycleNum - originLifeCycleNum).toBe(4);
  72. });
  73. });