upload-file.test.js 2.3 KB
Newer Older
1 2 3
const PAGE_PATH = '/pages/API/upload-file/upload-file'

describe('ExtApi-UploadFile', () => {
4
  if (process.env.uniTestPlatformInfo.startsWith('web')) {
雪洛's avatar
雪洛 已提交
5 6 7
    // TODO: web 端暂不支持测试
    it('web', async () => {
      expect(1).toBe(1)
8
    })
雪洛's avatar
雪洛 已提交
9
    return
雪洛's avatar
雪洛 已提交
10
  }
11

雪洛's avatar
雪洛 已提交
12
  let page;
13 14 15
  let res;
  beforeAll(async () => {
    page = await program.reLaunch(PAGE_PATH)
雪洛's avatar
雪洛 已提交
16 17
    await page.waitFor(600);
    await page.callMethod('jest_uploadFile');
18
    await page.waitFor(2000);
雪洛's avatar
雪洛 已提交
19 20 21 22 23 24 25
    res = await page.data('jest_result');
  });

  beforeEach(async () => {
    await page.setData({
      jest_result: false
    })
26 27 28
  });

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

  it('Check files upload', async () => {
    res = await page.callMethod('jest_files_upload')
    await page.waitFor(2000);
    res = await page.data('jest_result');
    expect(res).toBe(true)
37 38 39 40 41 42 43
  });

  it('Check uni.env', async () => {
    await page.callMethod('jest_uploadFile_with_uni_env');
    await page.waitFor(2000);
    res = await page.data('jest_result');
    expect(res).toBe(true);
44 45 46 47 48 49 50 51 52 53 54 55 56
  });

  // 15以下的模拟器所对应的xcode不能编译自定义插件
  let version = process.env.uniTestPlatformInfo
  let split = version.split(" ")
  version = parseInt(split[split.length - 1])
  if(!process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios') || version > 14) {
    it('Check Upload 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)
    })
57 58 59
  }


雪洛's avatar
雪洛 已提交
60

61
  let shouldTestCookie = false
62
  if (process.env.uniTestPlatformInfo.startsWith('android') && !process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
63 64 65 66 67 68 69 70 71
    let version = process.env.uniTestPlatformInfo
    version = parseInt(version.split(" ")[1])
    shouldTestCookie = version > 9
  }

  if (!shouldTestCookie) {
    return
  }

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