fallback.spec.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.switchTo().alert().dismiss()
  17. .catch(function (err) {
  18. console.log(err)
  19. })
  20. Driver.setSauceTestName(driver, testName)
  21. driver
  22. .findElement({css: '.UppyForm input'})
  23. .sendKeys(path.join(__dirname, 'image.jpg'))
  24. driver.switchTo().alert().dismiss()
  25. .catch(function (err) {
  26. console.log(err)
  27. })
  28. driver.findElement({css: '.UppyForm button'}).click()
  29. driver.switchTo().alert().dismiss()
  30. .catch(function (err) {
  31. console.log(err)
  32. })
  33. function isRedirectedAfterUpload () {
  34. // this should close the “Do you want to save this file?” alert when Travis runs the test
  35. driver.switchTo().alert().dismiss()
  36. .catch(function (err) {
  37. console.log(err)
  38. })
  39. return driver.getCurrentUrl().then(function (val) {
  40. console.log('current url is ', val)
  41. var isPageRedirected = val.indexOf('api2.transloadit.com') !== -1
  42. return isPageRedirected
  43. })
  44. }
  45. driver.wait(isRedirectedAfterUpload, 12000, 'Browser should navigate to api2.transloadit.com after upload')
  46. .then(function (isPageRedirected) {
  47. Driver.collectErrors(driver).then(function () {
  48. Driver.testEqual(driver, t, isPageRedirected === true)
  49. driver.quit()
  50. })
  51. })
  52. .catch(function (err) {
  53. Driver.collectErrors(driver).then(function () {
  54. Driver.testFail(driver, t, err)
  55. driver.quit()
  56. })
  57. })
  58. })
  59. }