Skip to content

Commit

Permalink
add testid-42 tests
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Silva <[email protected]>
  • Loading branch information
silvaf-dev committed Feb 4, 2025
1 parent 001246c commit 35306b6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import {
generateMaxRecentQueriesTestConfiguration,
BaseQuery,
TestQueries,
} from '../../../../../utils/apps/query_enhancements/max_recent_queries';
} from '../../../../../utils/apps/query_enhancements/recent_queries';

const workspace = getRandomizedWorkspaceName();

describe('filter for value spec', { testIsolation: true }, () => {
describe('recent queries spec', { testIsolation: true }, () => {
const index = INDEX_PATTERN_WITH_TIME.replace('*', '');
beforeEach(() => {
// Load test data
Expand Down Expand Up @@ -75,8 +75,6 @@ describe('filter for value spec', { testIsolation: true }, () => {
cy.setDataset(config.dataset, DATASOURCE_NAME, config.datasetType);
cy.setQueryLanguage(config.language);
setDatePickerDatesAndSearchIfRelevant(config.language);
cy.log(BaseQuery[config.datasetType].toString());
cy.log(config.language);
const currentBaseQuery = BaseQuery[config.datasetType][config.language];
TestQueries.forEach((query) => {
cy.setQueryEditor(currentBaseQuery + query, {}, true);
Expand Down Expand Up @@ -104,5 +102,50 @@ describe('filter for value spec', { testIsolation: true }, () => {
});
cy.contains(query).should('have.length', 1);
});

it(`check running and copying recent queries for ${config.testName}`, () => {
const checkRowText = (rowIndex, expectedQuery) => {
cy.getElementByTestIdLike('row-').each(($row, $index) => {
if ($index === rowIndex) {
expect($row.text()).to.include(expectedQuery);
}
});
};
cy.setDataset(config.dataset, DATASOURCE_NAME, config.datasetType);
cy.setQueryLanguage(config.language);
setDatePickerDatesAndSearchIfRelevant(config.language);
// Precondition: run some queries first
const currentBaseQuery = BaseQuery[config.datasetType][config.language];
const queries = [...TestQueries].splice(0, 3);
queries.forEach((query) => {
cy.setQueryEditor(currentBaseQuery + query, {}, true);
});
cy.getElementByTestId('queryEditorFooterToggleRecentQueriesButton').click({
force: true,
});
const expectedQuery = currentBaseQuery + queries[0];
checkRowText(2, expectedQuery);
cy.getElementByTestId('action-run').eq(2).click({ force: true });
cy.wait(2000);
checkRowText(0, expectedQuery);

cy.getElementByTestIdLike('row-')
.eq(1)
.then(($row) => {
cy.get('[aria-label="Copy recent query"]').eq(1).click({ force: true });
cy.wait(1000);
const regex = {
PPL: /.*?(source .*? 8000)(?:.*)/s,
'OpenSearch SQL': /.*?(SELECT .*? 8000)(?:.*)/s,
};
const expectedQuery = $row.text().replace(regex[config.language], '$1');
// necessary for hiding the syntax helper message box (again)
cy.getElementByTestId('languageReferenceButton').click();
cy.window()
.its('navigator.clipboard')
.then(($clip) => $clip.readText())
.should('eq', expectedQuery);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { INDEX_PATTERN_WITH_TIME, INDEX_WITH_TIME_1, QueryLanguages } from './constants';

export const MaxQueriesDataTypes = {
export const RecentQueriesDataTypes = {
INDEX_PATTERN: {
name: 'INDEX_PATTERN',
supportedLanguages: [QueryLanguages.SQL, QueryLanguages.PPL],
Expand Down Expand Up @@ -58,11 +58,9 @@ export const TestQueries = [
* @returns {MaxRecentQueriesFilteringTestConfig}
*/
export const generateMaxRecentQueriesTestConfiguration = (dataset, datasetType, language) => {
console.log(MaxQueriesDataTypes[datasetType].name);
console.log(MaxQueriesDataTypes[datasetType].toString());
return {
dataset,
datasetType: MaxQueriesDataTypes[datasetType].name,
datasetType: RecentQueriesDataTypes[datasetType].name,
language: language.name,
testName: `dataset: ${datasetType} and language: ${language.name}`,
};
Expand Down

0 comments on commit 35306b6

Please sign in to comment.