|
| 1 | +/* |
| 2 | + * Copyright OpenSearch Contributors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import sampleDocument from '../../../fixtures/plugins/query-insights-dashboards/sample_document.json'; |
| 7 | +import { QUERY_INSIGHTS_METRICS } from '../../../utils/constants'; |
| 8 | + |
| 9 | +const indexName = 'sample_index'; |
| 10 | + |
| 11 | +const clearAll = () => { |
| 12 | + cy.deleteIndexByName(indexName); |
| 13 | + cy.disableTopQueries(QUERY_INSIGHTS_METRICS.LATENCY); |
| 14 | + cy.disableTopQueries(QUERY_INSIGHTS_METRICS.CPU); |
| 15 | + cy.disableTopQueries(QUERY_INSIGHTS_METRICS.MEMORY); |
| 16 | +}; |
| 17 | + |
| 18 | +describe('Top Queries Details Page', () => { |
| 19 | + beforeEach(() => { |
| 20 | + clearAll(); |
| 21 | + cy.createIndexByName(indexName, sampleDocument); |
| 22 | + cy.enableTopQueries(QUERY_INSIGHTS_METRICS.LATENCY); |
| 23 | + cy.enableTopQueries(QUERY_INSIGHTS_METRICS.CPU); |
| 24 | + cy.enableTopQueries(QUERY_INSIGHTS_METRICS.MEMORY); |
| 25 | + cy.searchOnIndex(indexName); |
| 26 | + cy.searchOnIndex(indexName); |
| 27 | + cy.searchOnIndex(indexName); |
| 28 | + // waiting for the query insights queue to drain |
| 29 | + cy.wait(10000); |
| 30 | + cy.navigateToOverview(); |
| 31 | + cy.wait(10000); |
| 32 | + cy.get('.euiTableRow').first().find('button').first().trigger('mouseover'); |
| 33 | + cy.wait(1000); |
| 34 | + cy.get('.euiTableRow').first().find('button').first().click(); // Navigate to details |
| 35 | + cy.wait(1000); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should display correct details on the query details page', () => { |
| 39 | + // cy.get('.euiBasicTable a').first().click(); // Navigate to details |
| 40 | + cy.url().should('include', '/query-details'); |
| 41 | + // Validate the page title |
| 42 | + cy.get('h1').contains('Query details').should('be.visible'); |
| 43 | + // Validate the summary section |
| 44 | + cy.get('[data-test-subj="query-details-summary-section"]').should( |
| 45 | + 'be.visible' |
| 46 | + ); |
| 47 | + // Validate the presence of latency chart |
| 48 | + cy.get('[data-test-subj="query-details-latency-chart"]').should( |
| 49 | + 'be.visible' |
| 50 | + ); |
| 51 | + // Validate the presence of query source details section |
| 52 | + cy.get('[data-test-subj="query-details-source-section"]').should( |
| 53 | + 'be.visible' |
| 54 | + ); |
| 55 | + }); |
| 56 | + |
| 57 | + /** |
| 58 | + * Validate summary panel has valid labels |
| 59 | + */ |
| 60 | + it('the summary panel should display correctly', () => { |
| 61 | + // Validate all field labels exist |
| 62 | + const fieldLabels = [ |
| 63 | + 'Timestamp', |
| 64 | + 'Latency', |
| 65 | + 'CPU Time', |
| 66 | + 'Memory Usage', |
| 67 | + 'Indices', |
| 68 | + 'Search Type', |
| 69 | + 'Coordinator Node ID', |
| 70 | + 'Total Shards', |
| 71 | + ]; |
| 72 | + fieldLabels.forEach((label) => { |
| 73 | + cy.get('.euiPanel').contains('h4', label).should('be.visible'); |
| 74 | + }); |
| 75 | + }); |
| 76 | + |
| 77 | + /** |
| 78 | + * Validate each field in the summary panel has valid content |
| 79 | + */ |
| 80 | + it('should display correct values for all fields in the summary panel', () => { |
| 81 | + cy.get('[data-test-subj="query-details-summary-section"]').within(() => { |
| 82 | + // Validate Timestamp |
| 83 | + cy.contains('h4', 'Timestamp') |
| 84 | + .parent() |
| 85 | + .next() |
| 86 | + .invoke('text') |
| 87 | + .should('match', /\w{3} \d{2}, \d{4} @ \d{1,2}:\d{2}:\d{2} [AP]M/); |
| 88 | + // Validate Latency |
| 89 | + cy.contains('h4', 'Latency') |
| 90 | + .parent() |
| 91 | + .next() |
| 92 | + .invoke('text') |
| 93 | + .should('match', /^\d+(\.\d{1,2})? ms$/); |
| 94 | + // Validate CPU Time |
| 95 | + cy.contains('h4', 'CPU Time') |
| 96 | + .parent() |
| 97 | + .next() |
| 98 | + .invoke('text') |
| 99 | + .should('match', /^\d+(\.\d+)? ms$/); |
| 100 | + // Validate Memory Usage |
| 101 | + cy.contains('h4', 'Memory Usage') |
| 102 | + .parent() |
| 103 | + .next() |
| 104 | + .invoke('text') |
| 105 | + .should('match', /^\d+(\.\d+)? B$/); |
| 106 | + // Validate Indices |
| 107 | + cy.contains('h4', 'Indices') |
| 108 | + .parent() |
| 109 | + .next() |
| 110 | + .invoke('text') |
| 111 | + .should('not.be.empty'); |
| 112 | + // Validate Search Type |
| 113 | + cy.contains('h4', 'Search Type') |
| 114 | + .parent() |
| 115 | + .next() |
| 116 | + .invoke('text') |
| 117 | + .should('equal', 'query then fetch'); |
| 118 | + // Validate Coordinator Node ID |
| 119 | + cy.contains('h4', 'Coordinator Node ID') |
| 120 | + .parent() |
| 121 | + .next() |
| 122 | + .invoke('text') |
| 123 | + .should('not.be.empty'); |
| 124 | + // Validate Total Shards |
| 125 | + cy.contains('h4', 'Total Shards') |
| 126 | + .parent() |
| 127 | + .next() |
| 128 | + .invoke('text') |
| 129 | + .then((text) => { |
| 130 | + const shardCount = parseInt(text.trim(), 10); |
| 131 | + expect(shardCount).to.be.a('number').and.to.be.greaterThan(0); |
| 132 | + }); |
| 133 | + }); |
| 134 | + }); |
| 135 | + |
| 136 | + /** |
| 137 | + * Validate the latency chart interaction |
| 138 | + */ |
| 139 | + it('should render the latency chart and allow interaction', () => { |
| 140 | + // Ensure the chart is visible |
| 141 | + cy.get('#latency').should('be.visible'); |
| 142 | + cy.get('.plot-container').should('be.visible'); |
| 143 | + // Simulate hover over the chart for a data point |
| 144 | + cy.get('#latency').trigger('mousemove', { clientX: 100, clientY: 100 }); |
| 145 | + }); |
| 146 | + |
| 147 | + after(() => clearAll()); |
| 148 | +}); |
0 commit comments