Welcome to mirror list, hosted at ThFree Co, Russian Federation.

add_issuable_resource_link_form_spec.js « components « linked_resources « issuable « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b370756984807ff6e5cbe15a564cfa814ed3bcd9 (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
54
55
56
57
58
59
60
61
import { nextTick } from 'vue';
import { mountExtended } from 'helpers/vue_test_utils_helper';
import AddIssuableResourceLinkForm from '~/linked_resources/components/add_issuable_resource_link_form.vue';

describe('AddIssuableResourceLinkForm', () => {
  let wrapper;

  const mountComponent = () => {
    wrapper = mountExtended(AddIssuableResourceLinkForm);
  };

  afterEach(() => {
    if (wrapper) {
      wrapper.destroy();
    }
  });

  const findAddButton = () => wrapper.findByTestId('add-button');
  const findCancelButton = () => wrapper.findByText('Cancel');
  const findLinkTextInput = () => wrapper.findByTestId('link-text-input');
  const findLinkValueInput = () => wrapper.findByTestId('link-value-input');

  const cancelForm = async () => {
    await findCancelButton().trigger('click');
  };

  describe('cancel form button', () => {
    const closeFormEvent = { 'add-issuable-resource-link-form-cancel': [[]] };

    beforeEach(() => {
      mountComponent();
    });

    it('should close the form on cancel', async () => {
      await cancelForm();

      expect(wrapper.emitted()).toEqual(closeFormEvent);
    });

    it('keeps the button disabled without input', () => {
      expect(findAddButton().props('disabled')).toBe(true);
    });

    it('keeps the button disabled with only text input', async () => {
      findLinkTextInput().setValue('link text');

      await nextTick();

      expect(findAddButton().props('disabled')).toBe(true);
    });

    it('enables add button when link input is provided', async () => {
      findLinkTextInput().setValue('link text');
      findLinkValueInput().setValue('https://foo.example.com');

      await nextTick();

      expect(findAddButton().props('disabled')).toBe(false);
    });
  });
});