-
Notifications
You must be signed in to change notification settings - Fork 596
/
annotations.cy.ts
196 lines (182 loc) · 6.71 KB
/
annotations.cy.ts
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import { safeLoad, safeDump } from 'js-yaml';
import { defaultsDeep } from 'lodash';
import { checkErrors, testName } from '../../support';
import { detailsPage } from '../../views/details-page';
import { errorMessage } from '../../views/form';
import { listPage } from '../../views/list-page';
import { modal } from '../../views/modal';
import { nav } from '../../views/nav';
import * as yamlEditor from '../../views/yaml-editor';
import { projectDropdown } from '../../views/common';
const createExampleConfigMapInstance = () => {
cy.initAdmin();
nav.sidenav.clickNavLink(['Workloads', 'ConfigMaps']);
cy.byLegacyTestID('resource-title').should('have.text', 'ConfigMaps');
projectDropdown.selectProject(testName);
projectDropdown.shouldContain(testName);
listPage.clickCreateYAMLbutton();
cy.byTestID('yaml-view-input').click();
cy.byTestID('resource-sidebar').should('exist');
yamlEditor.isLoaded();
let newContent;
// get, update, and set yaml editor content.
yamlEditor.getEditorContent().then((content) => {
newContent = defaultsDeep({}, { metadata: { name: 'example' } }, safeLoad(content));
yamlEditor.setEditorContent(safeDump(newContent, { sortKeys: true })).then(() => {
yamlEditor.clickSaveCreateButton();
cy.get(errorMessage).should('not.exist');
});
});
};
const deleteExampleConfigMapInstance = () => {
detailsPage.isLoaded();
detailsPage.titleShouldContain('example');
detailsPage.clickPageActionFromDropdown('Delete ConfigMap');
modal.shouldBeOpened();
modal.submit();
modal.shouldBeClosed();
cy.get(errorMessage).should('not.exist');
};
const getNameValueEditorRow = (row: number) => {
return cy.byTestID('pairs-list-row').eq(row);
};
const setName = (row: JQuery<HTMLElement>, nameValue: string) => {
cy.wrap(row).within(() => {
cy.byTestID('pairs-list-name').type(nameValue);
});
};
const setValue = (row: JQuery<HTMLElement>, value: string) => {
cy.wrap(row).within(() => {
cy.byTestID('pairs-list-value').type(value);
});
};
const clearValue = (row: JQuery<HTMLElement>) => {
cy.wrap(row).within(() => {
cy.byTestID('pairs-list-value').clear();
});
};
const nameValueEquals = (row: JQuery<HTMLElement>, name: string, value: string) => {
cy.wrap(row).within(() => {
cy.byTestID('pairs-list-name').should('have.value', name);
cy.byTestID('pairs-list-value').should('have.value', value);
});
};
describe('Annotations', () => {
before(() => {
cy.login();
cy.createProjectWithCLI(testName);
createExampleConfigMapInstance();
});
afterEach(() => {
checkErrors();
});
after(() => {
deleteExampleConfigMapInstance();
cy.deleteProjectWithCLI(testName);
cy.logout();
});
it(`Creates, Edits, Updates, and Deletes Annotations`, () => {
const ANNOTATION_KEY = 'ALPHA_Num_KEY-3';
const ANNOTATION_VALUE = 'ALPHA_Num_VALUE-2';
const annotations = [
{
key: 'ALPHA_Num_KEY-1',
value: 'ALPHA_Num_VALUE-1',
},
{
key: 'ALPHA_Num_KEY-2',
value: '',
},
{
key: '',
value: 'ALPHA_Num_VALUE-3',
},
];
cy.url().should('include', `/k8s/ns/${testName}/configmaps/example`);
detailsPage.isLoaded();
detailsPage.titleShouldContain('example');
cy.byTestID('edit-annotations').contains('0 annotations');
cy.log('Add annotations');
detailsPage.clickPageActionFromDropdown('Edit annotations');
modal.shouldBeOpened();
getNameValueEditorRow(0).then((row) => {
setName(row, annotations[0].key);
setValue(row, annotations[0].value);
});
cy.byTestID('add-button').click();
getNameValueEditorRow(1).then((row) => {
setName(row, annotations[1].key); // adding only a key, no value, for 2nd annotation
});
cy.byTestID('add-button').click();
getNameValueEditorRow(2).then((row) => {
setValue(row, annotations[2].value); // adding only a value, no key, for 3rd annotation
});
modal.submit();
modal.shouldBeClosed();
cy.log('Verify first two saved annotations');
cy.byTestID('edit-annotations').contains('2 annotation'); // 3rd annotation without key should not have been saved
detailsPage.clickPageActionFromDropdown('Edit annotations');
modal.shouldBeOpened();
getNameValueEditorRow(0).then((row) => {
nameValueEquals(row, annotations[0].key, annotations[0].value);
});
getNameValueEditorRow(1).then((row) => {
nameValueEquals(row, annotations[1].key, annotations[1].value);
});
cy.log('Update first annotation (value to empty)');
getNameValueEditorRow(0).then((row) => {
clearValue(row);
});
cy.log('Update second annotation (empty to value)');
getNameValueEditorRow(1).then((row) => {
setValue(row, ANNOTATION_VALUE);
});
cy.log('Add third annotation');
cy.byTestID('add-button').click();
getNameValueEditorRow(2).then((row) => {
setName(row, ANNOTATION_KEY); // new key
setValue(row, annotations[2].value);
});
modal.submit();
modal.shouldBeClosed();
cy.log('Verify all three annotations');
cy.byTestID('edit-annotations').contains('3 annotations');
detailsPage.clickPageActionFromDropdown('Edit annotations');
modal.shouldBeOpened();
getNameValueEditorRow(0).then((row) => {
nameValueEquals(row, annotations[0].key, ''); // cleared 1st annotation value
});
getNameValueEditorRow(1).then((row) => {
nameValueEquals(row, annotations[1].key, ANNOTATION_VALUE); // empty to updated value
});
getNameValueEditorRow(2).then((row) => {
nameValueEquals(row, ANNOTATION_KEY, annotations[2].value); // new key
});
modal.cancel();
modal.shouldBeClosed();
cy.log('Delete 2nd annotation');
detailsPage.clickPageActionFromDropdown('Edit annotations');
modal.shouldBeOpened();
cy.byTestID('delete-button').eq(1).click();
modal.submit();
modal.shouldBeClosed();
cy.byTestID('edit-annotations').contains('2 annotations');
detailsPage.clickPageActionFromDropdown('Edit annotations');
modal.shouldBeOpened();
cy.log('verify 2nd annotation has been removed');
// first annotation should be the same
getNameValueEditorRow(0).then((row) => {
nameValueEquals(row, annotations[0].key, ''); // cleared 1st annotation value
});
// 2nd annotation should now have the key/value of 3rd annotation because previous 2nd annotation was deleted
getNameValueEditorRow(1).then((row) => {
nameValueEquals(row, ANNOTATION_KEY, annotations[2].value); // new key
});
cy.log('Delete all annotations');
cy.byTestID('delete-button').first().click();
cy.byTestID('delete-button').click();
modal.submit();
modal.shouldBeClosed();
cy.byTestID('edit-annotations').contains('0 annotations');
});
});