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
|
import { GlSprintf } from '@gitlab/ui';
import UserLink from '~/jira_connect/subscriptions/components/user_link.vue';
import SignInOauthButton from '~/jira_connect/subscriptions/components/sign_in_oauth_button.vue';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import waitForPromises from 'helpers/wait_for_promises';
jest.mock('~/jira_connect/subscriptions/utils', () => ({
getGitlabSignInURL: jest.fn().mockImplementation((path) => Promise.resolve(path)),
}));
describe('UserLink', () => {
let wrapper;
const createComponent = (propsData = {}, { provide } = {}) => {
wrapper = shallowMountExtended(UserLink, {
propsData,
provide,
stubs: {
GlSprintf,
SignInOauthButton,
},
});
};
const findSignInLink = () => wrapper.findByTestId('sign-in-link');
const findGitlabUserLink = () => wrapper.findByTestId('gitlab-user-link');
const findSprintf = () => wrapper.findComponent(GlSprintf);
const findOauthButton = () => wrapper.findComponent(SignInOauthButton);
describe.each`
userSignedIn | hasSubscriptions | expectGlSprintf | expectGlLink | expectOauthButton | jiraConnectOauthEnabled
${true} | ${false} | ${true} | ${false} | ${false} | ${false}
${false} | ${true} | ${false} | ${true} | ${false} | ${false}
${true} | ${true} | ${true} | ${false} | ${false} | ${false}
${false} | ${false} | ${false} | ${false} | ${false} | ${false}
${false} | ${true} | ${false} | ${false} | ${true} | ${true}
`(
'when `userSignedIn` is $userSignedIn, `hasSubscriptions` is $hasSubscriptions, `jiraConnectOauthEnabled` is $jiraConnectOauthEnabled',
({
userSignedIn,
hasSubscriptions,
expectGlSprintf,
expectGlLink,
expectOauthButton,
jiraConnectOauthEnabled,
}) => {
it('renders template correctly', () => {
createComponent(
{
userSignedIn,
hasSubscriptions,
},
{
provide: {
glFeatures: {
jiraConnectOauth: jiraConnectOauthEnabled,
},
oauthMetadata: {},
},
},
);
expect(findSprintf().exists()).toBe(expectGlSprintf);
expect(findSignInLink().exists()).toBe(expectGlLink);
expect(findOauthButton().exists()).toBe(expectOauthButton);
});
},
);
describe('sign in link', () => {
it('renders with correct href', async () => {
const mockUsersPath = '/user';
createComponent(
{
userSignedIn: false,
hasSubscriptions: true,
},
{ provide: { usersPath: mockUsersPath } },
);
await waitForPromises();
expect(findSignInLink().exists()).toBe(true);
expect(findSignInLink().attributes('href')).toBe(mockUsersPath);
});
});
describe('gitlab user link', () => {
describe.each`
current_username | gitlabUserPath | user | expectedUserHandle | expectedUserLink
${'root'} | ${'/root'} | ${{ username: 'test-user' }} | ${'@root'} | ${'/root'}
${'root'} | ${'/root'} | ${undefined} | ${'@root'} | ${'/root'}
${undefined} | ${undefined} | ${{ username: 'test-user' }} | ${'@test-user'} | ${'/test-user'}
`(
'when current_username=$current_username, gitlabUserPath=$gitlabUserPath and user=$user',
({ current_username, gitlabUserPath, user, expectedUserHandle, expectedUserLink }) => {
beforeEach(() => {
window.gon = { current_username, relative_root_url: '' };
createComponent(
{
userSignedIn: true,
hasSubscriptions: true,
user,
},
{ provide: { gitlabUserPath } },
);
});
it(`sets href to ${expectedUserLink}`, () => {
expect(findGitlabUserLink().attributes('href')).toBe(expectedUserLink);
});
it(`renders ${expectedUserHandle} as text`, () => {
expect(findGitlabUserLink().text()).toBe(expectedUserHandle);
});
},
);
});
});
|