|
| 1 | +/* |
| 2 | + * Copyright OpenSearch Contributors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +import sampleDocument from '../fixtures/sample_document.json'; |
| 7 | +import { METRICS } from '../support/constants'; |
| 8 | + |
| 9 | +// Name of the test index used in tests |
| 10 | +const indexName = 'sample_index'; |
| 11 | + |
| 12 | +/** |
| 13 | + Helper function to clean up the environment: |
| 14 | + - Deletes the test index. |
| 15 | + - Disables the top queries features. |
| 16 | + */ |
| 17 | +const clearAll = () => { |
| 18 | + cy.deleteIndexByName(indexName); |
| 19 | + cy.disableTopQueries(METRICS.LATENCY); |
| 20 | + cy.disableTopQueries(METRICS.CPU); |
| 21 | + cy.disableTopQueries(METRICS.MEMORY); |
| 22 | +}; |
| 23 | + |
| 24 | +describe('Query Insights Dashboard', () => { |
| 25 | + // Setup before each test |
| 26 | + beforeEach(() => { |
| 27 | + clearAll(); |
| 28 | + cy.createIndexByName(indexName, sampleDocument); |
| 29 | + cy.enableTopQueries(METRICS.LATENCY); |
| 30 | + cy.enableTopQueries(METRICS.CPU); |
| 31 | + cy.searchOnIndex(indexName); |
| 32 | + // wait for 1s to avoid same timestamp |
| 33 | + cy.wait(1000); |
| 34 | + cy.searchOnIndex(indexName); |
| 35 | + cy.wait(1000); |
| 36 | + cy.searchOnIndex(indexName); |
| 37 | + // waiting for the query insights queue to drain |
| 38 | + cy.wait(6000); |
| 39 | + cy.navigateToOverview(); |
| 40 | + }); |
| 41 | + |
| 42 | + /** |
| 43 | + * Validate the main overview page loads correctly |
| 44 | + */ |
| 45 | + it('should display the main overview page', () => { |
| 46 | + cy.get('.euiBasicTable').should('be.visible'); |
| 47 | + cy.contains('Query insights - Top N queries'); |
| 48 | + cy.url().should('include', '/queryInsights'); |
| 49 | + |
| 50 | + // should display the query table on the overview page |
| 51 | + cy.get('.euiBasicTable').should('be.visible'); |
| 52 | + cy.get('.euiTableHeaderCell').should('have.length.greaterThan', 0); |
| 53 | + // should have top n queries displayed on the table |
| 54 | + cy.get('.euiTableRow').should('have.length.greaterThan', 0); |
| 55 | + }); |
| 56 | + |
| 57 | + /** |
| 58 | + * Validate sorting by the "Timestamp" column works correctly |
| 59 | + */ |
| 60 | + it('should sort the table by the Timestamp column', () => { |
| 61 | + // Capture the first row content before sorting |
| 62 | + let firstRowBeforeSort; |
| 63 | + cy.get('.euiTableRow') |
| 64 | + .first() |
| 65 | + .invoke('text') |
| 66 | + .then((text) => { |
| 67 | + firstRowBeforeSort = text.trim(); |
| 68 | + }); |
| 69 | + // Click the Timestamp column header to sort |
| 70 | + cy.get('.euiTableHeaderCell').contains('Timestamp').click(); |
| 71 | + // eslint-disable-next-line jest/valid-expect-in-promise |
| 72 | + cy.get('.euiTableRow') |
| 73 | + .first() |
| 74 | + .invoke('text') |
| 75 | + .then((firstRowAfterSort) => { |
| 76 | + // Assert that the content has changed |
| 77 | + expect(firstRowAfterSort.trim()).to.not.equal(firstRowBeforeSort); |
| 78 | + }); |
| 79 | + cy.get('.euiTableHeaderCell').contains('Timestamp').click(); |
| 80 | + // eslint-disable-next-line jest/valid-expect-in-promise |
| 81 | + cy.get('.euiTableRow') |
| 82 | + .first() |
| 83 | + .invoke('text') |
| 84 | + .then((firstRowAfterSecondSort) => { |
| 85 | + expect(firstRowAfterSecondSort.trim()).to.not.equal(firstRowBeforeSort); |
| 86 | + }); |
| 87 | + }); |
| 88 | + |
| 89 | + /** |
| 90 | + * Validate pagination works as expected |
| 91 | + */ |
| 92 | + it('should paginate the query table', () => { |
| 93 | + for (let i = 0; i < 20; i++) { |
| 94 | + cy.searchOnIndex(indexName); |
| 95 | + } |
| 96 | + // waiting for the query insights queue to drain |
| 97 | + cy.wait(10000); |
| 98 | + cy.reload(); |
| 99 | + cy.get('.euiPagination').should('be.visible'); |
| 100 | + cy.get('.euiPagination__item').contains('2').click(); |
| 101 | + // Verify rows on the second page |
| 102 | + cy.get('.euiTableRow').should('have.length.greaterThan', 0); |
| 103 | + }); |
| 104 | + |
| 105 | + it('should switch between tabs', () => { |
| 106 | + // Click Configuration tab |
| 107 | + cy.getElementByText('.euiTab', 'Configuration').click({ force: true }); |
| 108 | + cy.contains('Query insights - Configuration'); |
| 109 | + cy.url().should('include', '/configuration'); |
| 110 | + |
| 111 | + // Click back to Query Insights tab |
| 112 | + cy.getElementByText('.euiTab', 'Top N queries').click({ force: true }); |
| 113 | + cy.url().should('include', '/queryInsights'); |
| 114 | + }); |
| 115 | + |
| 116 | + it('should filter queries', () => { |
| 117 | + cy.get('.euiFieldSearch').should('be.visible'); |
| 118 | + cy.get('.euiFieldSearch').type('sample_index'); |
| 119 | + // Add assertions for filtered results |
| 120 | + cy.get('.euiTableRow').should('have.length.greaterThan', 0); |
| 121 | + }); |
| 122 | + |
| 123 | + it('should clear the search input and reset results', () => { |
| 124 | + cy.get('.euiFieldSearch').type('random_string'); |
| 125 | + cy.get('.euiTableRow').should('have.length.greaterThan', 0); |
| 126 | + cy.get('.euiFieldSearch').clear(); |
| 127 | + cy.get('.euiTableRow').should('have.length.greaterThan', 0); // Validate reset |
| 128 | + }); |
| 129 | + |
| 130 | + it('should display a message when no top queries are found', () => { |
| 131 | + clearAll(); // disable top n queries |
| 132 | + // waiting for the query insights queue to drain |
| 133 | + cy.wait(10000); |
| 134 | + cy.reload(); |
| 135 | + cy.contains('No items found'); |
| 136 | + }); |
| 137 | + |
| 138 | + after(() => clearAll()); |
| 139 | +}); |
0 commit comments