aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/blueimp/jquery-file-upload/wdio/test/pages/file-upload.js
blob: 32ba5c39af969c18efe6e6e254406460bae29112 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'use strict'

/* global browser, $, $$ */
/* eslint-disable class-methods-use-this */

class FileUpload {
  get fileinput() {
    return $('.fileinput-button input')
  }
  get start() {
    return $('.fileupload-buttonbar .start')
  }
  get toggle() {
    return $('.fileupload-buttonbar .toggle')
  }
  get remove() {
    return $('.fileupload-buttonbar .delete')
  }
  get processing() {
    return $$('.files .processing')
  }
  get uploads() {
    return $$('.files .template-upload')
  }
  get downloads() {
    return $$('.files .template-download')
  }
  get checked() {
    return $$('.files .toggle:checked')
  }
  /**
   * Opens the file upload form.
   *
   * @param {number} [timeout] Wait timeout
   */
  async open(timeout) {
    await browser.url('/')
    await this.fileinput.waitForExist({ timeout })
  }
  /**
   * Uploads files.
   *
   * @param {Array<string>} files Files to upload
   * @param {number} [timeout] Wait timeout
   */
  async upload(files, timeout) {
    await this.fileinput.addValue(files.join('\n'))
    await browser.waitUntil(async () => !(await this.processing.length), {
      timeout
    })
    await this.start.click()
    await browser.waitUntil(async () => !!(await this.downloads.length), {
      timeout
    })
    await browser.waitUntil(async () => !(await this.uploads.length), {
      timeout
    })
  }
  /**
   * Deletes uploaded files.
   *
   * @param {number} [timeout] Wait timeout
   */
  async delete(timeout) {
    await this.toggle.click()
    await browser.waitUntil(
      async () => (await this.downloads.length) === (await this.checked.length),
      {
        timeout
      }
    )
    await this.remove.click()
    await browser.waitUntil(async () => !(await this.downloads.length), {
      timeout
    })
  }
}

module.exports = new FileUpload()