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

apply_suggestion_spec.js « markdown « components « vue_shared « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0598506891ba3b8272d66e1c52d79090275e9df6 (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
62
63
64
65
66
67
68
69
70
71
72
import { shallowMount } from '@vue/test-utils';
import { GlDropdown, GlFormTextarea, GlButton } from '@gitlab/ui';
import ApplySuggestionComponent from '~/vue_shared/components/markdown/apply_suggestion.vue';

describe('Apply Suggestion component', () => {
  const propsData = { fileName: 'test.js', disabled: false };
  let wrapper;

  const createWrapper = props => {
    wrapper = shallowMount(ApplySuggestionComponent, { propsData: { ...propsData, ...props } });
  };

  const findDropdown = () => wrapper.find(GlDropdown);
  const findTextArea = () => wrapper.find(GlFormTextarea);
  const findApplyButton = () => wrapper.find(GlButton);

  beforeEach(() => createWrapper());

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

  describe('initial template', () => {
    it('renders a dropdown with the correct props', () => {
      const dropdown = findDropdown();

      expect(dropdown.exists()).toBe(true);
      expect(dropdown.props('text')).toBe('Apply suggestion');
      expect(dropdown.props('headerText')).toBe('Apply suggestion commit message');
      expect(dropdown.props('disabled')).toBe(false);
    });

    it('renders a textarea with the correct props', () => {
      const textArea = findTextArea();

      expect(textArea.exists()).toBe(true);
      expect(textArea.attributes('placeholder')).toBe('Apply suggestion on test.js');
    });

    it('renders an apply button', () => {
      const applyButton = findApplyButton();

      expect(applyButton.exists()).toBe(true);
      expect(applyButton.text()).toBe('Apply');
    });
  });

  describe('disabled', () => {
    it('disables the dropdown', () => {
      createWrapper({ disabled: true });

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

  describe('apply suggestion', () => {
    it('emits an apply event with a default message if no message was added', () => {
      findTextArea().vm.$emit('input', null);
      findApplyButton().vm.$emit('click');

      expect(wrapper.emitted('apply')).toEqual([['Apply suggestion on test.js']]);
    });

    it('emits an apply event with a user-defined message', () => {
      findTextArea().vm.$emit('input', 'some text');
      findApplyButton().vm.$emit('click');

      expect(wrapper.emitted('apply')).toEqual([['some text']]);
    });
  });
});