upload-file.test.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  2. const isIOS = platformInfo.startsWith('ios')
  3. const isMP = platformInfo.startsWith('mp')
  4. const isWeb = platformInfo.startsWith('web')
  5. const isAppWebView = process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true'
  6. const isAndroid = platformInfo.startsWith('android')
  7. const PAGE_PATH = '/pages/API/upload-file/upload-file'
  8. describe('ExtApi-UploadFile', () => {
  9. let page;
  10. let res;
  11. beforeAll(async () => {
  12. page = await program.reLaunch(PAGE_PATH)
  13. });
  14. if (isWeb || isMP) {
  15. it('not support', async () => {
  16. expect(1).toBe(1)
  17. })
  18. return
  19. }
  20. beforeEach(async () => {
  21. await page.setData({
  22. jest_result: false
  23. })
  24. });
  25. if(!isMP) {
  26. it('Check ', async () => {
  27. await page.waitFor(600);
  28. await page.callMethod('jest_uploadFile');
  29. await page.waitFor(2000);
  30. res = await page.data('jest_result');
  31. expect(res).toBe(true);
  32. });
  33. it('Check files upload', async () => {
  34. res = await page.callMethod('jest_files_upload')
  35. await page.waitFor(2000);
  36. res = await page.data('jest_result');
  37. expect(res).toBe(true)
  38. });
  39. }
  40. it('Check uni.env', async () => {
  41. await page.callMethod('jest_uploadFile_with_uni_env');
  42. await page.waitFor(3000);
  43. res = await page.data('jest_result');
  44. expect(res).toBe(true);
  45. });
  46. // 15以下的模拟器所对应的xcode不能编译自定义插件,大于15是因为某台设备,会用xcode14.1跑15.5的设备
  47. let version = process.env.uniTestPlatformInfo
  48. let split = version.split(" ")
  49. version = parseInt(split[split.length - 1])
  50. if(!isIOS || version > 15) {
  51. it('Check Upload File In UTS Module', async () => {
  52. res = await page.callMethod('jest_uts_module_invoked')
  53. await page.waitFor(2000);
  54. res = await page.data('jest_result');
  55. expect(res).toBe(true)
  56. })
  57. }
  58. let shouldTestCookie = false
  59. if (isAndroid && !isAppWebView) {
  60. let version = process.env.uniTestPlatformInfo
  61. version = parseInt(version.split(" ")[1])
  62. shouldTestCookie = version > 9
  63. }
  64. if (!shouldTestCookie) {
  65. return
  66. }
  67. it('Check Set Cookie', async () => {
  68. res = await page.callMethod('jest_set_cookie')
  69. await page.waitFor(2000);
  70. res = await page.data('jest_result');
  71. expect(res).toBe(true)
  72. });
  73. it('Check Delete Cookie', async () => {
  74. res = await page.callMethod('jest_delete_cookie')
  75. await page.waitFor(2000);
  76. res = await page.data('jest_result');
  77. expect(res).toBe(true)
  78. });
  79. });