download-file.test.js 2.6 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
  let res;
  beforeAll(async () => {
    page = await program.reLaunch(PAGE_PATH)
雪洛's avatar
雪洛 已提交
9 10
    await page.waitFor(600);
    await page.callMethod('jest_downloadFile');
11
    await page.waitFor(2000);
雪洛's avatar
雪洛 已提交
12 13 14 15 16 17 18
    res = await page.data('jest_result');
  });

  beforeEach(async () => {
    await page.setData({
      jest_result: false
    })
19 20 21
  });

  it('Check ', async () => {
雪洛's avatar
雪洛 已提交
22
    expect(res).toBe(true);
23
  });
雪洛's avatar
雪洛 已提交
24 25 26 27 28 29

  it('Check Special characters Url download file', async () => {
    res = await page.callMethod('jest_special_characters_download')
    await page.waitFor(2000);
    res = await page.data('jest_result');
    expect(res).toBe(true)
30
  });
31

雪洛's avatar
雪洛 已提交
32 33 34 35
  if (
    !process.env.uniTestPlatformInfo.startsWith('web') &&
    !process.env.uniTestPlatformInfo.startsWith('mp')
  ) {
36 37 38 39 40 41 42
    it('Check uni.env', async () => {
      await page.callMethod('jest_downloadFile_with_uni_env');
      await page.waitFor(2000);
      res = await page.data('jest_result');
      expect(res).toBe(true);
    });

43
    // 15以下的模拟器所对应的xcode不能编译自定义插件,大于15是因为某台设备,会用xcode14.1跑15.5的设备
44 45 46
    let version = process.env.uniTestPlatformInfo
    let split = version.split(" ")
    version = parseInt(split[split.length - 1])
雪洛's avatar
雪洛 已提交
47
    if (!process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios') || version > 15) {
48 49 50 51 52 53 54 55
      it('Check Download File In UTS Module', async () => {
        res = await page.callMethod('jest_uts_module_invoked')
        await page.waitFor(2000);
        res = await page.data('jest_result');
        expect(res).toBe(true)
      })
    }
  }
56

雪洛's avatar
雪洛 已提交
57 58

  let shouldTestCookie = false
59
  if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
雪洛's avatar
雪洛 已提交
60
    let version = process.env.uniTestPlatformInfo
61
    version = parseInt(version.split(" ")[1])
雪洛's avatar
雪洛 已提交
62
    shouldTestCookie = version > 9
63
  } else if (process.env.uniTestPlatformInfo.startsWith('web')) {
雪洛's avatar
雪洛 已提交
64 65 66
    // TODO 测试网址调整后放开此测试
    shouldTestCookie = false
  }
67 68 69
  if (!shouldTestCookie) {
    return
  }
雪洛's avatar
雪洛 已提交
70 71 72

  it('Check Set Cookie', async () => {
    res = await page.callMethod('jest_set_cookie')
73
    await page.waitFor(2000);
雪洛's avatar
雪洛 已提交
74 75 76 77 78
    res = await page.data('jest_result');
    expect(res).toBe(true)
  });
  it('Check Delete Cookie', async () => {
    res = await page.callMethod('jest_delete_cookie')
79
    await page.waitFor(2000);
雪洛's avatar
雪洛 已提交
80 81
    res = await page.data('jest_result');
    expect(res).toBe(true)
82
  });
83
});