Skip to content

Commit

Permalink
Refactor TESTID 140 and clean up
Browse files Browse the repository at this point in the history
Signed-off-by: Anan <[email protected]>
  • Loading branch information
ananzh committed Jan 21, 2025
1 parent 4ebb204 commit c6e7933
Show file tree
Hide file tree
Showing 4 changed files with 533 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import {
INDEX_PATTERN_WITH_TIME,
INDEX_WITH_TIME_1,
} from '../../../../../utils/apps/constants';
import * as dataExplorer from '../../../../../utils/apps/query_enhancements/field_display_filtering.js';
import * as fieldFiltering from '../../../../../utils/apps/query_enhancements/field_display_filtering.js';
import { SECONDARY_ENGINE, BASE_PATH } from '../../../../../utils/constants';
import { NEW_SEARCH_BUTTON } from '../../../../../utils/dashboards/data_explorer/elements.js';
import {
generateAllTestConfigurations,
getRandomizedWorkspaceName,
setDatePickerDatesAndSearchIfRelevant,
} from '../../../../../utils/apps/query_enhancements/shared';
import { generateFieldDisplayFilteringTestConfiguration } from '../../../../../utils/apps/query_enhancements/field_display_filtering';

const workspace = getRandomizedWorkspaceName();

Expand Down Expand Up @@ -65,162 +64,162 @@ describe('filter for value spec', () => {
cy.deleteIndex(INDEX_WITH_TIME_1);
});

