onLoad.test.js 4.3 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2 3 4 5 6 7 8 9 10 11
jest.setTimeout(20000);
const PAGE_PATH = "/pages/API/navigator/new-page/onLoad";
const INTERMEDIATE_PAGE_PATH = "/pages/API/navigator/new-page/new-page-1";
const TARGET_PAGE_PATH = "/pages/API/navigator/new-page/new-page-3";
let page;

describe("onLoad", () => {
  it("adjustData", async () => {
    page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
    await page.waitFor('view');
    await page.callMethod("navigateToOnLoadWithType", "adjustData");
DCloud-WZF's avatar
DCloud-WZF 已提交
12
    await page.waitFor(1000);
DCloud-WZF's avatar
DCloud-WZF 已提交
13 14 15 16 17 18 19
    const image = await program.screenshot();
    expect(image).toMatchImageSnapshot();
  });
  it("navigateTo", async () => {
    page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
    await page.waitFor('view');
    await page.callMethod("navigateToOnLoadWithType", "navigateTo");
DCloud-WZF's avatar
DCloud-WZF 已提交
20
    await page.waitFor(1000);
DCloud-WZF's avatar
DCloud-WZF 已提交
21 22 23 24
    page = await program.currentPage();
    expect(page.path).toBe(TARGET_PAGE_PATH.substring(1));
  });
  it("navigateBack", async () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
25 26 27 28 29 30 31 32
    if (process.env.uniTestPlatformInfo.startsWith('android')) {
      page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
      await page.waitFor('view');
      await page.callMethod("navigateToOnLoadWithType", "navigateBack");
      await page.waitFor('view');
      page = await program.currentPage();
      expect(page.path).toBe(INTERMEDIATE_PAGE_PATH.substring(1));
    }
DCloud-WZF's avatar
DCloud-WZF 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
  });
  it("redirectTo", async () => {
    page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
    await page.waitFor('view');
    await page.callMethod("navigateToOnLoadWithType", "redirectTo");
    await page.waitFor(100);
    page = await program.currentPage();
    expect(page.path).toBe(TARGET_PAGE_PATH.substring(1));
  });
  it("reLaunch", async () => {
    page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
    await page.waitFor('view');
    await page.callMethod("navigateToOnLoadWithType", "reLaunch");
    await page.waitFor(100);
    page = await program.currentPage();
    expect(page.path).toBe(TARGET_PAGE_PATH.substring(1));
  });
  it("switchTab", async () => {
    page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
    await page.waitFor('view');
    await page.callMethod("navigateToOnLoadWithType", "switchTab");
    await page.waitFor(100);
DCloud-WZF's avatar
DCloud-WZF 已提交
55
    page = await program.currentPage();
DCloud-WZF's avatar
DCloud-WZF 已提交
56 57 58 59
    expect(page.path).toBe("pages/tabBar/component");
  });
  it("showToast", async () => {
    page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
DCloud-WZF's avatar
DCloud-WZF 已提交
60
    await page.waitFor("view");
DCloud-WZF's avatar
DCloud-WZF 已提交
61
    await page.callMethod("navigateToOnLoadWithType", "showToast");
DCloud-WZF's avatar
DCloud-WZF 已提交
62
    await page.waitFor(1000);
DCloud-WZF's avatar
DCloud-WZF 已提交
63 64 65 66 67
    const image = await program.screenshot({
      adb: true,
      area: {
        x: 0,
        y: 200,
DCloud-WZF's avatar
DCloud-WZF 已提交
68 69
        height: 2140,
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
70
    });
DCloud-WZF's avatar
DCloud-WZF 已提交
71 72 73 74
    expect(image).toMatchImageSnapshot({
      failureThreshold: 0.05,
      failureThresholdType: "percent",
    });
DCloud-WZF's avatar
DCloud-WZF 已提交
75 76 77
  });
  it("showLoading", async () => {
    page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
DCloud-WZF's avatar
DCloud-WZF 已提交
78
    await page.waitFor("view");
DCloud-WZF's avatar
DCloud-WZF 已提交
79
    await page.callMethod("navigateToOnLoadWithType", "showLoading");
DCloud-WZF's avatar
DCloud-WZF 已提交
80
    await page.waitFor(1000);
DCloud-WZF's avatar
DCloud-WZF 已提交
81 82 83 84 85
    const image = await program.screenshot({
      adb: true,
      area: {
        x: 0,
        y: 200,
DCloud-WZF's avatar
DCloud-WZF 已提交
86 87
        height: 2140,
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
88
    });
DCloud-WZF's avatar
DCloud-WZF 已提交
89 90 91
    expect(image).toMatchImageSnapshot({
      failureThreshold: 0.05,
      failureThresholdType: "percent",
DCloud-WZF's avatar
DCloud-WZF 已提交
92
    });
DCloud-WZF's avatar
DCloud-WZF 已提交
93 94 95
  });
  it("showModal", async () => {
    page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
DCloud-WZF's avatar
DCloud-WZF 已提交
96
    await page.waitFor("view");
DCloud-WZF's avatar
DCloud-WZF 已提交
97
    await page.callMethod("navigateToOnLoadWithType", "showModal");
DCloud-WZF's avatar
DCloud-WZF 已提交
98
    await page.waitFor(1000);
DCloud-WZF's avatar
DCloud-WZF 已提交
99 100 101 102 103
    const image = await program.screenshot({
      adb: true,
      area: {
        x: 0,
        y: 200,
DCloud-WZF's avatar
DCloud-WZF 已提交
104 105
        height: 2140,
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
106
    });
DCloud-WZF's avatar
DCloud-WZF 已提交
107 108 109 110
    expect(image).toMatchImageSnapshot({
      failureThreshold: 0.05,
      failureThresholdType: "percent",
    });
DCloud-WZF's avatar
DCloud-WZF 已提交
111 112 113
  });
  it("showActionSheet", async () => {
    page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
DCloud-WZF's avatar
DCloud-WZF 已提交
114
    await page.waitFor("view");
DCloud-WZF's avatar
DCloud-WZF 已提交
115
    await page.callMethod("navigateToOnLoadWithType", "showActionSheet");
DCloud-WZF's avatar
DCloud-WZF 已提交
116
    await page.waitFor(1000);
DCloud-WZF's avatar
DCloud-WZF 已提交
117 118 119 120
    const image = await program.screenshot({
      adb: true,
      area: {
        x: 0,
DCloud-WZF's avatar
DCloud-WZF 已提交
121 122 123
        y: 200,
        height: 2140,
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
124
    });
DCloud-WZF's avatar
DCloud-WZF 已提交
125 126 127 128
    expect(image).toMatchImageSnapshot({
      failureThreshold: 0.05,
      failureThresholdType: "percent",
    });
DCloud-WZF's avatar
DCloud-WZF 已提交
129
  });
DCloud-WZF's avatar
DCloud-WZF 已提交
130
});