Skip to content

Commit

Permalink
feat: SQL Toolbar (#12067)
Browse files Browse the repository at this point in the history
Co-authored-by: hughhhh <hughmil3s@gmail.com>
Co-authored-by: Evan Rusackas <evan@preset.io>
Co-authored-by: Phillip Kelley-Dotson <pkelleydotson@yahoo.com>
Co-authored-by: Simcha Shats <simcha.shats@nielsen.com>
Co-authored-by: amitNielsen <amit.miran@nielsen.com>
Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com>
Co-authored-by: Agata Stawarz-Pastewska <agata.stawarz-pastewska@polidea.com>
Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
Co-authored-by: David Aaron Suddjian <aasuddjian@gmail.com>
Co-authored-by: David Aaron Suddjian <1858430+suddjian@users.noreply.github.com>
Co-authored-by: Geido <60598000+geido@users.noreply.github.com>
Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
Co-authored-by: ʈᵃᵢ <tdupreetan@gmail.com>
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Co-authored-by: Lily Kuang <lily@preset.io>
Co-authored-by: Victor Malai <malai9696@gmail.com>
Co-authored-by: Agata Stawarz <47450693+agatapst@users.noreply.github.com>
Co-authored-by: Daniel Vaz Gaspar <danielvazgaspar@gmail.com>
Co-authored-by: Jesse Yang <jesse.yang@airbnb.com>
Co-authored-by: Nikola Gigić <nik.gigic@gmail.com>
Co-authored-by: Jagadish <jagadishmts@gmail.com>
Co-authored-by: Hugh A. Miles II <hughmil3s@gmail.com>
Co-authored-by: Elizabeth Thompson <eschutho@gmail.com>
  • Loading branch information
22 people authored Jan 7, 2021
1 parent 5088e57 commit 9997abe
Show file tree
Hide file tree
Showing 20 changed files with 762 additions and 721 deletions.
21 changes: 21 additions & 0 deletions superset-frontend/images/icons/link.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions superset-frontend/images/icons/save.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
128 changes: 0 additions & 128 deletions superset-frontend/spec/javascripts/sqllab/LimitControl_spec.jsx

This file was deleted.

10 changes: 7 additions & 3 deletions superset-frontend/spec/javascripts/sqllab/SaveQuery_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ describe('SavedQuery', () => {
const wrapper = shallow(<SaveQuery {...mockedProps} />);
expect(wrapper.find(Modal)).toExist();
});
it('has a cancel button', () => {
// TODO: eschutho convert test to RTL
// eslint-disable-next-line jest/no-disabled-tests
it.skip('has a cancel button', () => {
const wrapper = shallow(<SaveQuery {...mockedProps} />);
const modal = wrapper.find(Modal);

Expand All @@ -56,7 +58,8 @@ describe('SavedQuery', () => {

expect(modal.find(FormControl)).toHaveLength(2);
});
it('has a save button if this is a new query', () => {
// eslint-disable-next-line jest/no-disabled-tests
it.skip('has a save button if this is a new query', () => {
const saveSpy = sinon.spy();
const wrapper = shallow(<SaveQuery {...mockedProps} onSave={saveSpy} />);
const modal = wrapper.find(Modal);
Expand All @@ -65,7 +68,8 @@ describe('SavedQuery', () => {
modal.find(Button).at(0).simulate('click');
expect(saveSpy.calledOnce).toBe(true);
});
it('has an update button if this is an existing query', () => {
// eslint-disable-next-line jest/no-disabled-tests
it.skip('has an update button if this is an existing query', () => {
const updateSpy = sinon.spy();
const props = {
...mockedProps,
Expand Down
62 changes: 29 additions & 33 deletions superset-frontend/spec/javascripts/sqllab/ShareSqlLabQuery_spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@
import React from 'react';
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import Popover from 'src/common/components/Popover';
import fetchMock from 'fetch-mock';
import * as featureFlags from 'src/featureFlags';
import { shallow } from 'enzyme';

import * as utils from 'src/utils/common';
import Button from 'src/components/Button';
import ShareSqlLabQuery from 'src/SqlLab/components/ShareSqlLabQuery';
import CopyToClipboard from 'src/components/CopyToClipboard';
import { Tooltip } from 'src/common/components/Tooltip';

const mockStore = configureStore([thunk]);
const store = mockStore();
let isFeatureEnabledMock;

describe('ShareSqlLabQuery via /kv/store', () => {
const clipboardSpy = jest.fn();

describe('ShareSqlLabQuery', () => {
const storeQueryUrl = 'glob:*/kv/store/';
const storeQueryMockId = '123';

Expand All @@ -41,6 +43,7 @@ describe('ShareSqlLabQuery via /kv/store', () => {
overwriteRoutes: true,
});
fetchMock.resetHistory();
jest.clearAllMocks();
});

afterAll(fetchMock.reset);
Expand Down Expand Up @@ -83,29 +86,22 @@ describe('ShareSqlLabQuery via /kv/store', () => {
isFeatureEnabledMock.restore();
});

it('renders an OverlayTrigger with Button', () => {
const wrapper = setup();
const trigger = wrapper.find(Popover);
const button = trigger.find(Button);

expect(trigger).toHaveLength(1);
expect(button).toHaveLength(1);
});

it('calls storeQuery() with the query when getCopyUrl() is called and saves the url', () => {
it('calls storeQuery() with the query when getCopyUrl() is called', () => {
expect.assertions(4);
const storeQuerySpy = jest.spyOn(utils, 'storeQuery');

const wrapper = setup();
const instance = wrapper.instance();

return instance.getCopyUrl().then(() => {
return instance.getCopyUrl(clipboardSpy).then(() => {
expect(storeQuerySpy.mock.calls).toHaveLength(1);
expect(fetchMock.calls(storeQueryUrl)).toHaveLength(1);
expect(storeQuerySpy.mock.calls[0][0]).toMatchObject(
storedQueryAttributes,
);
expect(instance.state.shortUrl).toContain(storeQueryMockId);
expect(clipboardSpy).toHaveBeenCalledWith(
expect.stringContaining('?id='),
);

storeQuerySpy.mockRestore();

Expand All @@ -115,7 +111,7 @@ describe('ShareSqlLabQuery via /kv/store', () => {

it('dispatches an error toast upon fetching failure', () => {
expect.assertions(3);
const error = 'error';
const error = 'There was an error with your request';
const addDangerToastSpy = jest.fn();
fetchMock.post(
storeQueryUrl,
Expand All @@ -127,7 +123,7 @@ describe('ShareSqlLabQuery via /kv/store', () => {

return wrapper
.instance()
.getCopyUrl()
.getCopyUrl(clipboardSpy)
.then(() => {
// Fails then retries thrice
expect(fetchMock.calls(storeQueryUrl)).toHaveLength(4);
Expand All @@ -149,37 +145,37 @@ describe('ShareSqlLabQuery via /kv/store', () => {
isFeatureEnabledMock.restore();
});

it('renders an OverlayTrigger with Button', () => {
const wrapper = setup();
const trigger = wrapper.find(Popover);
const button = trigger.find(Button);

expect(trigger).toHaveLength(1);
expect(button).toHaveLength(1);
});

it('does not call storeQuery() with the query when getCopyUrl() is called', () => {
const storeQuerySpy = jest.spyOn(utils, 'storeQuery');

const wrapper = setup();
const instance = wrapper.instance();

instance.getCopyUrl();
instance.getCopyUrl(clipboardSpy);

expect(storeQuerySpy.mock.calls).toHaveLength(0);
expect(fetchMock.calls(storeQueryUrl)).toHaveLength(0);
expect(instance.state.shortUrl).toContain(999);
expect(clipboardSpy).toHaveBeenCalledWith(
expect.stringContaining('savedQueryId'),
);

storeQuerySpy.mockRestore();
});

it('shows a request to save the query when the query is not yet saved', () => {
const wrapper = setup({ remoteId: undefined });
const instance = wrapper.instance();

instance.getCopyUrl();
const wrapper = setup({
queryEditor: {
...defaultProps.queryEditor,
remoteId: undefined,
},
});

expect(instance.state.shortUrl).toContain('save');
expect(wrapper.find(CopyToClipboard)).toHaveLength(0);
expect(wrapper.find('.btn-disabled')).toHaveLength(1);
expect(wrapper.find(Tooltip)).toHaveProp(
'title',
expect.stringContaining('Save the query'),
);
});
});
});
Loading

0 comments on commit 9997abe

Please sign in to comment.