Skip to content

Commit b9d834f

Browse files
committed
Add tests for query enhancement discover covering basic functions and shared links
Signed-off-by: Anan <[email protected]>
1 parent b5b2cb8 commit b9d834f

File tree

7 files changed

+682
-53
lines changed

7 files changed

+682
-53
lines changed
Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import {
7+
TestFixtureHandler,
8+
MiscUtils,
9+
} from '@opensearch-dashboards-test/opensearch-dashboards-test-library';
10+
import { CURRENT_TENANT } from '../../../../../utils/commands';
11+
import {
12+
DE_DEFAULT_END_TIME,
13+
DE_DEFAULT_START_TIME,
14+
} from '../../../../../utils/constants';
15+
16+
const miscUtils = new MiscUtils(cy);
17+
const testFixtureHandler = new TestFixtureHandler(
18+
cy,
19+
Cypress.env('openSearchUrl')
20+
);
21+
const indexSet = [
22+
'logstash-2015.09.22',
23+
'logstash-2015.09.21',
24+
'logstash-2015.09.20',
25+
];
26+
27+
describe(
28+
'discover query enhancement basic functions',
29+
{ scrollBehavior: false },
30+
() => {
31+
const isEnhancement = true;
32+
before(() => {
33+
CURRENT_TENANT.newTenant = 'global';
34+
cy.log('load opensearch-dashboards index with default index pattern');
35+
36+
// import long window logstash index pattern
37+
testFixtureHandler.importJSONDoc(
38+
'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/long_window_logstash_index_pattern/data.json.txt'
39+
);
40+
41+
// import logstash functional
42+
testFixtureHandler.importJSONDocIfNeeded(
43+
indexSet,
44+
'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.mappings.json.txt',
45+
'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/logstash/logstash.json.txt'
46+
);
47+
48+
// import long window logstash
49+
testFixtureHandler.importJSONMapping(
50+
'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/long_window_logstash/mappings.json.txt'
51+
);
52+
53+
testFixtureHandler.importJSONDoc(
54+
'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/long_window_logstash/data.json.txt'
55+
);
56+
57+
cy.setAdvancedSetting({
58+
defaultIndex: 'long-window-logstash-*',
59+
'dateFormat:tz': 'Europe/Berlin',
60+
});
61+
62+
// Go to the Discover page
63+
miscUtils.visitPage('app/data-explorer/discover#/');
64+
});
65+
66+
after(() => {
67+
miscUtils.visitPage('app/management/opensearch-dashboards/settings');
68+
cy.waitForLoader(isEnhancement);
69+
cy.getElementByTestId('advancedSetting-resetField-dateFormat:tz').click({
70+
force: true,
71+
});
72+
cy.getElementByTestId('advancedSetting-saveButton').click({
73+
force: true,
74+
});
75+
testFixtureHandler.clearJSONMapping(
76+
'cypress/fixtures/dashboard/opensearch_dashboards/data_explorer/long_window_logstash/mappings.json.txt'
77+
);
78+
cy.deleteIndex('long-window-logstash-0');
79+
cy.deleteSavedObjectByType('index-pattern');
80+
cy.clearCache();
81+
});
82+
83+
describe('no result panel', () => {
84+
before(() => {
85+
cy.selectDatasetForEnhancement('long-window-logstash-*');
86+
// Set a time range where we know there will be no data
87+
const fromTime = 'Jan 1, 2024 @ 00:00:00.000';
88+
const toTime = 'Jan 2, 2024 @ 00:00:00.000';
89+
cy.setTopNavDateWithRetry(fromTime, toTime, isEnhancement);
90+
});
91+
92+
it('should show no results', () => {
93+
// Check for the presence of the no results component
94+
cy.getElementByTestId('discoverNoResults').should('be.visible');
95+
cy.getElementByTestId('discoverNoResultsTimefilter')
96+
.should('be.visible')
97+
.should(
98+
'contain.text',
99+
'Try selecting a different data source, expanding your time range or modifying the query & filters.'
100+
);
101+
});
102+
});
103+
104+
describe('render discover with side bar, top nav and canvas', () => {
105+
before(() => {
106+
// Set a time range where we know there will be no data
107+
const fromTime = 'Nov 01, 2017 @ 00:00:00.000';
108+
const toTime = 'Mar 21, 2018 @ 00:00:00.000';
109+
cy.setTopNavDateWithRetry(fromTime, toTime, isEnhancement);
110+
});
111+
112+
it('should show side bar with DatasetSelector', () => {
113+
// Test both the sidebar container and dataset selector
114+
cy.get('.deSidebar').should('exist');
115+
cy.get('.datasetSelector__button').should('exist');
116+
117+
// Also verify the sidebar has the field list sections
118+
cy.getElementByTestId('fieldList-selected').should('exist');
119+
cy.getElementByTestId('fieldList-unpopular').should('exist');
120+
});
121+
122+
it('should show top nav header', () => {
123+
// Test main header container
124+
cy.get('.headerAppActionMenuSection').should('exist');
125+
cy.getElementByTestId('headerAppActionMenu').should('exist');
126+
127+
// Test navigation menu
128+
cy.getElementByTestId('top-nav').should('exist');
129+
130+
// Test all action buttons exist
131+
cy.getElementByTestId('discoverSaveButton').should('exist');
132+
cy.getElementByTestId('discoverOpenButton').should('exist');
133+
cy.getElementByTestId('discoverNewButton').should('exist');
134+
cy.getElementByTestId('openInspectorButton').should('exist');
135+
cy.getElementByTestId('shareTopNavButton').should('exist');
136+
137+
// Test date picker exists
138+
cy.get('.euiFlexItem.globalDatePicker').should('exist');
139+
cy.getElementByTestId('superDatePickerToggleQuickMenuButton').should(
140+
'exist'
141+
);
142+
});
143+
144+
it('should show globalQueryEditor', () => {
145+
// Test the query editor container and its main components
146+
cy.get('.globalQueryEditor').should('exist');
147+
cy.get('.osdQueryEditor').should('exist');
148+
cy.get('.osdQueryEditor__input').should('exist');
149+
150+
// Test the query language selector
151+
cy.get('.languageSelector').should('exist');
152+
});
153+
154+
it('should show discoverTable', () => {
155+
// Test main discover table container exists
156+
cy.getElementByTestId('discoverTable').should('exist');
157+
158+
// Test table exists and has correct structure
159+
cy.get('.osd-table').should('exist');
160+
161+
// Test header cells exist
162+
cy.getElementByTestId('docTableHeader').should('exist');
163+
cy.getElementByTestId('docTableHeaderField').should('exist');
164+
cy.get('[data-test-subj="docTableHeader-@timestamp"]').should('exist');
165+
cy.get('[data-test-subj="docTableHeader-_source"]').should('exist');
166+
167+
// Test table body and row content exists
168+
cy.get('tbody').should('exist');
169+
cy.get('[data-test-subj="docTableField"]').should('exist');
170+
cy.get('.osdDocTableCell__source').should('exist');
171+
});
172+
});
173+
174+
describe('filters and queries', () => {
175+
before(() => {
176+
// Set a time range where we know there will be no data
177+
const fromTime = 'Nov 01, 2017 @ 00:00:00.000';
178+
const toTime = 'Mar 21, 2018 @ 00:00:00.000';
179+
cy.setTopNavDateWithRetry(fromTime, toTime, isEnhancement);
180+
});
181+
182+
it('should persist across refresh', function () {
183+
// Set up query and filter
184+
cy.setTopNavQuery('response:200', true, isEnhancement);
185+
cy.getElementByTestId('showFilterActions').click();
186+
cy.submitFilterFromDropDown(
187+
'extension.keyword',
188+
'is one of',
189+
'jpg',
190+
isEnhancement
191+
);
192+
cy.reload();
193+
cy.get('.osdQueryEditor__input .monaco-editor .view-lines').should(
194+
'contain.text',
195+
'response:200'
196+
);
197+
cy.get('[data-test-subj~="filter-key-extension.keyword"]')
198+
.should('be.visible')
199+
.click();
200+
cy.get('button[aria-label="Delete"]').click();
201+
});
202+
});
203+
204+
describe('save search', () => {
205+
const saveSearch1 = 'Save Search # 1';
206+
const saveSearch2 = 'Modified Save Search # 1';
207+
208+
it('should show correct time range string by timepicker', function () {
209+
cy.setTopNavDateWithRetry(
210+
DE_DEFAULT_START_TIME,
211+
DE_DEFAULT_END_TIME,
212+
isEnhancement
213+
);
214+
cy.verifyTimeConfig(DE_DEFAULT_START_TIME, DE_DEFAULT_END_TIME);
215+
});
216+
217+
it('save search should display save search name in breadcrumb', function () {
218+
cy.saveSearch(saveSearch1, isEnhancement);
219+
cy.getElementByTestId('headerAppActionMenu')
220+
.should('be.visible')
221+
.should('contain', saveSearch1);
222+
});
223+
224+
it('load save search should show save search name in breadcrumb', function () {
225+
cy.loadSaveSearch(saveSearch1, isEnhancement);
226+
227+
cy.getElementByTestId('headerAppActionMenu')
228+
.should('be.visible')
229+
.should('contain', saveSearch1);
230+
});
231+
232+
it('renaming a save search should modify name in breadcrumb', function () {
233+
cy.loadSaveSearch(saveSearch1, isEnhancement);
234+
cy.saveSearch(saveSearch2, isEnhancement);
235+
236+
cy.getElementByTestId('headerAppActionMenu')
237+
.should('be.visible')
238+
.should('contain', saveSearch2);
239+
});
240+
241+
it('should show the correct hit count', function () {
242+
cy.loadSaveSearch(saveSearch2, isEnhancement);
243+
cy.setTopNavDateWithRetry(
244+
DE_DEFAULT_START_TIME,
245+
DE_DEFAULT_END_TIME,
246+
isEnhancement
247+
);
248+
const expectedHitCount = '35';
249+
cy.verifyHitCount(expectedHitCount);
250+
});
251+
252+
it('should show correct time range string in chart', function () {
253+
cy.getElementByTestId('discoverIntervalDateRange').should(
254+
'have.text',
255+
`${DE_DEFAULT_START_TIME} - ${DE_DEFAULT_END_TIME} per`
256+
);
257+
});
258+
259+
it('should show correct initial chart interval of Auto', function () {
260+
cy.getElementByTestId('discoverIntervalSelect')
261+
.get('option')
262+
.first()
263+
.should('have.text', 'Auto');
264+
});
265+
266+
it('should not show "no results"', () => {
267+
cy.getElementByTestId('discoverNoResults').should('not.exist');
268+
});
269+
270+
it('should reload the saved search with persisted query to show the initial hit count', function () {
271+
// apply query some changes
272+
cy.setTopNavQuery('DE', true, isEnhancement);
273+
cy.verifyHitCount('3');
274+
275+
// reset to persisted state
276+
cy.getElementByTestId('resetSavedSearch').click();
277+
const expectedHitCount = '35';
278+
cy.verifyHitCount(expectedHitCount);
279+
});
280+
});
281+
}
282+
);

0 commit comments

Comments
 (0)