Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Add Cypress testing for SQL Workbench #562

Merged
merged 7 commits into from
Aug 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions sql-workbench/.cypress/integration/ui.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

/// <reference types="cypress" />

import { edit } from "brace";
import { delay, testQueries, verifyDownloadData, files } from "../utils/constants";

describe('Test UI buttons', () => {
beforeEach(() => {
cy.visit('app/opendistro-sql-workbench');
});

it('Test Run button and field search', () => {
cy.get('textarea.ace_text-input').eq(0).focus().type('{enter}select * from accounts where balance > 49500;', { force: true });
cy.wait(delay);
cy.get('.euiButton__text').contains('Run').click();
cy.wait(delay);
cy.get('.euiTab__content').contains('accounts').click();

cy.get('input.euiFieldSearch').type('marissa');
cy.get('span.euiTableCellContent__text').eq(15).should((account_number) => {
expect(account_number).to.contain('803');
});
});

it('Test Translate button', () => {
cy.get('textarea.ace_text-input').eq(0).focus().type('{selectall}{backspace}', { force: true });
cy.wait(delay);
cy.get('textarea.ace_text-input').eq(0).focus().type('{selectall}{backspace}select log(balance) from accounts where abs(age) > 20;', { force: true });
cy.wait(delay);
cy.get('.euiButton__text').contains('Translate').click();
cy.wait(delay);

// Note: Translation retrived this way will get cut off, so doing a substring check
cy.get('.ace_content').eq(1).then((translate_editor) => {
const editor = edit(translate_editor[0]);
expect(editor.getValue()).to.have.string("Math.abs(doc['age'].value);abs_1 > 20");
});
});

it('Test Clear button', () => {
cy.get('.euiButton__text').contains('Clear').click();
cy.wait(delay);

cy.get('.ace_content').eq(0).then((sql_query_editor) => {
const editor = edit(sql_query_editor[0]);
expect(editor.getValue()).to.equal('');
});
});
});

describe('Test and verify downloads', () => {
verifyDownloadData.map(({ title, url, file }) => {
it(title, () => {
cy.request({
method: 'POST',
form: true,
url: url,
headers: {
'content-type': 'application/json;charset=UTF-8',
'kbn-version': '7.8.0',
},
body: {
'query': 'select * from accounts where balance > 49500'
}
}).then(response => {
expect(response.body.resp).to.have.string(files[file]);
});
});
});
});

describe('Test table display', () => {
beforeEach(() => {
cy.visit('app/opendistro-sql-workbench');
cy.get('textarea.ace_text-input').eq(0).focus().type('{selectall}{backspace}', { force: true });
cy.wait(delay);
});

testQueries.map(({ title, query, cell_idx, expected_string }) => {
it(title, () => {
cy.get('textarea.ace_text-input').eq(0).focus().type(`{selectall}{backspace}${query}`, { force: true });
cy.wait(delay);
cy.get('.euiButton__text').contains('Run').click();
cy.wait(delay);

cy.get('span.euiTableCellContent__text').eq(cell_idx).should((cell) => {
expect(cell).to.contain(expected_string);
});
});
});

it('Test nested fields display', () => {
cy.get('textarea.ace_text-input').eq(0).focus().type(`{selectall}{backspace}select * from employee_nested;`, { force: true });
cy.wait(delay);
cy.get('.euiButton__text').contains('Run').click();
cy.wait(delay);

cy.get('span.euiTableCellContent__text').eq(21).click();
cy.wait(delay);
cy.get('span.euiTableCellContent__text').eq(27).should((cell) => {
expect(cell).to.contain('2018-06-23');
});
});
});
37 changes: 37 additions & 0 deletions sql-workbench/.cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

/// <reference types="cypress" />

// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
};
40 changes: 40 additions & 0 deletions sql-workbench/.cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
35 changes: 35 additions & 0 deletions sql-workbench/.cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands';

// Alternatively you can use CommonJS syntax:
// require('./commands')
97 changes: 97 additions & 0 deletions sql-workbench/.cypress/utils/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

export const delay = 300;

export const verifyDownloadData = [
{
title: 'Download and verify JSON',
url: 'api/sql_console/queryjson',
file: 'JSONFile'
},
{
title: 'Download and verify JDBC',
url: 'api/sql_console/queryjdbc',
file: 'JDBCFile'
},
{
title: 'Download and verify CSV',
url: 'api/sql_console/querycsv',
file: 'CSVFile'
},
{
title: 'Download and verify Text',
url: 'api/sql_console/querytext',
file: 'TextFile'
},
];

