file-upload.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. 'use strict'
  2. /* global browser, $, $$ */
  3. /* eslint-disable class-methods-use-this */
  4. class FileUpload {
  5. get fileinput() {
  6. return $('.fileinput-button input')
  7. }
  8. get start() {
  9. return $('.fileupload-buttonbar .start')
  10. }
  11. get toggle() {
  12. return $('.fileupload-buttonbar .toggle')
  13. }
  14. get remove() {
  15. return $('.fileupload-buttonbar .delete')
  16. }
  17. get processing() {
  18. return $$('.files .processing')
  19. }
  20. get uploads() {
  21. return $$('.files .template-upload')
  22. }
  23. get downloads() {
  24. return $$('.files .template-download')
  25. }
  26. get checked() {
  27. return $$('.files .toggle:checked')
  28. }
  29. /**
  30. * Opens the file upload form.
  31. *
  32. * @param {number} [timeout] Wait timeout
  33. * @returns {FileUpload} FileUpload object
  34. */
  35. open(timeout) {
  36. browser.url('/')
  37. this.fileinput.waitForExist(timeout)
  38. return this
  39. }
  40. /**
  41. * Uploads files.
  42. *
  43. * @param {Array<string>} files Files to upload
  44. * @param {number} [timeout] Wait timeout
  45. * @returns {FileUpload} FileUpload object
  46. */
  47. upload(files, timeout) {
  48. this.fileinput.addValue(files.join('\n'))
  49. browser.waitUntil(() => !this.processing.length, timeout)
  50. this.start.click()
  51. browser.waitUntil(() => !!this.downloads.length, timeout)
  52. browser.waitUntil(() => !this.uploads.length, timeout)
  53. return this
  54. }
  55. /**
  56. * Deletes uploaded files.
  57. *
  58. * @param {number} [timeout] Wait timeout
  59. * @returns {FileUpload} FileUpload object
  60. */
  61. delete(timeout) {
  62. this.toggle.click()
  63. browser.waitUntil(
  64. () => this.downloads.length === this.checked.length,
  65. timeout
  66. )
  67. this.remove.click()
  68. browser.waitUntil(() => !this.downloads.length, timeout)
  69. return this
  70. }
  71. }
  72. module.exports = new FileUpload()