summaryrefslogtreecommitdiff
path: root/spec/frontend/jira_connect/subscriptions/components/sign_in_button_spec.js
blob: 94dcf9decec60f76fb2911378f6201965deb9cc7 (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
import { GlButton } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import { getGitlabSignInURL } from '~/jira_connect/subscriptions/utils';
import SignInButton from '~/jira_connect/subscriptions/components/sign_in_button.vue';
import waitForPromises from 'helpers/wait_for_promises';

const MOCK_USERS_PATH = '/user';

jest.mock('~/jira_connect/subscriptions/utils');

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

  const createComponent = ({ slots } = {}) => {
    wrapper = shallowMount(SignInButton, {
      propsData: {
        usersPath: MOCK_USERS_PATH,
      },
      slots,
    });
  };

  const findButton = () => wrapper.findComponent(GlButton);

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

  it('displays a button', () => {
    createComponent();

    expect(findButton().exists()).toBe(true);
    expect(findButton().text()).toBe(SignInButton.i18n.defaultButtonText);
  });

  describe.each`
    expectedHref
    ${MOCK_USERS_PATH}
    ${`${MOCK_USERS_PATH}?return_to=${encodeURIComponent('https://test.jira.com')}`}
  `('when getGitlabSignInURL resolves with `$expectedHref`', ({ expectedHref }) => {
    it(`sets button href to ${expectedHref}`, async () => {
      getGitlabSignInURL.mockResolvedValue(expectedHref);
      createComponent();

      await waitForPromises();

      expect(findButton().attributes('href')).toBe(expectedHref);
    });
  });

  describe('with slot', () => {
    const mockSlotContent = 'custom button content!';
    it('renders slot content in button', () => {
      createComponent({ slots: { default: mockSlotContent } });
      expect(wrapper.text()).toMatchInterpolatedText(mockSlotContent);
    });
  });
});