onLoad.test.js 4.8 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);
13 14 15
    const image = await program.screenshot({
      fullPage: true
    });
16
    expect(image).toSaveImageSnapshot();
DCloud-WZF's avatar
DCloud-WZF 已提交
17 18 19 20 21
  });
  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 已提交
22
    await page.waitFor(1000);
DCloud-WZF's avatar
DCloud-WZF 已提交
23 24 25 26
    page = await program.currentPage();
    expect(page.path).toBe(TARGET_PAGE_PATH.substring(1));
  });
  it("navigateBack", async () => {
27
    if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
DCloud-WZF's avatar
DCloud-WZF 已提交
28 29 30 31 32 33 34
      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 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
  });
  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 已提交
57
    page = await program.currentPage();
DCloud-WZF's avatar
DCloud-WZF 已提交
58 59 60 61
    expect(page.path).toBe("pages/tabBar/component");
  });
  it("showToast", async () => {
    page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
DCloud-WZF's avatar
DCloud-WZF 已提交
62
    await page.waitFor("view");
DCloud-WZF's avatar
DCloud-WZF 已提交
63
    await page.callMethod("navigateToOnLoadWithType", "showToast");
DCloud-WZF's avatar
DCloud-WZF 已提交
64
    await page.waitFor(1000);
DCloud-WZF's avatar
DCloud-WZF 已提交
65
    const image = await program.screenshot({
66
      deviceShot: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
67 68 69
      area: {
        x: 0,
        y: 200,
DCloud-WZF's avatar
DCloud-WZF 已提交
70 71
        height: 2140,
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
72
    });
73
    expect(image).toSaveImageSnapshot({
DCloud-WZF's avatar
DCloud-WZF 已提交
74 75 76
      failureThreshold: 0.05,
      failureThresholdType: "percent",
    });
DCloud-WZF's avatar
DCloud-WZF 已提交
77 78 79
  });
  it("showLoading", async () => {
    page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
DCloud-WZF's avatar
DCloud-WZF 已提交
80
    await page.waitFor("view");
DCloud-WZF's avatar
DCloud-WZF 已提交
81
    await page.callMethod("navigateToOnLoadWithType", "showLoading");
DCloud-WZF's avatar
DCloud-WZF 已提交
82
    await page.waitFor(1000);
DCloud-WZF's avatar
DCloud-WZF 已提交
83
    const image = await program.screenshot({
84
      deviceShot: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
85 86 87
      area: {
        x: 0,
        y: 200,
DCloud-WZF's avatar
DCloud-WZF 已提交
88 89
        height: 2140,
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
90
    });
91
    expect(image).toSaveImageSnapshot({
DCloud-WZF's avatar
DCloud-WZF 已提交
92 93
      failureThreshold: 0.05,
      failureThresholdType: "percent",
94
    });
DCloud-WZF's avatar
DCloud-WZF 已提交
95 96 97
  });
  it("showModal", async () => {
    page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
DCloud-WZF's avatar
DCloud-WZF 已提交
98
    await page.waitFor("view");
DCloud-WZF's avatar
DCloud-WZF 已提交
99
    await page.callMethod("navigateToOnLoadWithType", "showModal");
DCloud-WZF's avatar
DCloud-WZF 已提交
100
    await page.waitFor(1000);
DCloud-WZF's avatar
DCloud-WZF 已提交
101
    const image = await program.screenshot({
102
      deviceShot: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
103 104 105
      area: {
        x: 0,
        y: 200,
DCloud-WZF's avatar
DCloud-WZF 已提交
106 107
        height: 2140,
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
108
    });
109
    expect(image).toSaveImageSnapshot({
DCloud-WZF's avatar
DCloud-WZF 已提交
110 111 112
      failureThreshold: 0.05,
      failureThresholdType: "percent",
    });
DCloud-WZF's avatar
DCloud-WZF 已提交
113 114 115
  });
  it("showActionSheet", async () => {
    page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
DCloud-WZF's avatar
DCloud-WZF 已提交
116
    await page.waitFor("view");
DCloud-WZF's avatar
DCloud-WZF 已提交
117
    await page.callMethod("navigateToOnLoadWithType", "showActionSheet");
DCloud-WZF's avatar
DCloud-WZF 已提交
118
    await page.waitFor(1000);
DCloud-WZF's avatar
DCloud-WZF 已提交
119
    const image = await program.screenshot({
120
      deviceShot: true,
DCloud-WZF's avatar
DCloud-WZF 已提交
121 122
      area: {
        x: 0,
DCloud-WZF's avatar
DCloud-WZF 已提交
123 124 125
        y: 200,
        height: 2140,
      },
DCloud-WZF's avatar
DCloud-WZF 已提交
126
    });
127
    expect(image).toSaveImageSnapshot({
DCloud-WZF's avatar
DCloud-WZF 已提交
128 129 130
      failureThreshold: 0.05,
      failureThresholdType: "percent",
    });
DCloud-WZF's avatar
DCloud-WZF 已提交
131
  });
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
  it('onLoad 参数 decode', async () => {
    page = await program.reLaunch(PAGE_PATH);
    await page.waitFor("view");
    const TEXT = '中文测试'
    uni.navigateTo({
      url: INTERMEDIATE_PAGE_PATH + '?data=' + encodeURIComponent(TEXT),
      success() {

      }
    })
    await page.waitFor(1000);
    page = await program.currentPage();
    const data = await page.data();
    expect(data.data).toBe(TEXT);
  })
});