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

blob_edit_spec.js « components « repository « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e2de7bc2957053d364a89ffc7d3e0c7026b9a8e3 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { GlButton } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import BlobEdit from '~/repository/components/blob_edit.vue';
import WebIdeLink from '~/vue_shared/components/web_ide_link.vue';

const DEFAULT_PROPS = {
  editPath: 'some_file.js/edit',
  webIdePath: 'some_file.js/ide/edit',
  showEditButton: true,
  needsToFork: false,
};

describe('BlobEdit component', () => {
  let wrapper;

  const createComponent = (consolidatedEditButton = false, props = {}) => {
    wrapper = shallowMount(BlobEdit, {
      propsData: {
        ...DEFAULT_PROPS,
        ...props,
      },
      provide: {
        glFeatures: {
          consolidatedEditButton,
        },
      },
    });
  };

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

  const findButtons = () => wrapper.findAll(GlButton);
  const findEditButton = () => wrapper.find('[data-testid="edit"]');
  const findWebIdeButton = () => wrapper.find('[data-testid="web-ide"]');
  const findWebIdeLink = () => wrapper.find(WebIdeLink);

  it('renders component', () => {
    createComponent();

    const { editPath, webIdePath } = DEFAULT_PROPS;

    expect(wrapper.props()).toMatchObject({
      editPath,
      webIdePath,
    });
  });

  it('renders both buttons', () => {
    createComponent();

    expect(findButtons()).toHaveLength(2);
  });

  it('renders the Edit button', () => {
    createComponent();

    expect(findEditButton().text()).toBe('Edit');
    expect(findEditButton()).not.toBeDisabled();
  });

  it('renders the Web IDE button', () => {
    createComponent();

    expect(findWebIdeButton().text()).toBe('Web IDE');
    expect(findWebIdeButton()).not.toBeDisabled();
  });

  it('renders WebIdeLink component', () => {
    createComponent(true);

    const { editPath: editUrl, webIdePath: webIdeUrl, needsToFork } = DEFAULT_PROPS;

    expect(findWebIdeLink().props()).toMatchObject({
      editUrl,
      webIdeUrl,
      isBlob: true,
      showEditButton: true,
      needsToFork,
    });
  });

  describe('Without Edit button', () => {
    const showEditButton = false;

    it('renders WebIdeLink component without an edit button', () => {
      createComponent(true, { showEditButton });

      expect(findWebIdeLink().props()).toMatchObject({ showEditButton });
    });

    it('does not render an Edit button', () => {
      createComponent(false, { showEditButton });

      expect(findEditButton().exists()).toBe(false);
    });
  });
});