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
|
import { GlFormCheckbox } from '@gitlab/ui';
import { shallowMountExtended, mountExtended } from 'helpers/vue_test_utils_helper';
import SettingsForm from '~/admin/application_settings/inactive_project_deletion/components/form.vue';
describe('Form component', () => {
let wrapper;
const findEnabledCheckbox = () => wrapper.findComponent(GlFormCheckbox);
const findProjectDeletionSettings = () =>
wrapper.findByTestId('inactive-project-deletion-settings');
const findMinSizeGroup = () => wrapper.findByTestId('min-size-group');
const findMinSizeInputGroup = () => wrapper.findByTestId('min-size-input-group');
const findMinSizeInput = () => wrapper.findByTestId('min-size-input');
const findDeleteAfterMonthsGroup = () => wrapper.findByTestId('delete-after-months-group');
const findDeleteAfterMonthsInputGroup = () =>
wrapper.findByTestId('delete-after-months-input-group');
const findDeleteAfterMonthsInput = () => wrapper.findByTestId('delete-after-months-input');
const findSendWarningEmailAfterMonthsGroup = () =>
wrapper.findByTestId('send-warning-email-after-months-group');
const findSendWarningEmailAfterMonthsInputGroup = () =>
wrapper.findByTestId('send-warning-email-after-months-input-group');
const findSendWarningEmailAfterMonthsInput = () =>
wrapper.findByTestId('send-warning-email-after-months-input');
const createComponent = (
mountFn = shallowMountExtended,
propsData = { deleteInactiveProjects: true },
) => {
wrapper = mountFn(SettingsForm, { propsData });
};
describe('Enable inactive project deletion', () => {
it('has the checkbox', () => {
createComponent();
expect(findEnabledCheckbox().exists()).toBe(true);
});
it.each([[true], [false]])(
'when the checkbox is %s then the project deletion settings visibility is set to %s',
(visible) => {
createComponent(shallowMountExtended, { deleteInactiveProjects: visible });
expect(findProjectDeletionSettings().exists()).toBe(visible);
},
);
});
describe('Minimum size for deletion', () => {
beforeEach(() => {
createComponent(mountExtended);
});
it('has the minimum size input', () => {
expect(findMinSizeInput().exists()).toBe(true);
});
it('has the field description', () => {
expect(findMinSizeGroup().text()).toContain('Delete inactive projects that exceed');
});
it('has the appended text on the field', () => {
expect(findMinSizeInputGroup().text()).toContain('MB');
});
it.each`
value | valid
${'0'} | ${true}
${'250'} | ${true}
${'-1'} | ${false}
`(
'when the minimum size input has a value of $value, then its validity should be $valid',
async ({ value, valid }) => {
await findMinSizeInput().find('input').setValue(value);
expect(findMinSizeGroup().classes('is-valid')).toBe(valid);
expect(findMinSizeInput().classes('is-valid')).toBe(valid);
},
);
});
describe('Delete project after', () => {
beforeEach(() => {
createComponent(mountExtended);
});
it('has the delete after months input', () => {
expect(findDeleteAfterMonthsInput().exists()).toBe(true);
});
it('has the appended text on the field', () => {
expect(findDeleteAfterMonthsInputGroup().text()).toContain('months');
});
it.each`
value | valid
${'0'} | ${false}
${'1'} | ${false /* Less than the default send warning email months */}
${'2'} | ${true}
`(
'when the delete after months input has a value of $value, then its validity should be $valid',
async ({ value, valid }) => {
await findDeleteAfterMonthsInput().find('input').setValue(value);
expect(findDeleteAfterMonthsGroup().classes('is-valid')).toBe(valid);
expect(findDeleteAfterMonthsInput().classes('is-valid')).toBe(valid);
},
);
});
describe('Send warning email', () => {
beforeEach(() => {
createComponent(mountExtended);
});
it('has the send warning email after months input', () => {
expect(findSendWarningEmailAfterMonthsInput().exists()).toBe(true);
});
it('has the field description', () => {
expect(findSendWarningEmailAfterMonthsGroup().text()).toContain(
'Send email to maintainers after project is inactive for',
);
});
it('has the appended text on the field', () => {
expect(findSendWarningEmailAfterMonthsInputGroup().text()).toContain('months');
});
it.each`
value | valid
${'2'} | ${true}
${'0'} | ${false}
`(
'when the minimum size input has a value of $value, then its validity should be $valid',
async ({ value, valid }) => {
await findSendWarningEmailAfterMonthsInput().find('input').setValue(value);
expect(findSendWarningEmailAfterMonthsGroup().classes('is-valid')).toBe(valid);
expect(findSendWarningEmailAfterMonthsInput().classes('is-valid')).toBe(valid);
},
);
});
});
|