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
|
import { GlButton, GlTooltip } from '@gitlab/ui';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import CreateTokenButton from '~/clusters/agents/components/create_token_button.vue';
import { CREATE_TOKEN_MODAL } from '~/clusters/agents/constants';
describe('CreateTokenButton', () => {
let wrapper;
const defaultProvide = {
canAdminCluster: true,
};
const findButton = () => wrapper.findComponent(GlButton);
const findTooltip = () => wrapper.findComponent(GlTooltip);
const createWrapper = ({ provideData = {} } = {}) => {
wrapper = shallowMountExtended(CreateTokenButton, {
provide: {
...defaultProvide,
...provideData,
},
directives: {
GlModalDirective: createMockDirective(),
},
stubs: {
GlTooltip,
},
});
};
afterEach(() => {
wrapper.destroy();
});
describe('when user can create token', () => {
beforeEach(() => {
createWrapper();
});
it('displays create agent token button', () => {
expect(findButton().text()).toBe('Create token');
});
it('displays create agent token button as not disabled', () => {
expect(findButton().attributes('disabled')).toBeUndefined();
});
it('triggers the modal', () => {
const binding = getBinding(findButton().element, 'gl-modal-directive');
expect(binding.value).toBe(CREATE_TOKEN_MODAL);
});
});
describe('when user cannot create token', () => {
beforeEach(() => {
createWrapper({ provideData: { canAdminCluster: false } });
});
it('disabled the button', () => {
expect(findButton().attributes('disabled')).toBe('true');
});
it('shows a disabled tooltip', () => {
expect(findTooltip().attributes('title')).toBe(
'Requires a Maintainer or greater role to perform these actions',
);
});
});
});
|