[sql lab] allow users to save their queries (#2528)

* Allow users to save their queries

Fixing tests .

* Adding placeholder for Query Description

* initJQueryCSRF -> initJQueryAjaxCSRF
This commit is contained in:
Maxime Beauchemin
2017-04-04 20:15:19 -07:00
committed by GitHub
parent c1d9918abe
commit 122891c29b
31 changed files with 656 additions and 279 deletions

View File

@@ -0,0 +1,11 @@
import React from 'react';
import AlertsWrapper from '../../../javascripts/SqlLab/components/AlertsWrapper';
import { describe, it } from 'mocha';
import { expect } from 'chai';
describe('AlertsWrapper', () => {
it('is valid', () => {
expect(React.isValidElement(<AlertsWrapper />)).to.equal(true);
});
});

View File

@@ -1,24 +0,0 @@
import React from 'react';
import Alerts from '../../../javascripts/SqlLab/components/Alerts';
import { Alert } from 'react-bootstrap';
import { shallow } from 'enzyme';
import { describe, it } from 'mocha';
import { expect } from 'chai';
import { alert } from './fixtures';
describe('Alerts', () => {
const mockedProps = {
alerts: [alert],
};
it('is valid', () => {
expect(React.isValidElement(<Alerts />)).to.equal(true);
});
it('is valid with props', () => {
expect(React.isValidElement(<Alerts {...mockedProps} />)).to.equal(true);
});
it('renders an Alert', () => {
const wrapper = shallow(<Alerts {...mockedProps} />);
expect(wrapper.find(Alert)).to.have.length(1);
});
});

View File

@@ -0,0 +1,48 @@
import React from 'react';
import SaveQuery from '../../../javascripts/SqlLab/components/SaveQuery';
import { Overlay, Popover, FormControl } from 'react-bootstrap';
import { shallow, mount } from 'enzyme';
import { describe, it } from 'mocha';
import { expect } from 'chai';
describe('SavedQuery', () => {
const mockedProps = {
dbId: 1,
schema: 'main',
sql: 'SELECT * FROM t',
defaultLabel: 'untitled',
animation: false,
};
it('is valid', () => {
expect(
React.isValidElement(<SaveQuery />)
).to.equal(true);
});
it('is valid with props', () => {
expect(
React.isValidElement(<SaveQuery {...mockedProps} />)
).to.equal(true);
});
it('has an Overlay and a Popover', () => {
const wrapper = shallow(<SaveQuery {...mockedProps} />);
expect(wrapper.find(Overlay)).to.have.length(1);
expect(wrapper.find(Popover)).to.have.length(1);
});
it('pops and hides', () => {
const wrapper = mount(<SaveQuery {...mockedProps} />);
expect(wrapper.state().showSave).to.equal(false);
wrapper.find('.toggleSave').simulate('click');
expect(wrapper.state().showSave).to.equal(true);
wrapper.find('.toggleSave').simulate('click');
expect(wrapper.state().showSave).to.equal(false);
});
it('has a cancel button', () => {
const wrapper = shallow(<SaveQuery {...mockedProps} />);
expect(wrapper.find('.cancelQuery')).to.have.length(1);
});
it('has 2 FormControls', () => {
const wrapper = shallow(<SaveQuery {...mockedProps} />);
expect(wrapper.find(FormControl)).to.have.length(2);
});
});