test.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* global browser, expect, capabilities, $ */
  2. const path = require('path')
  3. const fs = require('fs')
  4. const { selectFakeFile, supportsChooseFile } = require('../utils')
  5. const testURL = 'http://localhost:4567/transloadit'
  6. function unhideTheInput () {
  7. var input = document.querySelector('#uppy-transloadit .uppy-Dashboard-input')
  8. input.removeAttribute('hidden')
  9. input.removeAttribute('aria-hidden')
  10. input.removeAttribute('tabindex')
  11. }
  12. function setTransloaditKeyAndInit (transloaditKey) {
  13. window.initUppyTransloadit(transloaditKey)
  14. }
  15. describe('Transloadit file processing', () => {
  16. beforeEach(() => {
  17. browser.url(testURL)
  18. })
  19. it('should upload a file to Transloadit and crop it', function () {
  20. const transloaditKey = process.env.TRANSLOADIT_KEY
  21. if (transloaditKey === undefined) {
  22. console.log('skipping Transloadit integration test')
  23. return this.skip()
  24. }
  25. browser.execute(setTransloaditKeyAndInit, transloaditKey)
  26. const inputPath = '#uppy-transloadit .uppy-Dashboard-input'
  27. const resultPath = '#uppy-result'
  28. $(inputPath).waitForExist()
  29. if (supportsChooseFile(capabilities)) {
  30. browser.execute(unhideTheInput)
  31. browser.chooseFile(inputPath, path.join(__dirname, '../../resources/image.jpg'))
  32. } else {
  33. const img = path.join(__dirname, '../../resources/image.jpg')
  34. browser.execute(
  35. selectFakeFile,
  36. 'uppyTransloadit',
  37. path.basename(img), // name
  38. `image/jpeg`, // type
  39. fs.readFileSync(img, 'base64') // b64
  40. )
  41. browser.execute(selectFakeFile, 'uppyTransloadit')
  42. }
  43. $(resultPath).waitForExist(15000)
  44. const text = browser.getText(resultPath)
  45. expect(text).to.be.equal('ok')
  46. })
  47. })