Skip to content

Commit b9341e5

Browse files
test(cypress): add tests for table vis (#10896)
* Add cypress test for table visualization Signed-off-by: Luna Liu <[email protected]> * Changeset file for PR #10896 created/updated --------- Signed-off-by: Luna Liu <[email protected]> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
1 parent 8a0ed5f commit b9341e5

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed

changelogs/fragments/10896.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
feat:
2+
- Add tests for table vis ([#10896](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/10896))
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { INDEX_WITH_TIME_1, DATASOURCE_NAME } from '../../../../../../utils/apps/explore/constants';
7+
import { getRandomizedWorkspaceName } from '../../../../../../utils/apps/explore/shared';
8+
import { prepareTestSuite } from '../../../../../../utils/helpers';
9+
10+
const workspaceName = getRandomizedWorkspaceName();
11+
const datasetName = `${INDEX_WITH_TIME_1}*`;
12+
13+
export const runCreateVisTests = () => {
14+
describe('create table visualization tests', () => {
15+
before(() => {
16+
cy.osd.setupWorkspaceAndDataSourceWithIndices(workspaceName, [INDEX_WITH_TIME_1]);
17+
cy.explore.createWorkspaceDataSets({
18+
workspaceName: workspaceName,
19+
indexPattern: INDEX_WITH_TIME_1,
20+
timefieldName: 'timestamp',
21+
dataSource: DATASOURCE_NAME,
22+
isEnhancement: true,
23+
});
24+
cy.osd.navigateToWorkSpaceSpecificPage({
25+
workspaceName: workspaceName,
26+
page: 'explore/logs',
27+
isEnhancement: true,
28+
});
29+
});
30+
31+
beforeEach(() => {
32+
cy.getElementByTestId('discoverNewButton').click();
33+
cy.osd.waitForLoader(true);
34+
});
35+
36+
after(() => {
37+
cy.osd.cleanupWorkspaceAndDataSourceAndIndices(workspaceName, [INDEX_WITH_TIME_1]);
38+
});
39+
40+
it('should create a table visualization using a query with multiple fields', () => {
41+
const query = `source=${datasetName} | stats count() by category, response_time | head 10`;
42+
cy.explore.createVisualizationWithQuery(query, 'Table', datasetName, {
43+
shouldManualSelectChartType: true,
44+
});
45+
46+
cy.get('.tableVis').should('be.visible');
47+
});
48+
49+
it('should toggle column filter and the changes reflect immediately to the table visualization', () => {
50+
const query = `source=${datasetName} | stats count() by category, response_time | head 10`;
51+
cy.explore.createVisualizationWithQuery(query, 'Table', datasetName, {
52+
shouldManualSelectChartType: true,
53+
});
54+
55+
cy.get('[data-test-subj*="visTableFilterIcon"]').should('not.exist');
56+
cy.getElementByTestId('visTableColumnFilter').click();
57+
cy.get('[data-test-subj*="visTableFilterIcon"]').should('be.visible');
58+
cy.get('[data-test-subj*="visTableFilterIcon"]').first().click();
59+
cy.get('.visTableColumnHeader_filterPopover').should('be.visible');
60+
61+
cy.get('.visTableColumnHeader_filterPopover').within(() => {
62+
cy.get('select').should('be.visible');
63+
cy.get('input.euiFieldText').should('be.visible');
64+
cy.get('button').contains('OK').should('be.visible');
65+
cy.get('button').contains('Cancel').should('be.visible');
66+
cy.get('button').contains('Clear filter').should('be.visible');
67+
});
68+
});
69+
70+
it('should add threshold coloring and reflect immediately to the table visualization', () => {
71+
const query = `source=${datasetName} | stats count() by category | head 5`;
72+
cy.explore.createVisualizationWithQuery(query, 'Table', datasetName, {
73+
shouldManualSelectChartType: true,
74+
});
75+
76+
// Click "Add new cell type" button
77+
cy.getElementByTestId('visTableAddCellType').click();
78+
79+
cy.getElementByTestId('visTableCellTypeField0').select(1);
80+
cy.getElementByTestId('visTableCellTypeMode0').select(2);
81+
82+
// Click "Add threshold" button
83+
cy.getElementByTestId('exploreVisAddThreshold').click();
84+
85+
// Verify that data grid cell has background-color style applied
86+
cy.get('[role="gridcell"]')
87+
.first()
88+
.should((element) => {
89+
const style = element[0].style;
90+
expect(style.backgroundColor).to.exist;
91+
});
92+
});
93+
94+
it('should create data links that turn cell values into clickable links', () => {
95+
const query = `source=${datasetName} | stats count() by category | head 10`;
96+
cy.explore.createVisualizationWithQuery(query, 'Table', datasetName, {
97+
shouldManualSelectChartType: true,
98+
});
99+
100+
// Click "Add link" button
101+
cy.getElementByTestId('addDataLinkButton').click();
102+
103+
cy.getElementByTestId('dataLinkTitleInput').type('test');
104+
cy.getElementByTestId('dataLinkAddFieldButton').click();
105+
cy.get('[data-test-subj*="dataLinkFieldOption"]').contains('category').click();
106+
cy.get('body').click(0, 0);
107+
cy.getElementByTestId('dataLinkUrlInput').type('https://www.google.com/');
108+
cy.getElementByTestId('dataLinkSaveButton').click();
109+
110+
// Verify that category column cells contain clickable links
111+
cy.get('[role="gridcell"] a').should('exist');
112+
});
113+
});
114+
};
115+
116+
prepareTestSuite('Create Table Visualization', runCreateVisTests);

0 commit comments

Comments
 (0)