generateAllTestConfigurations(generateFieldDisplayFilteringTestConfiguration).forEach(
(config) => {
it(`filter actions in table field for ${config.testName}`, () => {
cy.setDataset(config.dataset, DATASOURCE_NAME, config.datasetType);
cy.setQueryLanguage(config.language);
setDatePickerDatesAndSearchIfRelevant(config.language);
generateAllTestConfigurations(
fieldFiltering.generateFieldDisplayFilteringTestConfiguration
).forEach((config) => {
it(`filter actions in table field for ${config.testName}`, () => {
cy.setDataset(config.dataset, DATASOURCE_NAME, config.datasetType);
cy.setQueryLanguage(config.language);
setDatePickerDatesAndSearchIfRelevant(config.language);

cy.getElementByTestId('docTable').get('tbody tr').should('have.length.above', 3); // To ensure it waits until a full table is loaded into the DOM, instead of a bug where table only has 1 hit.
cy.getElementByTestId('docTable').get('tbody tr').should('have.length.above', 3); // To ensure it waits until a full table is loaded into the DOM, instead of a bug where table only has 1 hit.

const shouldText = config.isFilterButtonsEnabled ? 'exist' : 'not.exist';
dataExplorer.getDocTableField(0, 0).within(() => {
cy.getElementByTestId('filterForValue').should(shouldText);
cy.getElementByTestId('filterOutValue').should(shouldText);
});
const shouldText = config.isFilterButtonsEnabled ? 'exist' : 'not.exist';
fieldFiltering.getDocTableField(0, 0).within(() => {
cy.getElementByTestId('filterForValue').should(shouldText);
cy.getElementByTestId('filterOutValue').should(shouldText);
});

if (config.isFilterButtonsEnabled) {
fieldFiltering.verifyDocTableFilterAction(0, 'filterForValue', '10,000', '1', true);
fieldFiltering.verifyDocTableFilterAction(0, 'filterOutValue', '10,000', '9,999', false);
}
});

if (config.isFilterButtonsEnabled) {
dataExplorer.verifyDocTableFilterAction(0, 'filterForValue', '10,000', '1', true);
dataExplorer.verifyDocTableFilterAction(0, 'filterOutValue', '10,000', '9,999', false);
it(`filter actions in expanded table for ${config.testName}`, () => {
// Check if the first expanded Doc Table Field's first row's Filter For, Filter Out and Exists Filter buttons are disabled.
const verifyFirstExpandedFieldFilterForFilterOutFilterExistsButtons = () => {
const shouldText = config.isFilterButtonsEnabled ? 'be.enabled' : 'be.disabled';
fieldFiltering.getExpandedDocTableRow(0, 0).within(() => {
cy.getElementByTestId('addInclusiveFilterButton').should(shouldText);
cy.getElementByTestId('removeInclusiveFilterButton').should(shouldText);
cy.getElementByTestId('addExistsFilterButton').should(shouldText);
});
};

/**
* Check the Filter For or Out buttons in the expandedDocumentRowNumberth field in the expanded Document filters the correct value.
* @param {string} filterButton For or Out
* @param {number} docTableRowNumber Integer starts from 0 for the first row
* @param {number} expandedDocumentRowNumber Integer starts from 0 for the first row
* @param {string} expectedQueryHitsWithoutFilter expected number of hits in string after the filter is removed Note you should add commas when necessary e.g. 9,999
* @param {string} expectedQueryHitsAfterFilterApplied expected number of hits in string after the filter is applied. Note you should add commas when necessary e.g. 9,999
* @example verifyDocTableFirstExpandedFieldFirstRowFilterForButtonFiltersCorrectField('for', 0, 0, '10,000', '1');
*/
const verifyDocTableFirstExpandedFieldFirstRowFilterForOutButtonFiltersCorrectField = (
filterButton,
docTableRowNumber,
expandedDocumentRowNumber,
expectedQueryHitsWithoutFilter,
expectedQueryHitsAfterFilterApplied
) => {
if (filterButton !== 'for' || filterButton !== 'out') {
cy.log('Filter button must be for or or.');
return;
}
});

it(`filter actions in expanded table for ${config.testName}`, () => {
// Check if the first expanded Doc Table Field's first row's Filter For, Filter Out and Exists Filter buttons are disabled.
const verifyFirstExpandedFieldFilterForFilterOutFilterExistsButtons = () => {
const shouldText = config.isFilterButtonsEnabled ? 'be.enabled' : 'be.disabled';
dataExplorer.getExpandedDocTableRow(0, 0).within(() => {
cy.getElementByTestId('addInclusiveFilterButton').should(shouldText);
cy.getElementByTestId('removeInclusiveFilterButton').should(shouldText);
cy.getElementByTestId('addExistsFilterButton').should(shouldText);
const filterButtonElement =
filterButton === 'for' ? 'addInclusiveFilterButton' : 'removeInclusiveFilterButton';
const shouldText = filterButton === 'for' ? 'have.text' : 'not.have.text';

fieldFiltering
.getExpandedDocTableRowValue(docTableRowNumber, expandedDocumentRowNumber)
.then(($expandedDocumentRowValue) => {
const filterFieldText = $expandedDocumentRowValue.text();
fieldFiltering
.getExpandedDocTableRow(docTableRowNumber, expandedDocumentRowNumber)
.within(() => {
cy.getElementByTestId(filterButtonElement).click();
});
// Verify pill text
cy.getElementByTestId('globalFilterLabelValue').should('have.text', filterFieldText);
cy.getElementByTestId('discoverQueryHits').should(
'have.text',
expectedQueryHitsAfterFilterApplied
); // checkQueryHitText must be in front of checking first line text to give time for DocTable to update.
fieldFiltering
.getExpandedDocTableRowValue(docTableRowNumber, expandedDocumentRowNumber)
.should(shouldText, filterFieldText);
});
};

/**
* Check the Filter For or Out buttons in the expandedDocumentRowNumberth field in the expanded Document filters the correct value.
* @param {string} filterButton For or Out
* @param {number} docTableRowNumber Integer starts from 0 for the first row
* @param {number} expandedDocumentRowNumber Integer starts from 0 for the first row
* @param {string} expectedQueryHitsWithoutFilter expected number of hits in string after the filter is removed Note you should add commas when necessary e.g. 9,999
* @param {string} expectedQueryHitsAfterFilterApplied expected number of hits in string after the filter is applied. Note you should add commas when necessary e.g. 9,999
* @example verifyDocTableFirstExpandedFieldFirstRowFilterForButtonFiltersCorrectField('for', 0, 0, '10,000', '1');
*/
const verifyDocTableFirstExpandedFieldFirstRowFilterForOutButtonFiltersCorrectField = (
filterButton,
docTableRowNumber,
expandedDocumentRowNumber,
expectedQueryHitsWithoutFilter,
expectedQueryHitsAfterFilterApplied
) => {
if (filterButton !== 'for' || filterButton !== 'out') {
cy.log('Filter button must be for or or.');
return;
}

const filterButtonElement =
filterButton === 'for' ? 'addInclusiveFilterButton' : 'removeInclusiveFilterButton';
const shouldText = filterButton === 'for' ? 'have.text' : 'not.have.text';

dataExplorer
.getExpandedDocTableRowValue(docTableRowNumber, expandedDocumentRowNumber)
.then(($expandedDocumentRowValue) => {
const filterFieldText = $expandedDocumentRowValue.text();
dataExplorer
.getExpandedDocTableRow(docTableRowNumber, expandedDocumentRowNumber)
.within(() => {
cy.getElementByTestId(filterButtonElement).click();
});
// Verify pill text
cy.getElementByTestId('globalFilterLabelValue').should('have.text', filterFieldText);
cy.getElementByTestId('discoverQueryHits').should(
'have.text',
expectedQueryHitsAfterFilterApplied
); // checkQueryHitText must be in front of checking first line text to give time for DocTable to update.
dataExplorer
.getExpandedDocTableRowValue(docTableRowNumber, expandedDocumentRowNumber)
.should(shouldText, filterFieldText);
});
cy.getElementByTestId('globalFilterBar').find('[aria-label="Delete"]').click();
cy.getElementByTestId('discoverQueryHits').should(
'have.text',
expectedQueryHitsWithoutFilter
);
};

/**
* Check the first expanded Doc Table Field's first row's Exists Filter button filters the correct Field.
* @param {number} docTableRowNumber Integer starts from 0 for the first row
* @param {number} expandedDocumentRowNumber Integer starts from 0 for the first row
* @param {string} expectedQueryHitsWithoutFilter expected number of hits in string after the filter is removed Note you should add commas when necessary e.g. 9,999
* @param {string} expectedQueryHitsAfterFilterApplied expected number of hits in string after the filter is applied. Note you should add commas when necessary e.g. 9,999
*/
const verifyDocTableFirstExpandedFieldFirstRowExistsFilterButtonFiltersCorrectField = (
docTableRowNumber,
expandedDocumentRowNumber,
expectedQueryHitsWithoutFilter,
expectedQueryHitsAfterFilterApplied
) => {
dataExplorer
.getExpandedDocTableRowFieldName(docTableRowNumber, expandedDocumentRowNumber)
.then(($expandedDocumentRowField) => {
const filterFieldText = $expandedDocumentRowField.text();
dataExplorer
.getExpandedDocTableRow(docTableRowNumber, expandedDocumentRowNumber)
.within(() => {
cy.getElementByTestId('addExistsFilterButton').click();
});
// Verify full pill text
// globalFilterLabelValue gives the inner element, but we may want all the text in the filter pill
cy.getElementByTestId('globalFilterLabelValue', {
timeout: 10000,
})
.parent()
.should('have.text', filterFieldText + ': ' + 'exists');
cy.getElementByTestId('discoverQueryHits').should(
'have.text',
expectedQueryHitsAfterFilterApplied
);
});
cy.getElementByTestId('globalFilterBar').find('[aria-label="Delete"]').click();
cy.getElementByTestId('discoverQueryHits').should(
'have.text',
expectedQueryHitsWithoutFilter
);
};

cy.setDataset(config.dataset, DATASOURCE_NAME, config.datasetType);
cy.setQueryLanguage(config.language);
setDatePickerDatesAndSearchIfRelevant(config.language);

cy.getElementByTestId('docTable').get('tbody tr').should('have.length.above', 3); // To ensure it waits until a full table is loaded into the DOM, instead of a bug where table only has 1 hit.
dataExplorer.toggleDocTableRow(0);
verifyFirstExpandedFieldFilterForFilterOutFilterExistsButtons();
dataExplorer.verifyDocTableFirstExpandedFieldFirstRowToggleColumnButtonHasIntendedBehavior();

if (config.isFilterButtonsEnabled) {
verifyDocTableFirstExpandedFieldFirstRowFilterForOutButtonFiltersCorrectField(
'for',
0,
0,
'10,000',
'1'
);
verifyDocTableFirstExpandedFieldFirstRowFilterForOutButtonFiltersCorrectField(
'out',
0,
0,
'10,000',
'9,999'
);
verifyDocTableFirstExpandedFieldFirstRowExistsFilterButtonFiltersCorrectField(
0,
0,
'10,000',
'10,000'
);
}
});
}
);
cy.getElementByTestId('globalFilterBar').find('[aria-label="Delete"]').click();
cy.getElementByTestId('discoverQueryHits').should(
'have.text',
expectedQueryHitsWithoutFilter
);
};

/**
* Check the first expanded Doc Table Field's first row's Exists Filter button filters the correct Field.
* @param {number} docTableRowNumber Integer starts from 0 for the first row
* @param {number} expandedDocumentRowNumber Integer starts from 0 for the first row
* @param {string} expectedQueryHitsWithoutFilter expected number of hits in string after the filter is removed Note you should add commas when necessary e.g. 9,999
* @param {string} expectedQueryHitsAfterFilterApplied expected number of hits in string after the filter is applied. Note you should add commas when necessary e.g. 9,999
*/
const verifyDocTableFirstExpandedFieldFirstRowExistsFilterButtonFiltersCorrectField = (
docTableRowNumber,
expandedDocumentRowNumber,
expectedQueryHitsWithoutFilter,
expectedQueryHitsAfterFilterApplied
) => {
fieldFiltering
.getExpandedDocTableRowFieldName(docTableRowNumber, expandedDocumentRowNumber)
.then(($expandedDocumentRowField) => {
const filterFieldText = $expandedDocumentRowField.text();
fieldFiltering
.getExpandedDocTableRow(docTableRowNumber, expandedDocumentRowNumber)
.within(() => {
cy.getElementByTestId('addExistsFilterButton').click();
});
// Verify full pill text
// globalFilterLabelValue gives the inner element, but we may want all the text in the filter pill
cy.getElementByTestId('globalFilterLabelValue', {
timeout: 10000,
})
.parent()
.should('have.text', filterFieldText + ': ' + 'exists');
cy.getElementByTestId('discoverQueryHits').should(
'have.text',
expectedQueryHitsAfterFilterApplied
);
});
cy.getElementByTestId('globalFilterBar').find('[aria-label="Delete"]').click();
cy.getElementByTestId('discoverQueryHits').should(
'have.text',
expectedQueryHitsWithoutFilter
);
};

cy.setDataset(config.dataset, DATASOURCE_NAME, config.datasetType);
cy.setQueryLanguage(config.language);
setDatePickerDatesAndSearchIfRelevant(config.language);

cy.getElementByTestId('docTable').get('tbody tr').should('have.length.above', 3); // To ensure it waits until a full table is loaded into the DOM, instead of a bug where table only has 1 hit.
fieldFiltering.toggleDocTableRow(0);
verifyFirstExpandedFieldFilterForFilterOutFilterExistsButtons();
fieldFiltering.verifyDocTableFirstExpandedFieldFirstRowToggleColumnButtonHasIntendedBehavior();

if (config.isFilterButtonsEnabled) {
verifyDocTableFirstExpandedFieldFirstRowFilterForOutButtonFiltersCorrectField(
'for',
0,
0,
'10,000',
'1'
);
verifyDocTableFirstExpandedFieldFirstRowFilterForOutButtonFiltersCorrectField(
'out',
0,
0,
'10,000',
'9,999'
);
verifyDocTableFirstExpandedFieldFirstRowExistsFilterButtonFiltersCorrectField(
0,
0,
'10,000',
'10,000'
);
}
});
});
});
Loading

0 comments on commit c6e7933

Please sign in to comment.