download-file.test.js 3.0 KB
Newer Older
1 2 3 4
const PAGE_PATH = '/pages/API/download-file/download-file'

describe('ExtApi-DownloadFile', () => {

雪洛's avatar
雪洛 已提交
5
  let page;
6 7 8 9 10 11 12 13 14 15 16
  let res;
  let timeout = 3000
  let waitForStartTime
  async function waitCallbackTriggredOrTimeout(){
    waitForStartTime = Date.now()
    await page.waitFor(async () => {
      const callbackTriggred = await page.data('jest_callback_triggred')
      return callbackTriggred || (Date.now() - waitForStartTime > timeout)
    })
  }

17 18
  beforeAll(async () => {
    page = await program.reLaunch(PAGE_PATH)
19
    await page.waitFor('view');
雪洛's avatar
雪洛 已提交
20
    await page.callMethod('jest_downloadFile');
21
    await waitCallbackTriggredOrTimeout()
雪洛's avatar
雪洛 已提交
22 23 24
    res = await page.data('jest_result');
  });

25
  beforeEach(async () => {
雪洛's avatar
雪洛 已提交
26
    await page.setData({
27 28
      jest_result: false,
      jest_callback_triggred: false
雪洛's avatar
雪洛 已提交
29
    })
30 31 32
  });

  it('Check ', async () => {
雪洛's avatar
雪洛 已提交
33
    expect(res).toBe(true);
34
  });
雪洛's avatar
雪洛 已提交
35 36 37

  it('Check Special characters Url download file', async () => {
    res = await page.callMethod('jest_special_characters_download')
38
    await waitCallbackTriggredOrTimeout()
雪洛's avatar
雪洛 已提交
39 40
    res = await page.data('jest_result');
    expect(res).toBe(true)
41
  });
42

雪洛's avatar
雪洛 已提交
43 44 45 46
  if (
    !process.env.uniTestPlatformInfo.startsWith('web') &&
    !process.env.uniTestPlatformInfo.startsWith('mp')
  ) {
47 48
    it('Check uni.env', async () => {
      await page.callMethod('jest_downloadFile_with_uni_env');
49
      await waitCallbackTriggredOrTimeout()
50 51 52 53
      res = await page.data('jest_result');
      expect(res).toBe(true);
    });

54
    // 15以下的模拟器所对应的xcode不能编译自定义插件,大于15是因为某台设备,会用xcode14.1跑15.5的设备
55 56 57
    let version = process.env.uniTestPlatformInfo
    let split = version.split(" ")
    version = parseInt(split[split.length - 1])
雪洛's avatar
雪洛 已提交
58
    if (!process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios') || version > 15) {
59 60
      it('Check Download File In UTS Module', async () => {
        res = await page.callMethod('jest_uts_module_invoked')
61
        await waitCallbackTriggredOrTimeout()
62 63 64 65 66
        res = await page.data('jest_result');
        expect(res).toBe(true)
      })
    }
  }
67

雪洛's avatar
雪洛 已提交
68 69

  let shouldTestCookie = false
70
  if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
雪洛's avatar
雪洛 已提交
71
    let version = process.env.uniTestPlatformInfo
72
    version = parseInt(version.split(" ")[1])
雪洛's avatar
雪洛 已提交
73
    shouldTestCookie = version > 9
74
  } else if (process.env.uniTestPlatformInfo.startsWith('web')) {
雪洛's avatar
雪洛 已提交
75 76 77
    // TODO 测试网址调整后放开此测试
    shouldTestCookie = false
  }
78 79 80
  if (!shouldTestCookie) {
    return
  }
雪洛's avatar
雪洛 已提交
81 82 83

  it('Check Set Cookie', async () => {
    res = await page.callMethod('jest_set_cookie')
84
    await waitCallbackTriggredOrTimeout()
雪洛's avatar
雪洛 已提交
85 86 87 88 89
    res = await page.data('jest_result');
    expect(res).toBe(true)
  });
  it('Check Delete Cookie', async () => {
    res = await page.callMethod('jest_delete_cookie')
90
    await waitCallbackTriggredOrTimeout()
雪洛's avatar
雪洛 已提交
91 92
    res = await page.data('jest_result');
    expect(res).toBe(true)
93
  });
94
});