Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
Signed-off-by: Amardeepsingh Siglani <[email protected]>
  • Loading branch information
amsiglan committed Feb 7, 2024
1 parent 6c46e28 commit bbc89c4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,21 @@ const validatePendingFieldMappingsPanel = (mappings) => {
});
};

const fillDetailsForm = (detectorName, dataSource) => {
const fillDetailsForm = (
detectorName,
dataSource,
isCustomDataSource = false
) => {
getNameField().type(detectorName);
getDataSourceField().sa_selectComboboxItem(dataSource);

if (isCustomDataSource) {
getDataSourceField()
.focus()
.type(dataSource + '{enter}');
} else {
getDataSourceField().sa_selectComboboxItem(dataSource);
}

getDataSourceField().focus().blur();
getLogTypeField().sa_selectComboboxItem(getLogTypeLabel(cypressLogTypeDns));
getLogTypeField().focus().blur();
Expand All @@ -149,7 +161,7 @@ const fillDetailsForm = (detectorName, dataSource) => {
const createDetector = (detectorName, dataSource, expectFailure) => {
getCreateDetectorButton().click({ force: true });

fillDetailsForm(detectorName, dataSource);
fillDetailsForm(detectorName, dataSource, expectFailure);

cy.sa_getElementByText(
'.euiAccordion .euiTitle',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,6 @@ const getListRadioField = () => cy.get('[for="selection-map-list-0-0"]');
const getTextRadioField = () => cy.get('[for="selection-map-value-0-0"]');
const getConditionField = () =>
cy.get('[data-test-subj="rule_detection_field"]');
const getConditionAddButton = () =>
cy.get('[data-test-subj="condition-add-selection-btn"]');
const getConditionRemoveButton = (index) =>
cy.get(`[data-test-subj="selection-exp-field-item-remove-${index}"]`);
const getRuleSubmitButton = () =>
cy.get('[data-test-subj="submit_rule_form_button"]');
const getTagField = (index) =>
Expand Down Expand Up @@ -212,8 +208,6 @@ const fillCreateForm = () => {
getMapValueField().type('FieldValue');
});

getConditionAddButton().click({ force: true });

// rule additional details
SAMPLE_RULE.tags.forEach((tag, idx) => {
getTagField(idx).type(tag);
Expand Down Expand Up @@ -387,7 +381,7 @@ describe('Rules', () => {
getMapKeyField()
.parentsUntil('.euiFormRow__fieldWrapper')
.siblings()
.contains('Key name is required');
.contains('Invalid key name');

getMapKeyField().type('FieldKey');
getMapKeyField()
Expand Down Expand Up @@ -443,15 +437,8 @@ describe('Rules', () => {
getRuleSubmitButton().click({ force: true });
getConditionField()
.parents('.euiFormRow__fieldWrapper')
.contains('Condition is required');

getConditionAddButton().click({ force: true });
getConditionField().find('.euiFormErrorText').should('not.exist');

getConditionRemoveButton(0).click({ force: true });
getConditionField()
.parents('.euiFormRow__fieldWrapper')
.contains('Condition is required');
.contains('Condition is required')
.should('not.exist');
});

it('...should validate tag field', () => {
Expand Down Expand Up @@ -512,7 +499,6 @@ describe('Rules', () => {
getSelectionPanelByIndex(0).within(() =>
getMapKeyField().type('{selectall}').type('{backspace}')
);
toastShouldExist();
getSelectionPanelByIndex(0).within(() =>
getMapKeyField().type('FieldKey')
);
Expand All @@ -537,11 +523,6 @@ describe('Rules', () => {
getMapListField().type('FieldValue');
});

// condition field
getConditionRemoveButton(0).click({ force: true });
toastShouldExist();
getConditionAddButton().click({ force: true });

// tags field
getTagField(0).sa_clearValue().type('wrong.tag');
toastShouldExist();
Expand Down

0 comments on commit bbc89c4

Please sign in to comment.