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: ce6861ff4609186aea76f8ab4767b7e052be500f (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { nextTick } from 'vue';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';

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

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

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 findSetupInstructions = () => wrapper.findComponent(SetupInstructions);
  const findSignInOauthButton = () => wrapper.findComponent(SignInOauthButton);
  const findVersionSelectForm = () => wrapper.findComponent(VersionSelectForm);
  const findSubtitle = () => wrapper.findByTestId('subtitle');

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

  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', () => {
    describe('when on self-managed', () => {
      beforeEach(() => {
        retrieveBaseUrl.mockReturnValue(mockBasePath);
        createComponent();
      });

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

      it('renders setup instructions', () => {
        expect(findSetupInstructions().exists()).toBe(true);
      });

      it('calls setApiBaseURL with correct params', () => {
        expect(setApiBaseURL).toHaveBeenCalledWith(mockBasePath);
      });

      describe('when SetupInstructions emits `next` event', () => {
        beforeEach(async () => {
          findSetupInstructions().vm.$emit('next');
          await nextTick();
        });

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

        it('hides setup instructions', () => {
          expect(findSetupInstructions().exists()).toBe(false);
        });
      });
    });

    describe('when on GitLab.com', () => {
      beforeEach(() => {
        retrieveBaseUrl.mockReturnValue(GITLAB_COM_BASE_PATH);
        createComponent();
      });

      it('does not render setup instructions', () => {
        expect(findSetupInstructions().exists()).toBe(false);
      });

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

      it('does not call setApiBaseURL', () => {
        expect(setApiBaseURL).not.toHaveBeenCalled();
      });

      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);
        });
      });
    });
  });
});