summaryrefslogtreecommitdiff
path: root/spec/frontend/transfer_edit_spec.js
blob: dc9455a569d4032bf41f247ff7774bca84c46cf4 (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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import $ from 'jquery';

import { loadHTMLFixture } from 'helpers/fixtures';
import setupTransferEdit from '~/transfer_edit';

describe('setupTransferEdit', () => {
  const formSelector = '.js-project-transfer-form';
  const targetSelector = 'select.select2';

  beforeEach(() => {
    loadHTMLFixture('projects/edit.html');
    setupTransferEdit(formSelector, targetSelector);
  });

  it('disables submit button on load', () => {
    expect(
      $(formSelector)
        .find(':submit')
        .prop('disabled'),
    ).toBe(true);
  });

  it('enables submit button when selection changes to non-empty value', () => {
    const nonEmptyValue = $(formSelector)
      .find(targetSelector)
      .find('option')
      .not(':empty')
      .val();
    $(formSelector)
      .find(targetSelector)
      .val(nonEmptyValue)
      .trigger('change');

    expect(
      $(formSelector)
        .find(':submit')
        .prop('disabled'),
    ).toBeFalsy();
  });

  it('disables submit button when selection changes to empty value', () => {
    $(formSelector)
      .find(targetSelector)
      .val('')
      .trigger('change');

    expect(
      $(formSelector)
        .find(':submit')
        .prop('disabled'),
    ).toBe(true);
  });
});