download-file.test.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  2. const isMP = platformInfo.startsWith('mp')
  3. const isWeb = platformInfo.startsWith('web')
  4. const isAndroid = platformInfo.startsWith('android')
  5. const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true'
  6. const PAGE_PATH = '/pages/API/download-file/download-file'
  7. describe('ExtApi-DownloadFile', () => {
  8. let page;
  9. let res;
  10. let timeout = 3000
  11. let waitForStartTime
  12. async function waitCallbackTriggredOrTimeout(){
  13. waitForStartTime = Date.now()
  14. await page.waitFor(async () => {
  15. const callbackTriggred = await page.data('jest_callback_triggred')
  16. return callbackTriggred || (Date.now() - waitForStartTime > timeout)
  17. })
  18. }
  19. beforeAll(async () => {
  20. page = await program.reLaunch(PAGE_PATH)
  21. await page.waitFor('view');
  22. await page.callMethod('jest_downloadFile');
  23. await waitCallbackTriggredOrTimeout()
  24. res = await page.data('jest_result');
  25. });
  26. beforeEach(async () => {
  27. await page.setData({
  28. jest_result: false,
  29. jest_callback_triggred: false
  30. })
  31. });
  32. it('Check ', async () => {
  33. expect(res).toBe(true);
  34. });
  35. it('Check Special characters Url download file', async () => {
  36. res = await page.callMethod('jest_special_characters_download')
  37. await waitCallbackTriggredOrTimeout()
  38. res = await page.data('jest_result');
  39. expect(res).toBe(true)
  40. });
  41. it('Check download call timeout', async () => {
  42. res = await page.callMethod('jest_download_call_timeout')
  43. await page.waitFor(5000);
  44. res = await page.data('jest_result');
  45. expect(res).toBe(true)
  46. })
  47. if (!(isMP || isWeb)) {
  48. it('Check uni.env', async () => {
  49. await page.callMethod('jest_downloadFile_with_uni_env');
  50. await waitCallbackTriggredOrTimeout()
  51. res = await page.data('jest_result');
  52. expect(res).toBe(true);
  53. });
  54. // 15以下的模拟器所对应的xcode不能编译自定义插件,大于15是因为某台设备,会用xcode14.1跑15.5的设备
  55. let version = process.env.uniTestPlatformInfo
  56. let split = version.split(" ")
  57. version = parseInt(split[split.length - 1])
  58. if (!process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios') || version > 15) {
  59. it('Check Download File In UTS Module', async () => {
  60. res = await page.callMethod('jest_uts_module_invoked')
  61. await waitCallbackTriggredOrTimeout()
  62. res = await page.data('jest_result');
  63. expect(res).toBe(true)
  64. })
  65. }
  66. }
  67. let shouldTestCookie = false
  68. if (isAndroid && isAppWebView) {
  69. let version = process.env.uniTestPlatformInfo
  70. version = parseInt(version.split(" ")[1])
  71. shouldTestCookie = version > 9
  72. } else if (isWeb) {
  73. // TODO 测试网址调整后放开此测试
  74. shouldTestCookie = false
  75. }
  76. if (!shouldTestCookie) {
  77. return
  78. }
  79. it('Check Set Cookie', async () => {
  80. res = await page.callMethod('jest_set_cookie')
  81. await waitCallbackTriggredOrTimeout()
  82. res = await page.data('jest_result');
  83. expect(res).toBe(true)
  84. });
  85. it('Check Delete Cookie', async () => {
  86. res = await page.callMethod('jest_delete_cookie')
  87. await waitCallbackTriggredOrTimeout()
  88. res = await page.data('jest_result');
  89. expect(res).toBe(true)
  90. });
  91. });