fallback.spec.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. var test = require('tape')
  2. var path = require('path')
  3. var chalk = require('chalk')
  4. var Driver = require('./Driver')
  5. module.exports = function (driver, platform, host) {
  6. var testName = 'fallback: fall back to regular <form> upload when JS is not working, or not loaded yet, or browser is not supported by Uppy'
  7. var platformName = chalk.underline.yellow('[' +
  8. platform.os + ' ' +
  9. platform.browser + ' ' +
  10. platform.version +
  11. ']')
  12. test(testName + ' ' + platformName, function (t) {
  13. t.plan(1)
  14. driver.get(host + '/examples/multipart')
  15. driver.manage().window().maximize()
  16. Driver.setSauceTestName(driver, testName)
  17. driver
  18. .findElement({css: '.UppyForm input'})
  19. .sendKeys(path.join(__dirname, 'image.jpg'))
  20. driver.findElement({css: '.UppyForm button'}).click()
  21. // this should solve some mysterious alert error when Travis runs the test
  22. driver.switchTo().alert().accept().catch(function (err) {
  23. console.log(err)
  24. })
  25. function isRedirectedAfterUpload () {
  26. return driver.getCurrentUrl().then(function (val) {
  27. console.log('current url is ', val)
  28. var isPageRedirected = val.indexOf('api2.transloadit.com') !== -1
  29. return isPageRedirected
  30. })
  31. }
  32. driver.wait(isRedirectedAfterUpload, 12000, 'Browser should navigate to api2.transloadit.com after upload')
  33. .then(function (isPageRedirected) {
  34. Driver.collectErrors(driver).then(function () {
  35. Driver.testEqual(driver, t, isPageRedirected === true)
  36. driver.quit()
  37. })
  38. })
  39. .catch(function (err) {
  40. Driver.collectErrors(driver).then(function () {
  41. Driver.testFail(driver, t, err)
  42. driver.quit()
  43. })
  44. })
  45. })
  46. }