summaryrefslogtreecommitdiff
path: root/spec/frontend/releases/components/tag_field_exsting_spec.js
blob: 70a195556dffe0d64e222813c95ee5a4c49b5e88 (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
import Vuex from 'vuex';
import { GlFormInput } from '@gitlab/ui';
import { shallowMount, mount, createLocalVue } from '@vue/test-utils';
import TagFieldExisting from '~/releases/components/tag_field_existing.vue';
import createStore from '~/releases/stores';
import createDetailModule from '~/releases/stores/modules/detail';

const TEST_TAG_NAME = 'test-tag-name';
const TEST_DOCS_PATH = '/help/test/docs/path';

const localVue = createLocalVue();
localVue.use(Vuex);

describe('releases/components/tag_field_existing', () => {
  let store;
  let wrapper;

  const createComponent = (mountFn = shallowMount) => {
    wrapper = mountFn(TagFieldExisting, {
      store,
      localVue,
    });
  };

  const findInput = () => wrapper.find(GlFormInput);
  const findHelp = () => wrapper.find('[data-testid="tag-name-help"]');
  const findHelpLink = () => {
    const link = findHelp().find('a');

    return {
      text: link.text(),
      href: link.attributes('href'),
      target: link.attributes('target'),
    };
  };

  beforeEach(() => {
    store = createStore({
      modules: {
        detail: createDetailModule({
          updateReleaseApiDocsPath: TEST_DOCS_PATH,
          tagName: TEST_TAG_NAME,
        }),
      },
    });

    store.state.detail.release = {
      tagName: TEST_TAG_NAME,
    };
  });

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

  describe('default', () => {
    it('shows the tag name', () => {
      createComponent();

      expect(findInput().attributes()).toMatchObject({
        disabled: '',
        value: TEST_TAG_NAME,
      });
    });

    it('shows help', () => {
      createComponent(mount);

      expect(findHelp().text()).toMatchInterpolatedText(
        'Changing a Release tag is only supported via Releases API. More information',
      );

      const helpLink = findHelpLink();

      expect(helpLink).toEqual({
        text: 'More information',
        href: TEST_DOCS_PATH,
        target: '_blank',
      });
    });
  });
});