export const testQueries = [
{
title: 'Test GROUP BY',
query: 'select count(*) from accounts group by gender;',
cell_idx: 5,
expected_string: '507'
},
{
title: 'Test GROUP BY with aliases and scalar function',
query: 'SELECT ABS(age) AS a FROM accounts GROUP BY ABS(age);',
cell_idx: 17,
expected_string: '35.0'
},
{
title: 'Test GROUP BY and HAVING',
query: 'SELECT age, MAX(balance) FROM accounts GROUP BY age HAVING MIN(balance) > 3000;',
cell_idx: 15,
expected_string: '49339'
},
{
title: 'Test ORDER BY',
query: 'SELECT account_number FROM accounts ORDER BY account_number DESC;',
cell_idx: 5,
expected_string: '999'
},
{
title: 'Test JOIN',
query: 'select a.account_number, a.firstname, a.lastname, e.id, e.name from accounts a join employee_nested e order by a.account_number;',
cell_idx: 45,
expected_string: 'Amber'
},
];

export const files = {
JSONFile:
`"hits":[{"_index":"accounts","_type":"_doc","_id":"842","_score":0,"_source":{"account_number":842,"balance":49587,"firstname":"Meagan","lastname":"Buckner","age":23,"gender":"F","address":"833 Bushwick Court","employer":"Biospan","email":"meaganbuckner@biospan.com","city":"Craig","state":"TX"}},{"_index":"accounts","_type":"_doc","_id":"854","_score":0,"_source":{"account_number":854,"balance":49795,"firstname":"Jimenez","lastname":"Barry","age":25,"gender":"F","address":"603 Cooper Street","employer":"Verton","email":"jimenezbarry@verton.com","city":"Moscow","state":"AL"}},{"_index":"accounts","_type":"_doc","_id":"97","_score":0,"_source":{"account_number":97,"balance":49671,"firstname":"Karen","lastname":"Trujillo","age":40,"gender":"F","address":"512 Cumberland Walk","employer":"Tsunamia","email":"karentrujillo@tsunamia.com","city":"Fredericktown","state":"MO"}},{"_index":"accounts","_type":"_doc","_id":"168","_score":0,"_source":{"account_number":168,"balance":49568,"firstname":"Carissa","lastname":"Simon","age":20,"gender":"M","address":"975 Flatbush Avenue","employer":"Zillacom","email":"carissasimon@zillacom.com","city":"Neibert","state":"IL"}},{"_index":"accounts","_type":"_doc","_id":"240","_score":0,"_source":{"account_number":240,"balance":49741,"firstname":"Oconnor","lastname":"Clay","age":35,"gender":"F","address":"659 Highland Boulevard","employer":"Franscene","email":"oconnorclay@franscene.com","city":"Kilbourne","state":"NH"}},{"_index":"accounts","_type":"_doc","_id":"803","_score":0,"_source":{"account_number":803,"balance":49567,"firstname":"Marissa","lastname":"Spears","age":25,"gender":"M","address":"963 Highland Avenue","employer":"Centregy","email":"marissaspears@centregy.com","city":"Bloomington","state":"MS"}},{"_index":"accounts","_type":"_doc","_id":"248","_score":0,"_source":{"account_number":248,"balance":49989,"firstname":"West","lastname":"England","age":36,"gender":"M","address":"717 Hendrickson Place","employer":"Obliq","email":"westengland@obliq.com","city":"Maury","state":"WA"}}]`,
JDBCFile:
`{"schema":[{"name":"account_number","type":"long"},{"name":"firstname","type":"text"},{"name":"gender","type":"text"},{"name":"city","type":"text"},{"name":"balance","type":"long"},{"name":"employer","type":"text"},{"name":"state","type":"text"},{"name":"email","type":"text"},{"name":"address","type":"text"},{"name":"lastname","type":"text"},{"name":"age","type":"long"}],"total":7,"datarows":[[842,"Meagan","F","Craig",49587,"Biospan","TX","meaganbuckner@biospan.com","833 Bushwick Court","Buckner",23],[854,"Jimenez","F","Moscow",49795,"Verton","AL","jimenezbarry@verton.com","603 Cooper Street","Barry",25],[97,"Karen","F","Fredericktown",49671,"Tsunamia","MO","karentrujillo@tsunamia.com","512 Cumberland Walk","Trujillo",40],[168,"Carissa","M","Neibert",49568,"Zillacom","IL","carissasimon@zillacom.com","975 Flatbush Avenue","Simon",20],[240,"Oconnor","F","Kilbourne",49741,"Franscene","NH","oconnorclay@franscene.com","659 Highland Boulevard","Clay",35],[803,"Marissa","M","Bloomington",49567,"Centregy","MS","marissaspears@centregy.com","963 Highland Avenue","Spears",25],[248,"West","M","Maury",49989,"Obliq","WA","westengland@obliq.com","717 Hendrickson Place","England",36]],"size":7,"status":200}`,
CSVFile:
`account_number,firstname,address,balance,gender,city,employer,state,age,email,lastname
842,Meagan,833 Bushwick Court,49587,F,Craig,Biospan,TX,23,meaganbuckner@biospan.com,Buckner
854,Jimenez,603 Cooper Street,49795,F,Moscow,Verton,AL,25,jimenezbarry@verton.com,Barry
97,Karen,512 Cumberland Walk,49671,F,Fredericktown,Tsunamia,MO,40,karentrujillo@tsunamia.com,Trujillo
168,Carissa,975 Flatbush Avenue,49568,M,Neibert,Zillacom,IL,20,carissasimon@zillacom.com,Simon
240,Oconnor,659 Highland Boulevard,49741,F,Kilbourne,Franscene,NH,35,oconnorclay@franscene.com,Clay
803,Marissa,963 Highland Avenue,49567,M,Bloomington,Centregy,MS,25,marissaspears@centregy.com,Spears
248,West,717 Hendrickson Place,49989,M,Maury,Obliq,WA,36,westengland@obliq.com,England`,
TextFile:
`842|Meagan|F|Craig|49587|Biospan|TX|meaganbuckner@biospan.com|833 Bushwick Court|Buckner|23
854|Jimenez|F|Moscow|49795|Verton|AL|jimenezbarry@verton.com|603 Cooper Street|Barry|25
97|Karen|F|Fredericktown|49671|Tsunamia|MO|karentrujillo@tsunamia.com|512 Cumberland Walk|Trujillo|40
168|Carissa|M|Neibert|49568|Zillacom|IL|carissasimon@zillacom.com|975 Flatbush Avenue|Simon|20
240|Oconnor|F|Kilbourne|49741|Franscene|NH|oconnorclay@franscene.com|659 Highland Boulevard|Clay|35
803|Marissa|M|Bloomington|49567|Centregy|MS|marissaspears@centregy.com|963 Highland Avenue|Spears|25
248|West|M|Maury|49989|Obliq|WA|westengland@obliq.com|717 Hendrickson Place|England|36
`,
};
4 changes: 4 additions & 0 deletions sql-workbench/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
/build/
.cypress/screenshots
.cypress/videos
13 changes: 13 additions & 0 deletions sql-workbench/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"baseUrl": "http://localhost:5601",
"video": true,
"fixturesFolder": ".cypress/fixtures",
"integrationFolder": ".cypress/integration",
"pluginsFile": ".cypress/plugins/index.js",
"screenshotsFolder": ".cypress/screenshots",
"supportFile": ".cypress/support/index.js",
"videosFolder": ".cypress/videos",
"requestTimeout": 60000,
"responseTimeout": 60000,
"defaultCommandTimeout": 60000
}
4 changes: 2 additions & 2 deletions sql-workbench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"brace": "0.11.1",
"lodash": "^4.17.19",
"react-dom": "^16.3.0",
"react-double-scrollbar": "^0.0.15",
"node": "^14.0.0"
"react-double-scrollbar": "^0.0.15"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.7.4",
Expand Down Expand Up @@ -57,6 +56,7 @@
"@types/react-dom": "^16.0.5",
"@types/react-router-dom": "^5.1.5",
"babel-eslint": "^10.1.0",
"cypress": "^4.9.0",
"eslint": "^6.8.0",
"eslint-plugin-babel": "^5.2.0",
"eslint-plugin-import": "^2.14.0",
Expand Down
Loading