Skip to content

Commit aa41ad4

Browse files
authored
Add basic test cases for dev tool console (#1204)
* Add basic test cases for console plugin Signed-off-by: Zhongnan Su <szhongna@amazon.com> * fix typo Signed-off-by: Zhongnan Su <szhongna@amazon.com> --------- Signed-off-by: Zhongnan Su <szhongna@amazon.com>
1 parent e4f0ccd commit aa41ad4

File tree

4 files changed

+110
-1
lines changed

4 files changed

+110
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library';
7+
8+
const miscUtils = new MiscUtils(cy);
9+
10+
describe('console app', () => {
11+
const DEFAULT_REQUEST = `GET _search
12+
{
13+
"query": {
14+
"match_all": {}
15+
}
16+
}`.trim();
17+
18+
beforeEach(() => {
19+
// Navigate to the console page before each test
20+
miscUtils.visitPage('/app/dev_tools#/console');
21+
// Assuming there's a method to collapse the help pane in your page objects or you directly use a command here
22+
cy.getElementByTestId('help-close-button').click({ force: true });
23+
cy.wait(1000);
24+
});
25+
26+
it('should show the default request', () => {
27+
// Get the request text and assert it matches the default request
28+
// Adjust the selector to target the element containing the request
29+
cy.getVisibleTextFromAceEditor('request-editor').should(
30+
'eq',
31+
DEFAULT_REQUEST
32+
);
33+
});
34+
35+
it('default request response should include `"timed_out" : false`', () => {
36+
// Click the "Play" button to submit the request
37+
// Adjust the selector as needed
38+
cy.getElementByTestId('sendRequestButton').click();
39+
40+
// Check the response for the expected text
41+
// Adjust the selector to target the element containing the response
42+
cy.getElementByTestId('response-editor').should(
43+
'contain',
44+
'"timed_out": false,'
45+
);
46+
});
47+
48+
it('settings should allow changing the text size', () => {
49+
// Navigate to settings and change the font size, then verify the change
50+
// This assumes you have a way to navigate to settings and change them, possibly abstracted in commands
51+
cy.changeConsoleFontSize(20);
52+
cy.getElementByTestId('request-editor').should(
53+
'have.css',
54+
'font-size',
55+
'20px'
56+
);
57+
58+
cy.changeConsoleFontSize(24);
59+
cy.getElementByTestId('request-editor').should(
60+
'have.css',
61+
'font-size',
62+
'24px'
63+
);
64+
});
65+
66+
it('should resize the editor', () => {
67+
// Set initial window size
68+
cy.viewport(1300, 1100);
69+
70+
// Capture initial size
71+
let initialWidth;
72+
cy.get('.conApp').then(($editor) => {
73+
initialWidth = $editor.width();
74+
});
75+
76+
// Change window size
77+
cy.viewport(1000, 1100);
78+
79+
// Assert that the editor width has decreased
80+
cy.get('.conApp').should(($editor) => {
81+
expect($editor.width()).to.be.lessThan(initialWidth);
82+
});
83+
});
84+
});

cypress/support/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import '../utils/plugins/ml-commons-dashboards/commands';
3131
import '../utils/plugins/security-analytics-dashboards-plugin/commands';
3232
import '../utils/plugins/notifications-dashboards/commands';
3333
import '../utils/plugins/dashboards-assistant/commands';
34+
import '../utils/dashboards/console/commands';
3435

3536
import 'cypress-real-events';
3637

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
Cypress.Commands.add('getVisibleTextFromAceEditor', (editorSelector) => {
7+
return cy
8+
.getElementByTestId(editorSelector)
9+
.find('.ace_line_group')
10+
.then((lines) => {
11+
const linesText = [...lines].map((line) => line.innerText);
12+
return linesText.join('\n');
13+
});
14+
});
15+
16+
Cypress.Commands.add('changeConsoleFontSize', (size) => {
17+
cy.getElementByTestId('consoleSettingsButton').click({ force: true });
18+
// Ensure the settings panel is open and ready
19+
cy.getElementByTestId('setting-font-size-input', { timeout: 1000 })
20+
.type('{selectall}')
21+
.type(size)
22+
.should('have.value', size);
23+
cy.get('[data-test-subj="settings-save-button"]').click();
24+
});

cypress/utils/dashboards/vis_builder/commands.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Cypress.Commands.add('vbEditAgg', (fields = []) => {
4444
});
4545

4646
fields.forEach(({ testSubj, type, value }) => {
47-
// TODO: Impliment controls for other input types
47+
// TODO: Implement controls for other input types
4848
switch (type) {
4949
case 'input':
5050
cy.getElementByTestId(testSubj)

0 commit comments

Comments
 (0)