fallback.spec.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. function isRedirectedAfterUpload () {
  22. // this should close the “Do you want to save this file?” alert when Travis runs the test
  23. driver.switchTo().alert().dismiss()
  24. .catch(function (err) {
  25. console.log(err)
  26. })
  27. return driver.getCurrentUrl().then(function (val) {
  28. console.log('current url is ', val)
  29. var isPageRedirected = val.indexOf('api2.transloadit.com') !== -1
  30. return isPageRedirected
  31. })
  32. }
  33. driver.wait(isRedirectedAfterUpload, 12000, 'Browser should navigate to api2.transloadit.com after upload')
  34. .then(function (isPageRedirected) {
  35. Driver.collectErrors(driver).then(function () {
  36. Driver.testEqual(driver, t, isPageRedirected === true)
  37. driver.quit()
  38. })
  39. })
  40. .catch(function (err) {
  41. Driver.collectErrors(driver).then(function () {
  42. Driver.testFail(driver, t, err)
  43. driver.quit()
  44. })
  45. })
  46. })
  47. }