summaryrefslogtreecommitdiff
path: root/spec/frontend/jira_connect/branches/pages/index_spec.js
blob: 92976dd28dafa86ad3c301ca9c3599278c3edd6a (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
import { GlEmptyState } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import NewBranchForm from '~/jira_connect/branches/components/new_branch_form.vue';
import {
  I18N_PAGE_TITLE_WITH_BRANCH_NAME,
  I18N_PAGE_TITLE_DEFAULT,
} from '~/jira_connect/branches/constants';
import JiraConnectNewBranchPage from '~/jira_connect/branches/pages/index.vue';
import { sprintf } from '~/locale';

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

  const findPageTitle = () => wrapper.find('h1');
  const findNewBranchForm = () => wrapper.findComponent(NewBranchForm);
  const findEmptyState = () => wrapper.findComponent(GlEmptyState);

  function createComponent({ provide } = {}) {
    wrapper = shallowMount(JiraConnectNewBranchPage, {
      provide: {
        initialBranchName: '',
        successStateSvgPath: '',
        ...provide,
      },
    });
  }

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

  describe('page title', () => {
    it.each`
      initialBranchName    | pageTitle
      ${undefined}         | ${I18N_PAGE_TITLE_DEFAULT}
      ${'ap1-test-button'} | ${sprintf(I18N_PAGE_TITLE_WITH_BRANCH_NAME, { jiraIssue: 'ap1-test-button' })}
    `(
      'sets page title to "$pageTitle" when initial branch name is "$initialBranchName"',
      ({ initialBranchName, pageTitle }) => {
        createComponent({ provide: { initialBranchName } });

        expect(findPageTitle().text()).toBe(pageTitle);
      },
    );
  });

  it('renders NewBranchForm by default', () => {
    createComponent();

    expect(findNewBranchForm().exists()).toBe(true);
    expect(findEmptyState().exists()).toBe(false);
  });

  describe('when `sucesss` event emitted from NewBranchForm', () => {
    it('renders the success state', async () => {
      createComponent();

      const newBranchForm = findNewBranchForm();
      await newBranchForm.vm.$emit('success');

      expect(findNewBranchForm().exists()).toBe(false);
      expect(findEmptyState().exists()).toBe(true);
    });
  });
});