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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
import { GlModal, GlSprintf, GlAlert } from '@gitlab/ui';
import { nextTick } from 'vue';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import Component from '~/feature_flags/components/configure_feature_flags_modal.vue';
describe('Configure Feature Flags Modal', () => {
const mockEvent = { preventDefault: jest.fn() };
const provide = {
projectName: 'fakeProjectName',
featureFlagsHelpPagePath: '/help/path',
featureFlagsClientLibrariesHelpPagePath: '/help/path/#flags',
featureFlagsClientExampleHelpPagePath: '/feature-flags#clientexample',
unleashApiUrl: '/api/url',
};
const propsData = {
instanceId: 'instance-id-token',
isRotating: false,
hasRotateError: false,
canUserRotateToken: true,
};
let wrapper;
const factory = (props = {}, { mountFn = shallowMountExtended, ...options } = {}) => {
wrapper = mountFn(Component, {
provide,
stubs: { GlSprintf },
propsData: {
...propsData,
...props,
},
...options,
});
};
const findGlModal = () => wrapper.findComponent(GlModal);
const findPrimaryAction = () => findGlModal().props('actionPrimary');
const findSecondaryAction = () => findGlModal().props('actionSecondary');
const findProjectNameInput = () => wrapper.find('#project_name_verification');
const findDangerGlAlert = () =>
wrapper.findAllComponents(GlAlert).filter((c) => c.props('variant') === 'danger');
describe('idle', () => {
beforeEach(factory);
it('should have Primary and Secondary actions', () => {
expect(findPrimaryAction().text).toBe('Close');
expect(findSecondaryAction().text).toBe('Regenerate instance ID');
});
it('should default disable the primary action', () => {
const { disabled } = findSecondaryAction().attributes;
expect(disabled).toBe(true);
});
it('should emit a `token` event when clicking on the Primary action', async () => {
findGlModal().vm.$emit('secondary', mockEvent);
await nextTick();
expect(wrapper.emitted('token')).toEqual([[]]);
expect(mockEvent.preventDefault).toHaveBeenCalled();
});
it('should clear the project name input after generating the token', async () => {
findProjectNameInput().vm.$emit('input', provide.projectName);
findGlModal().vm.$emit('primary', mockEvent);
await nextTick();
expect(findProjectNameInput().attributes('value')).toBe('');
});
it('should provide an input for filling the project name', () => {
expect(findProjectNameInput().exists()).toBe(true);
expect(findProjectNameInput().attributes('value')).toBe('');
});
it('should display an help text', () => {
const help = wrapper.find('p');
expect(help.text()).toMatch(/More Information/);
});
it('should have links to the documentation', () => {
expect(wrapper.find('[data-testid="help-link"]').attributes('href')).toBe(
provide.featureFlagsHelpPagePath,
);
expect(wrapper.find('[data-testid="help-client-link"]').attributes('href')).toBe(
provide.featureFlagsClientLibrariesHelpPagePath,
);
});
it('should display one and only one danger alert', () => {
const dangerGlAlert = findDangerGlAlert();
expect(dangerGlAlert.length).toBe(1);
expect(dangerGlAlert.at(0).text()).toMatch(/Regenerating the instance ID/);
});
it('should display a message asking to fill the project name', () => {
expect(wrapper.find('[data-testid="prevent-accident-text"]').text()).toMatch(
provide.projectName,
);
});
it('should display the api URL in an input box', () => {
const input = wrapper.find('#api-url');
expect(input.attributes('value')).toBe('/api/url');
});
it('should display the instance ID in an input box', () => {
const input = wrapper.find('#instance_id');
expect(input.attributes('value')).toBe('instance-id-token');
});
});
describe('verified', () => {
beforeEach(factory);
it('should enable the secondary action', async () => {
findProjectNameInput().vm.$emit('input', provide.projectName);
await nextTick();
const { disabled } = findSecondaryAction().attributes;
expect(disabled).toBe(false);
});
});
describe('cannot rotate token', () => {
beforeEach(factory.bind(null, { canUserRotateToken: false }));
it('should not display the primary action', () => {
expect(findSecondaryAction()).toBe(null);
});
it('should not display regenerating instance ID', async () => {
expect(findDangerGlAlert().exists()).toBe(false);
});
it('should disable the project name input', async () => {
expect(findProjectNameInput().exists()).toBe(false);
});
});
describe('has rotate error', () => {
beforeEach(() => {
factory({ hasRotateError: true });
});
it('should display an error', async () => {
expect(wrapper.findByTestId('rotate-error').exists()).toBe(true);
expect(wrapper.find('[name="warning"]').exists()).toBe(true);
});
});
describe('is rotating', () => {
beforeEach(factory.bind(null, { isRotating: true }));
it('should disable the project name input', async () => {
expect(findProjectNameInput().attributes('disabled')).toBe('true');
});
});
});
|