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

[SIP-4][superset-client] add SupersetClient, refactor app #5772

Closed
wants to merge 9 commits into from
3 changes: 2 additions & 1 deletion superset/assets/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"globals": {
"document": true,
"window": true,
},
"rules": {
"prefer-template": 0,
Expand All @@ -26,7 +27,7 @@
"no-mixed-operators": 0,
"no-continue": 0,
"no-bitwise": 0,
"no-undef": 0,
"no-undef": 1,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning for this, turning this off is BAD!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+100

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one total worths its own PR.

"no-multi-assign": 0,
"react/no-array-index-key": 0,
"no-restricted-properties": 0,
Expand Down
9 changes: 7 additions & 2 deletions superset/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@
},
"homepage": "http://superset.apache.org/",
"dependencies": {
"@data-ui/event-flow": "^0.0.54",
"@data-ui/event-flow": "^0.0.62",
"@data-ui/sparkline": "^0.0.54",
"@data-ui/xy-chart": "^0.0.61",
"@vx/responsive": "0.0.153",
"abortcontroller-polyfill": "^1.1.9",
"aphrodite": "^1.2.0",
"babel-register": "^6.24.1",
"bootstrap": "^3.3.6",
"bootstrap-slider": "^10.0.0",
Expand Down Expand Up @@ -120,7 +122,9 @@
"supercluster": "https://github.com/georgeke/supercluster/tarball/ac3492737e7ce98e07af679623aad452373bbc40",
"underscore": "^1.8.3",
"urijs": "^1.18.10",
"viewport-mercator-project": "^5.0.0"
"url-search-params-polyfill": "^4.0.1",
"viewport-mercator-project": "^5.0.0",
"whatwg-fetch": "^2.0.4"
},
"devDependencies": {
"babel-cli": "^6.14.0",
Expand All @@ -145,6 +149,7 @@
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-react": "^7.0.1",
"exports-loader": "^0.7.0",
"fetch-mock": "^6.5.2",
"file-loader": "^1.1.11",
"github-changes": "^1.0.4",
"ignore-styles": "^5.0.1",
Expand Down
10 changes: 10 additions & 0 deletions superset/assets/spec/helpers/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import 'babel-polyfill';
import chai from 'chai';
import jsdom from 'jsdom';
import SupersetClient from '../../src/packages/core/src';
import fetchMock from 'fetch-mock'; // eslint-disable-line import/first

require('babel-register')({
// NOTE: If `dynamic-import-node` is in .babelrc alongside
Expand Down Expand Up @@ -47,3 +49,11 @@ global.window.XMLHttpRequest = global.XMLHttpRequest;
global.window.location = { href: 'about:blank' };
global.window.performance = { now: () => new Date().getTime() };
global.$ = require('jquery')(global.window);

// The following are needed to mock out SupersetClient requests
// including CSRF authentication and initialization
global.FormData = window.FormData;
fetchMock.get(/superset\/csrf_token/, { csrf_token: '1234' });
SupersetClient.configure({ protocol: 'http', host: 'localhost' })
.init()
.then(() => fetchMock.reset()); // remove this call from mocks
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('sliceEntities reducer', () => {
it('should set slices', () => {
const result = sliceEntitiesReducer(
{ slices: { a: {} } },
{ type: SET_ALL_SLICES, slices: { 1: {}, 2: {} } },
{ type: SET_ALL_SLICES, payload: { slices: { 1: {}, 2: {} } } },
);

expect(result.slices).to.deep.equal({
Expand All @@ -42,7 +42,7 @@ describe('sliceEntities reducer', () => {
{},
{
type: FETCH_ALL_SLICES_FAILED,
error: { responseJSON: { message: 'errorrr' } },
error: 'errorrr',
Copy link
Member

@hughhhh hughhhh Aug 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a test / misspelling was purposeful.

},
);
expect(result.isLoading).to.equal(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { expect } from 'chai';
import { describe, it, beforeEach } from 'mocha';
import { shallow } from 'enzyme';
import configureStore from 'redux-mock-store';
import $ from 'jquery';
import sinon from 'sinon';
import fetchMock from 'fetch-mock';
import thunk from 'redux-thunk';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:) love thunk


import DatasourceEditor from '../../../src/datasource/DatasourceEditor';
import mockDatasource from '../../fixtures/mockDatasource';
Expand All @@ -14,8 +14,9 @@ const props = {
datasource: mockDatasource['7__table'],
addSuccessToast: () => {},
addDangerToast: () => {},
onChange: sinon.spy(),
onChange: () => {},
};

const extraColumn = {
column_name: 'new_column',
type: 'VARCHAR(10)',
Expand All @@ -27,26 +28,23 @@ const extraColumn = {
groupby: true,
};

const endpoint = 'glob:*/datasource/external_metadata/*';

describe('DatasourceEditor', () => {
const mockStore = configureStore([]);
const mockStore = configureStore([thunk]);
const store = mockStore({});
fetchMock.get(endpoint, []);

let wrapper;
let el;
let ajaxStub;
let inst;

beforeEach(() => {
ajaxStub = sinon.stub($, 'ajax');
el = <DatasourceEditor {...props} />;
wrapper = shallow(el, { context: { store } }).dive();
inst = wrapper.instance();
});

afterEach(() => {
ajaxStub.restore();
});

it('is valid', () => {
expect(React.isValidElement(el)).to.equal(true);
});
Expand All @@ -55,12 +53,17 @@ describe('DatasourceEditor', () => {
expect(wrapper.find(Tabs)).to.have.lengthOf(1);
});

it('makes an async request', () => {
it('makes an async request', (done) => {
wrapper.setState({ activeTabKey: 2 });
const syncButton = wrapper.find('.sync-from-source');
expect(syncButton).to.have.lengthOf(1);
syncButton.simulate('click');
expect(ajaxStub.calledOnce).to.equal(true);

setTimeout(() => {
expect(fetchMock.calls(endpoint)).to.have.lengthOf(1);
fetchMock.reset();
done();
}, 0);
});

it('merges columns', () => {
Expand All @@ -69,5 +72,4 @@ describe('DatasourceEditor', () => {
inst.mergeColumns([extraColumn]);
expect(inst.state.databaseColumns.length).to.equal(numCols + 1);
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { expect } from 'chai';
import { describe, it, beforeEach } from 'mocha';
import configureStore from 'redux-mock-store';
import { shallow } from 'enzyme';
import $ from 'jquery';
import fetchMock from 'fetch-mock';
import thunk from 'redux-thunk';
import sinon from 'sinon';

import DatasourceModal from '../../../src/datasource/DatasourceModal';
Expand All @@ -15,31 +16,30 @@ const props = {
datasource: mockDatasource['7__table'],
addSuccessToast: () => {},
addDangerToast: () => {},
onChange: sinon.spy(),
onChange: () => {},
show: true,
onHide: () => {},
onDatasourceSave: sinon.spy(),
};

const saveEndpoint = 'glob:*/datasource/save/';
const savePayload = { new: 'data' };

describe('DatasourceModal', () => {
const mockStore = configureStore([]);
const mockStore = configureStore([thunk]);
const store = mockStore({});
fetchMock.post(saveEndpoint, savePayload);

let wrapper;
let el;
let ajaxStub;
let inst;

beforeEach(() => {
ajaxStub = sinon.stub($, 'ajax');
el = <DatasourceModal {...props} />;
wrapper = shallow(el, { context: { store } }).dive();
inst = wrapper.instance();
});

afterEach(() => {
ajaxStub.restore();
});

it('is valid', () => {
expect(React.isValidElement(el)).to.equal(true);
});
Expand All @@ -52,8 +52,13 @@ describe('DatasourceModal', () => {
expect(wrapper.find(DatasourceEditor)).to.have.lengthOf(1);
});

it('saves on confirm', () => {
it('saves on confirm', (done) => {
inst.onConfirmSave();
expect(ajaxStub.calledOnce).to.equal(true);
setTimeout(() => {
expect(fetchMock.calls(saveEndpoint)).to.have.lengthOf(1);
expect(props.onDatasourceSave.getCall(0).args[0]).to.deep.equal(savePayload);
fetchMock.reset();
done();
}, 0);
});
});
Loading