summaryrefslogtreecommitdiff
path: root/spec/javascripts/lib/utils/file_upload_spec.js
blob: 92c9cc70aafa4519f265eae9f59ba2c348213fba (plain)
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
import fileUpload from '~/lib/utils/file_upload';

describe('File upload', () => {
  beforeEach(() => {
    setFixtures(`
      <form>
        <button class="js-button" type="button">Click me!</button>
        <input type="text" class="js-input" />
        <span class="js-filename"></span>
      </form>
    `);

    fileUpload('.js-button', '.js-input');
  });

  it('clicks file input after clicking button', () => {
    const btn = document.querySelector('.js-button');
    const input = document.querySelector('.js-input');

    spyOn(input, 'click');

    btn.click();

    expect(input.click).toHaveBeenCalled();
  });

  it('updates file name text', () => {
    const input = document.querySelector('.js-input');

    input.value = 'path/to/file/index.js';

    input.dispatchEvent(new CustomEvent('change'));

    expect(document.querySelector('.js-filename').textContent).toEqual('index.js');
  });
});