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

index_spec.js « sign_in_gitlab_multiversion « sign_in « pages « subscriptions « jira_connect « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 10696d25f17943baa2c7e3ce579ffe39bdac3efb (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
import { nextTick } from 'vue';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';

import SignInGitlabMultiversion from '~/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_multiversion/index.vue';
import VersionSelectForm from '~/jira_connect/subscriptions/pages/sign_in/sign_in_gitlab_multiversion/version_select_form.vue';
import SignInOauthButton from '~/jira_connect/subscriptions/components/sign_in_oauth_button.vue';

import { updateInstallation } from '~/jira_connect/subscriptions/api';
import { reloadPage, persistBaseUrl, retrieveBaseUrl } from '~/jira_connect/subscriptions/utils';

jest.mock('~/jira_connect/subscriptions/api', () => {
  return {
    updateInstallation: jest.fn(),
    setApiBaseURL: jest.fn(),
  };
});
jest.mock('~/jira_connect/subscriptions/utils');

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

  const mockBasePath = 'gitlab.mycompany.com';

  const findVersionSelectForm = () => wrapper.findComponent(VersionSelectForm);
  const findSignInOauthButton = () => wrapper.findComponent(SignInOauthButton);
  const findSubtitle = () => wrapper.findByTestId('subtitle');

  const createComponent = () => {
    wrapper = shallowMountExtended(SignInGitlabMultiversion);
  };

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

  describe('when version is not selected', () => {
    describe('VersionSelectForm', () => {
      it('renders version select form', () => {
        createComponent();

        expect(findVersionSelectForm().exists()).toBe(true);
      });

      describe('when form emits "submit" event', () => {
        it('updates the backend, then saves the baseUrl and reloads', async () => {
          updateInstallation.mockResolvedValue({});

          createComponent();

          findVersionSelectForm().vm.$emit('submit', mockBasePath);
          await nextTick();

          expect(updateInstallation).toHaveBeenCalled();
          expect(persistBaseUrl).toHaveBeenCalledWith(mockBasePath);
          expect(reloadPage).toHaveBeenCalled();
        });
      });
    });
  });

  describe('when version is selected', () => {
    beforeEach(() => {
      retrieveBaseUrl.mockReturnValue(mockBasePath);
      createComponent();
    });

    describe('sign in button', () => {
      it('renders sign in button', () => {
        expect(findSignInOauthButton().exists()).toBe(true);
        expect(findSignInOauthButton().props('gitlabBasePath')).toBe(mockBasePath);
      });

      describe('when button emits `sign-in` event', () => {
        it('emits `sign-in-oauth` event', () => {
          const button = findSignInOauthButton();

          const mockUser = { name: 'test' };
          button.vm.$emit('sign-in', mockUser);

          expect(wrapper.emitted('sign-in-oauth')[0]).toEqual([mockUser]);
        });
      });

      describe('when button emits `error` event', () => {
        it('emits `error` event', () => {
          const button = findSignInOauthButton();
          button.vm.$emit('error');

          expect(wrapper.emitted('error')).toHaveLength(1);
        });
      });
    });

    it('renders correct subtitle', () => {
      expect(findSubtitle().text()).toBe(SignInGitlabMultiversion.i18n.signInSubtitle);
    });
  });
});