Skip to content

Commit a916914

Browse files
Using form-elements-validation commands
1 parent be4365c commit a916914

File tree

1 file changed

+63
-45
lines changed
  • cypress/e2e/ui/Settings/Application-Settings

1 file changed

+63
-45
lines changed

cypress/e2e/ui/Settings/Application-Settings/zone.cy.js

Lines changed: 63 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
/* eslint-disable no-undef */
22
import { flashClassMap } from '../../../../support/assertions/assertion_constants';
3+
import {
4+
LABEL_CONFIG_KEYS,
5+
FIELD_CONFIG_KEYS,
6+
FIELD_TYPES,
7+
BUTTON_CONFIG_KEYS,
8+
} from '../../../../support/commands/constants/command_constants.js';
39

410
// Component route url
511
const COMPONENT_ROUTE_URL = '/ops/explorer#/';
@@ -78,51 +84,63 @@ function addZone() {
7884
function validateFormElements(isEditForm = false) {
7985
cy.expect_explorer_title(FORM_HEADER_FRAGMENT);
8086
cy.get('#main-content .bx--form h3').contains(INFO_SUB_HEADER);
81-
cy.getFormLabelByForAttribute({ forValue: 'name' })
82-
.should('be.visible')
83-
.and('contain.text', NAME_FIELD_LABEL);
84-
cy.getFormInputFieldByIdAndType({ inputId: 'name' })
85-
.should('be.visible')
86-
.then((nameField) => {
87-
if (isEditForm) {
88-
expect(nameField).to.be.disabled;
89-
} else {
90-
expect(nameField).to.not.be.disabled;
91-
}
92-
});
93-
cy.getFormLabelByForAttribute({ forValue: 'description' })
94-
.should('be.visible')
95-
.and('contain.text', DESCRIPTION_FIELD_LABEL);
96-
cy.getFormInputFieldByIdAndType({ inputId: 'description' })
97-
.should('be.visible')
98-
.and('be.enabled');
99-
cy.getFormLabelByForAttribute({ forValue: 'settings.proxy_server_ip' })
100-
.should('be.visible')
101-
.and('contain.text', SERVER_IP_FIELD_LABEL);
102-
cy.getFormInputFieldByIdAndType({ inputId: 'settings.proxy_server_ip' })
103-
.should('be.visible')
104-
.and('be.enabled');
105-
cy.get('#main-content .bx--form h3').contains(SETTINGS_SUB_HEADER);
106-
cy.getFormLabelByForAttribute({ forValue: 'settings.concurrent_vm_scans' })
107-
.should('be.visible')
108-
.and('contain.text', MAX_SCAN_FIELD_LABEL);
109-
cy.getFormSelectFieldById({ selectId: 'settings.concurrent_vm_scans' })
110-
.should('be.visible')
111-
.and('be.enabled');
112-
cy.getFormFooterButtonByTypeWithText({ buttonText: CANCEL_BUTTON_TEXT })
113-
.should('be.visible')
114-
.and('be.enabled');
115-
if (isEditForm) {
116-
cy.getFormFooterButtonByTypeWithText({ buttonText: RESET_BUTTON_TEXT })
117-
.should('be.visible')
118-
.and('be.disabled');
119-
}
120-
cy.getFormFooterButtonByTypeWithText({
121-
buttonText: isEditForm ? SAVE_BUTTON_TEXT : ADD_BUTTON_TEXT,
122-
buttonType: 'submit',
123-
})
124-
.should('be.visible')
125-
.and('be.disabled');
87+
// Validate form labels
88+
cy.validateFormLabels([
89+
{
90+
[LABEL_CONFIG_KEYS.FOR_VALUE]: 'name',
91+
[LABEL_CONFIG_KEYS.EXPECTED_TEXT]: NAME_FIELD_LABEL,
92+
},
93+
{
94+
[LABEL_CONFIG_KEYS.FOR_VALUE]: 'description',
95+
[LABEL_CONFIG_KEYS.EXPECTED_TEXT]: DESCRIPTION_FIELD_LABEL,
96+
},
97+
{
98+
[LABEL_CONFIG_KEYS.FOR_VALUE]: 'settings.proxy_server_ip',
99+
[LABEL_CONFIG_KEYS.EXPECTED_TEXT]: SERVER_IP_FIELD_LABEL,
100+
},
101+
{
102+
[LABEL_CONFIG_KEYS.FOR_VALUE]: 'settings.concurrent_vm_scans',
103+
[LABEL_CONFIG_KEYS.EXPECTED_TEXT]: MAX_SCAN_FIELD_LABEL,
104+
},
105+
]);
106+
// Validate form fields
107+
cy.validateFormFields([
108+
{
109+
[FIELD_CONFIG_KEYS.ID]: 'name',
110+
[FIELD_CONFIG_KEYS.SHOULD_BE_DISABLED]: isEditForm,
111+
},
112+
{
113+
[FIELD_CONFIG_KEYS.ID]: 'description',
114+
},
115+
{
116+
[FIELD_CONFIG_KEYS.ID]: 'settings.proxy_server_ip',
117+
},
118+
{
119+
[FIELD_CONFIG_KEYS.ID]: 'settings.concurrent_vm_scans',
120+
[FIELD_CONFIG_KEYS.FIELD_TYPE]: FIELD_TYPES.SELECT,
121+
},
122+
]);
123+
// Validate form footer buttons
124+
cy.validateFormFooterButtons([
125+
{
126+
[BUTTON_CONFIG_KEYS.BUTTON_TEXT]: CANCEL_BUTTON_TEXT,
127+
},
128+
{
129+
[BUTTON_CONFIG_KEYS.BUTTON_TEXT]: isEditForm
130+
? SAVE_BUTTON_TEXT
131+
: ADD_BUTTON_TEXT,
132+
[BUTTON_CONFIG_KEYS.BUTTON_TYPE]: 'submit',
133+
[BUTTON_CONFIG_KEYS.SHOULD_BE_DISABLED]: true,
134+
},
135+
...(isEditForm
136+
? [
137+
{
138+
[BUTTON_CONFIG_KEYS.BUTTON_TEXT]: RESET_BUTTON_TEXT,
139+
[BUTTON_CONFIG_KEYS.SHOULD_BE_DISABLED]: true,
140+
},
141+
]
142+
: []),
143+
]);
126144
}
127145

128146
function cleanUp() {

0 commit comments

Comments
 (0)