Skip to content

Commit

Permalink
Cypress tests for query grouping (#55) (#58)
Browse files Browse the repository at this point in the history
(cherry picked from commit 626cb15)

Signed-off-by: Siddhant Deshmukh <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 8599af2 commit a0bde79
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 3 deletions.
56 changes: 53 additions & 3 deletions cypress/e2e/3_configurations.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ describe('Query Insights Configurations Page', () => {
cy.contains('button', 'Top N queries').should('be.visible');
cy.contains('button', 'Configuration').should('have.class', 'euiTab-isSelected');
// Validate the panels
cy.get('.euiPanel').should('have.length', 4); // Two panels: configuration settings and statuses
cy.get('.euiPanel').should('have.length', 4); // 4 panels: Settings, Status, Group Settings, Group Status
});

/**
* Validate the dropdown has 3 metrics
* Validate the metric type dropdown has 3 metrics
*/
it('should display 3 metrics in the drop down', () => {
it('should display 3 metrics in the metric type drop down', () => {
// Validate default value
cy.get('select').first().find('option').should('have.length', 3);
const expectedMetrics = ['Latency', 'CPU', 'Memory'];
Expand Down Expand Up @@ -137,6 +137,56 @@ describe('Query Insights Configurations Page', () => {
});
});

/**
* Validate configuration settings panel for group by
*/
it('should display settings for configuration metrics for group by', () => {
cy.get('.euiPanel')
.eq(2)
.within(() => {
cy.get('h2').contains('Top n queries grouping configuration settings').should('be.visible');
});
});

/**
* Validate the group by drop-down has 2 options
*/
it('should display 2 metrics in the group by drop-down', () => {
cy.get('.euiPanel')
.eq(2)
.find('select')
.should('exist')
.then(($select) => {
cy.wrap($select).find('option').should('have.length', 2);

const expectedMetrics = ['None', 'Similarity'];

cy.wrap($select)
.find('option')
.each((option, index) => {
cy.wrap(option).should('have.text', expectedMetrics[index]);
});
});
});

/**
* Validate configuration status panel for group by
*/
it('should display configuration statuses for group by metrics', () => {
cy.get('.euiPanel')
.eq(3)
.within(() => {
cy.get('h2').should('be.visible').and('have.text', 'Statuses for group by');

const metrics = [{ name: 'Group By', status: 'Disabled' }];

metrics.forEach(({ name, status }) => {
cy.get('.euiText').contains(name).should('be.visible');
cy.get('.euiHealth').contains(status).should('be.visible');
});
});
});

/**
* Validate the save button, changes should be saved and redirect to overview
* After saving the status panel should show the correct status
Expand Down
104 changes: 104 additions & 0 deletions cypress/e2e/4_group_details.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import sampleDocument from '../fixtures/sample_document.json';

const indexName = 'sample_index';

const clearAll = () => {
cy.deleteIndexByName(indexName);
cy.disableGrouping();
};

describe('Query Group Details Page', () => {
beforeEach(() => {
clearAll();
cy.createIndexByName(indexName, sampleDocument);
cy.enableGrouping();
cy.searchOnIndex(indexName);
cy.searchOnIndex(indexName);
cy.searchOnIndex(indexName);
// waiting for the query insights queue to drain
cy.wait(10000);
cy.navigateToOverview();
cy.get('.euiTableRow').first().find('button').first().click(); // Navigate to details
});

it('should display correct details on the group details page', () => {
cy.url().should('include', '/query-group-details');
// Validate the page title
cy.get('h1').contains('Query group details').should('be.visible');

// Validate tooltip for query group details
cy.get('[aria-label="Details tooltip"]').eq(0).should('be.visible');

// Validate the Sample Query Details section
cy.get('h1').contains('Sample query details').should('be.visible');

// Validate tooltip for sample query details
cy.get('[aria-label="Details tooltip"]').eq(1).should('be.visible');

// Validate the presence of query source section
cy.get('.euiPanel').contains('Query').should('be.visible');

// Validate the presence of the latency chart
cy.get('#latency').should('be.visible');
});

it('should validate the aggregate summary fields', () => {
const expectedLabels = [
'Id',
'Average Latency',
'Average CPU Time',
'Average Memory Usage',
'Group by',
];

// Validate all field labels exist in the first EuiPanel
cy.get('.euiPanel')
.first()
.within(() => {
expectedLabels.forEach((label) => {
cy.contains('h4', label).should('be.visible');
});
});
});

it('should validate the sample query summary panel fields', () => {
const expectedLabels = [
'Timestamp',
'Indices',
'Search Type',
'Coordinator Node ID',
'Total Shards',
];

// Validate all field labels exist in the second EuiPanel
cy.get('.euiPanel')
.eq(1)
.within(() => {
expectedLabels.forEach((label) => {
cy.contains('h4', label).should('be.visible');
});
});
});

it('should display the query source code block', () => {
// Validate the query source code block
cy.get('.euiCodeBlock').should('be.visible');
});

it('should display the latency panel correctly', () => {
// Validate the fourth EuiPanel contains the Latency section
cy.get('.euiPanel')
.eq(3)
.within(() => {
cy.contains('h2', 'Latency').should('be.visible');
cy.get('#latency').should('be.visible');
});
});

after(() => clearAll());
});
41 changes: 41 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,47 @@ Cypress.Commands.add('disableTopQueries', (metric) => {
});
});

Cypress.Commands.add('enableGrouping', () => {
cy.request({
method: 'PUT',
url: `${Cypress.env('openSearchUrl')}/_cluster/settings`,
body: {
persistent: {
'search.insights.top_queries.latency.enabled': true,
'search.insights.top_queries.cpu.enabled': true,
'search.insights.top_queries.memory.enabled': true,
'search.insights.top_queries.group_by': 'similarity',
'search.insights.top_queries.max_groups_excluding_topn': 100,
'search.insights.top_queries.grouping.attributes.field_name': true,
'search.insights.top_queries.grouping.attributes.field_type': true,
'search.insights.top_queries.latency.top_n_size': 5,
'search.insights.top_queries.cpu.top_n_size': 5,
'search.insights.top_queries.memory.top_n_size': 5,
'search.insights.top_queries.latency.window_size': '1m',
'search.insights.top_queries.cpu.window_size': '1m',
'search.insights.top_queries.memory.window_size': '1m',
},
},
failOnStatusCode: false,
});
});

Cypress.Commands.add('disableGrouping', () => {
cy.request({
method: 'PUT',
url: `${Cypress.env('openSearchUrl')}/_cluster/settings`,
body: {
persistent: {
'search.insights.top_queries.latency.enabled': false,
'search.insights.top_queries.cpu.enabled': false,
'search.insights.top_queries.memory.enabled': false,
'search.insights.top_queries.group_by': 'none',
},
},
failOnStatusCode: false,
});
});

Cypress.Commands.add('createIndexByName', (indexName, body = {}) => {
cy.request('POST', `${Cypress.env('openSearchUrl')}/${indexName}/_doc`, body);
});
Expand Down

0 comments on commit a0bde79

Please sign in to comment.