fallback.spec.js 1.8 KB

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