Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add e2e testing #15376

Merged
merged 8 commits into from
Jun 29, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,71 +21,50 @@ import { DATABASE_LIST } from './helper';
describe('Add database', () => {
beforeEach(() => {
cy.login();
});

xit('should keep create modal open when error', () => {
cy.visit(DATABASE_LIST);

// open modal
cy.wait(3000);
cy.get('[data-test="btn-create-database"]').click();
});

// values should be blank
cy.get('[data-test="database-modal"] input[name="database_name"]').should(
'have.value',
'',
);
cy.get('[data-test="database-modal"] input[name="sqlalchemy_uri"]').should(
'have.value',
'',
);

// type values
cy.get('[data-test="database-modal"] input[name="database_name"]')
.focus()
.type('cypress');
cy.get('[data-test="database-modal"] input[name="sqlalchemy_uri"]')
.focus()
.type('bad_db_uri');

// click save
cy.get('[data-test="modal-confirm-button"]:not(:disabled)').click();

// should show error alerts and keep modal open
cy.get('.toast').contains('error');
cy.wait(1000); // wait for potential (incorrect) closing annimation
cy.get('[data-test="database-modal"]').should('be.visible');
it('should open dynamic form', () => {
// click postgres dynamic form
cy.get('.preferred > :nth-child(1)').click();

// should be able to close modal
cy.get('[data-test="modal-cancel-button"]').click();
cy.get('[data-test="database-modal"]').should('not.be.visible');
// 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', '');
});

xit('should keep update modal open when error', () => {
// open modal
cy.get('[data-test="database-edit"]:last').click();

// it should show saved values
cy.get('[data-test="database-modal"]:last input[name="sqlalchemy_uri"]')
.invoke('val')
.should('not.be.empty');
cy.get('[data-test="database-modal"] input[name="database_name"]')
.invoke('val')
.should('not.be.empty');
it('should open sqlalchemy form', () => {
// click postgres dynamic form
cy.get('.preferred > :nth-child(1)').click();

cy.get('[data-test="database-modal"]:last input[name="sqlalchemy_uri"]')
.focus()
.dblclick()
.type('{selectall}{backspace}bad_uri');
cy.get('[data-test="sqla-connect-btn"]').click();

// click save
cy.get('[data-test="modal-confirm-button"]:not(:disabled)').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');
});

// should show error alerts
// TODO(hugh): Update this test
// cy.get('.toast').contains('error').should('be.visible');
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",
);
});

// modal should still be open
// cy.wait(1000); // wait for potential (incorrect) closing annimation
// cy.get('[data-test="database-modal"]').should('be.visible');
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');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
key="submit"
buttonStyle="primary"
onClick={onClose}
data-test="modal-confirm-button"
>
Finish
</StyledFooterButton>
Expand Down Expand Up @@ -997,6 +998,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
/>
<div css={(theme: SupersetTheme) => infoTooltip(theme)}>
<Button
data-test="sqla-connect-btn"
buttonStyle="link"
onClick={() =>
setDB({
Expand Down