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