From 92df8156692d79fe46d45b44f9ce9c4a7e6f3c0e Mon Sep 17 00:00:00 2001 From: hughhhh Date: Wed, 23 Jun 2021 21:52:13 -0400 Subject: [PATCH 1/8] create boilerplate for cypress test --- .../integration/database/modal.test.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/superset-frontend/cypress-base/cypress/integration/database/modal.test.ts b/superset-frontend/cypress-base/cypress/integration/database/modal.test.ts index e54a600ecacff..5aa5988740aca 100644 --- a/superset-frontend/cypress-base/cypress/integration/database/modal.test.ts +++ b/superset-frontend/cypress-base/cypress/integration/database/modal.test.ts @@ -23,6 +23,31 @@ describe('Add database', () => { cy.login(); }); + it('should open dynamic form', () => { + cy.visit(DATABASE_LIST); + + // open modal + cy.get('[data-test="btn-create-database"]').click(); + + // click postgres dynamic form + cy.get('.preferred > :nth-child(1)').click(); + + // make sure all the fields are rendering + cy.get('input[name="host"]').should('have.value', ''); + cy.get('input[name="port"]').should('have.value', ''); + cy.get('input[name="database"]').should('have.value', ''); + cy.get('input[name="password"]').should('have.value', ''); + cy.get('input[name="database_name"]').should('have.value', ''); + cy.get('.ant-switch').should('be.visible'); + + }); + + xit('should open sqlalchemy form', () => {}); + xit('show error alerts on dynamic form', () => {}); + xit('show error alerts on sqlalchemy form', () => {}); + xit('should succesfully connect to db w/ dynamic form', () => {}); + xit('should succesfully connect to db w/ sqlalchemy form', () => {}); + xit('should keep create modal open when error', () => { cy.visit(DATABASE_LIST); From d162e185fc7617ba4ad70381e779f1ddb4ef2420 Mon Sep 17 00:00:00 2001 From: hughhhh Date: Thu, 24 Jun 2021 09:06:26 -0700 Subject: [PATCH 2/8] added 1 more test --- .../integration/database/modal.test.ts | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/superset-frontend/cypress-base/cypress/integration/database/modal.test.ts b/superset-frontend/cypress-base/cypress/integration/database/modal.test.ts index 5aa5988740aca..a7510bdea6f7d 100644 --- a/superset-frontend/cypress-base/cypress/integration/database/modal.test.ts +++ b/superset-frontend/cypress-base/cypress/integration/database/modal.test.ts @@ -21,11 +21,10 @@ import { DATABASE_LIST } from './helper'; describe('Add database', () => { beforeEach(() => { cy.login(); + cy.visit(DATABASE_LIST); }); it('should open dynamic form', () => { - cy.visit(DATABASE_LIST); - // open modal cy.get('[data-test="btn-create-database"]').click(); @@ -38,19 +37,28 @@ describe('Add database', () => { cy.get('input[name="database"]').should('have.value', ''); cy.get('input[name="password"]').should('have.value', ''); cy.get('input[name="database_name"]').should('have.value', ''); - cy.get('.ant-switch').should('be.visible'); + }); + + it('should open sqlalchemy form', () => { + // open modal + cy.get('[data-test="btn-create-database"]').click(); + // click postgres dynamic form + cy.get('.preferred > :nth-child(1)').click(); + + cy.get('[data-test="sqla-connect-btn"]').click(); + + // check if the sqlalchemy form is showing up + cy.get('[data-test=database-name-input]').should('be.visible'); + cy.get('[data-test="sqlalchemy-uri-input"]').should('be.visible'); }); - xit('should open sqlalchemy form', () => {}); xit('show error alerts on dynamic form', () => {}); xit('show error alerts on sqlalchemy form', () => {}); xit('should succesfully connect to db w/ dynamic form', () => {}); xit('should succesfully connect to db w/ sqlalchemy form', () => {}); xit('should keep create modal open when error', () => { - cy.visit(DATABASE_LIST); - // open modal cy.get('[data-test="btn-create-database"]').click(); From 5d784ec348d74402869b5bb0c351a30a3e05b900 Mon Sep 17 00:00:00 2001 From: hughhhh Date: Thu, 24 Jun 2021 10:41:43 -0700 Subject: [PATCH 3/8] add more test cases --- .../integration/database/modal.test.ts | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/superset-frontend/cypress-base/cypress/integration/database/modal.test.ts b/superset-frontend/cypress-base/cypress/integration/database/modal.test.ts index a7510bdea6f7d..d908d7f5e46ec 100644 --- a/superset-frontend/cypress-base/cypress/integration/database/modal.test.ts +++ b/superset-frontend/cypress-base/cypress/integration/database/modal.test.ts @@ -22,12 +22,11 @@ describe('Add database', () => { beforeEach(() => { cy.login(); cy.visit(DATABASE_LIST); + cy.wait(3000); + cy.get('[data-test="btn-create-database"]').click(); }); it('should open dynamic form', () => { - // open modal - cy.get('[data-test="btn-create-database"]').click(); - // click postgres dynamic form cy.get('.preferred > :nth-child(1)').click(); @@ -40,9 +39,6 @@ describe('Add database', () => { }); it('should open sqlalchemy form', () => { - // open modal - cy.get('[data-test="btn-create-database"]').click(); - // click postgres dynamic form cy.get('.preferred > :nth-child(1)').click(); @@ -53,7 +49,25 @@ describe('Add database', () => { cy.get('[data-test="sqlalchemy-uri-input"]').should('be.visible'); }); - xit('show error alerts on dynamic form', () => {}); + it('show error alerts on dynamic form for bad host', () => { + // click postgres dynamic form + cy.get('.preferred > :nth-child(1)').click(); + cy.get('input[name="host"]').focus().type('badhost'); + cy.get('input[name="port"]').focus().type('5432'); + cy.get('.ant-form-item-explain-error').contains( + "The hostname provided can't be resolved", + ); + }); + + it('show error alerts on dynamic form for bad port', () => { + // click postgres dynamic form + cy.get('.preferred > :nth-child(1)').click(); + cy.get('input[name="host"]').focus().type('localhost'); + cy.get('input[name="port"]').focus().type('123'); + cy.get('input[name="database"]').focus(); + cy.get('.ant-form-item-explain-error').contains('The port is closed'); + }); + xit('show error alerts on sqlalchemy form', () => {}); xit('should succesfully connect to db w/ dynamic form', () => {}); xit('should succesfully connect to db w/ sqlalchemy form', () => {}); From 4c467f5decb1316ffcf03e5588f6095c1efdcf78 Mon Sep 17 00:00:00 2001 From: hughhhh Date: Thu, 24 Jun 2021 10:45:21 -0700 Subject: [PATCH 4/8] saving this for development --- superset-frontend/cypress-base/cypress/support/index.ts | 2 +- .../CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx | 1 + .../src/views/CRUD/data/database/DatabaseModal/index.tsx | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/superset-frontend/cypress-base/cypress/support/index.ts b/superset-frontend/cypress-base/cypress/support/index.ts index e22f69975e96f..639b6c9f7a239 100644 --- a/superset-frontend/cypress-base/cypress/support/index.ts +++ b/superset-frontend/cypress-base/cypress/support/index.ts @@ -35,7 +35,7 @@ Cypress.Commands.add('login', () => { cy.request({ method: 'POST', url: '/login/', - body: { username: 'admin', password: 'general' }, + body: { username: 'h', password: 'h' }, }).then(response => { expect(response.status).to.eq(200); }); diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx index 5b9c57a463876..b79888ccd41cd 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx @@ -335,6 +335,7 @@ const forceSSLField = ({ }: FieldPropTypes) => (
infoTooltip(theme)}> { diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx index 9eae554c5c0bf..335e64a77cc90 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx @@ -598,6 +598,7 @@ const DatabaseModal: FunctionComponent = ({ key="submit" buttonStyle="primary" onClick={onClose} + data-test="modal-confirm-button" > Finish @@ -997,6 +998,7 @@ const DatabaseModal: FunctionComponent = ({ />
infoTooltip(theme)}>