-
Notifications
You must be signed in to change notification settings - Fork 16.6k
Added tests #1242
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
Added tests #1242
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import React from 'react'; | ||
| import Select from 'react-select'; | ||
| import { ChartControl } from '../../../../javascripts/explorev2/components/ChartControl'; | ||
| import { shallow } from 'enzyme'; | ||
| import { describe, it } from 'mocha'; | ||
| import { expect } from 'chai'; | ||
|
|
||
| describe('QuerySearch', () => { | ||
| it('should render', () => { | ||
| expect( | ||
| React.isValidElement(<ChartControl />) | ||
| ).to.equal(true); | ||
| }); | ||
|
|
||
| const wrapper = shallow(<ChartControl />); | ||
| it('should have two Select', () => { | ||
| expect(wrapper.find(Select)).to.have.length(2); | ||
| }); | ||
| }); | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import React from 'react'; | ||
| import { expect } from 'chai'; | ||
| import { describe, it } from 'mocha'; | ||
| import { shallow } from 'enzyme'; | ||
| import { Button } from 'react-bootstrap'; | ||
| import Select from 'react-select'; | ||
| import { Filters } from '../../../../javascripts/explorev2/components/Filters'; | ||
| import shortid from 'shortid'; | ||
|
|
||
| function setup() { | ||
| const props = { | ||
| filters: [ | ||
| { | ||
| id: shortid.generate(), | ||
| field: null, | ||
| op: null, | ||
| value: null, | ||
| }, | ||
| ] | ||
| } | ||
| const wrapper = shallow(<Filters {...props} />); | ||
| return { | ||
| props, | ||
| wrapper, | ||
| }; | ||
| } | ||
|
|
||
| describe('Filters', () => { | ||
| it('renders', () => { | ||
| expect(React.isValidElement(<Filters />)).to.equal(true); | ||
| }); | ||
|
|
||
| it('should have one button', () => { | ||
| const wrapper = shallow(<Filters />); | ||
| expect(wrapper.find(Button)).to.have.length(1); | ||
| expect(wrapper.find(Button).contains('Add Filter')).to.eql(true); | ||
| }); | ||
|
|
||
| it('should have Select and button for filters', () => { | ||
| const { wrapper, props } = setup(); | ||
| expect(wrapper.find(Button)).to.have.length(2); | ||
| expect(wrapper.find(Select)).to.have.length(2); | ||
| expect(wrapper.find('input')).to.have.length(1); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import React from 'react'; | ||
| import { expect } from 'chai'; | ||
| import { describe, it } from 'mocha'; | ||
| import { shallow } from 'enzyme'; | ||
| import Select from 'react-select'; | ||
| import { GroupBy } from '../../../../javascripts/explorev2/components/GroupBy'; | ||
|
|
||
| describe('GroupBy', () => { | ||
| it('renders', () => { | ||
| expect(React.isValidElement(<GroupBy />)).to.equal(true); | ||
| }); | ||
|
|
||
| it('should have two Select', () => { | ||
| const wrapper = shallow(<GroupBy />); | ||
| expect(wrapper.find(Select)).to.have.length(2); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import React from 'react'; | ||
| import { expect } from 'chai'; | ||
| import { describe, it } from 'mocha'; | ||
| import { shallow } from 'enzyme'; | ||
| import { SqlClause } from '../../../../javascripts/explorev2/components/SqlClause'; | ||
|
|
||
| describe('SqlClause', () => { | ||
| it('renders', () => { | ||
| expect(React.isValidElement(<SqlClause />)).to.equal(true); | ||
| }); | ||
|
|
||
| it('should have two input fields', () => { | ||
| const wrapper = shallow(<SqlClause />); | ||
| expect(wrapper.find('input')).to.have.length(2); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import React from 'react'; | ||
| import Select from 'react-select'; | ||
| import { expect } from 'chai'; | ||
| import { describe, it } from 'mocha'; | ||
| import { shallow } from 'enzyme'; | ||
| import { TimeFilter } from '../../../../javascripts/explorev2/components/TimeFilter'; | ||
|
|
||
| describe('TimeFilter', () => { | ||
| it('renders', () => { | ||
| expect(React.isValidElement(<TimeFilter />)).to.equal(true); | ||
| }); | ||
|
|
||
| it('should have four Select', () => { | ||
| const wrapper = shallow(<TimeFilter />); | ||
| expect(wrapper.find(Select)).to.have.length(4); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,111 @@ | ||
| import { it, describe } from 'mocha'; | ||
| import { expect } from 'chai'; | ||
| import configureMockStore from 'redux-mock-store'; | ||
| import thunk from 'redux-thunk'; | ||
| import nock from 'nock'; | ||
| import { expect, assert } from 'chai'; | ||
| import sinon from 'sinon'; | ||
| import shortid from 'shortid'; | ||
| import * as actions from '../../../../javascripts/explorev2/actions/exploreActions'; | ||
| import { initialState } from '../../../../javascripts/explorev2/stores/store'; | ||
| import { exploreReducer } from '../../../../javascripts/explorev2/reducers/exploreReducer'; | ||
|
|
||
| const middlewares = [thunk]; | ||
| const mockStore = configureMockStore(middlewares); | ||
|
|
||
| describe('ajax call for datasource metadata', () => { | ||
| afterEach(() => { | ||
| nock.cleanAll(); | ||
| }); | ||
|
|
||
| it('should return a function', () => { | ||
| expect(actions.setFormOpts(999, 'test')).to.be.function; | ||
| }); | ||
|
|
||
| it('should dispatch clearAllOpts', () => { | ||
| const dispatch = sinon.spy(); | ||
| actions.setFormOpts(null, null)(dispatch); | ||
| assert(dispatch.withArgs(actions.clearAllOpts()).calledOnce); | ||
| }); | ||
|
|
||
| it('should dispatch new opts', () => { | ||
| nock('/caravel') | ||
| .get('/fetch_datasource_metadata') | ||
| .query({ datasource_id: 999, datasource_type: 'test' }) | ||
| .reply(200, { | ||
| datasource_class: 'SqlaTable', | ||
| time_columns: ['col'], | ||
| time_grains: [], | ||
| groupby_cols: [], | ||
| metrics: [], | ||
| filter_cols: [], | ||
| }); | ||
|
|
||
| const store = mockStore(initialState); | ||
| store.dispatch = sinon.spy(); | ||
| store.dispatch(actions.setFormOpts(999, 'test')); | ||
| expect(store.dispatch.callCount).to.equal(5); | ||
|
||
| expect(store.getState().timeColumnOpts).to.eql(['col']); | ||
| }); | ||
| }); | ||
|
|
||
| describe('reducers', () => { | ||
| it('should return new state with time column options', () => { | ||
| const newState = exploreReducer(initialState, actions.setTimeColumnOpts(['col1', 'col2'])); | ||
| expect(newState.timeColumnOpts).to.eql(['col1', 'col2']); | ||
| }); | ||
| it('should return new state with time grain options', () => { | ||
| const newState = exploreReducer(initialState, actions.setTimeGrainOpts(['day', 'week'])); | ||
| expect(newState.timeGrainOpts).to.eql(['day', 'week']); | ||
| }); | ||
|
|
||
| it('should return new state with groupby column options', () => { | ||
| const newState = exploreReducer(initialState, actions.setGroupByColumnOpts(['col1', 'col2'])); | ||
| expect(newState.groupByColumnOpts).to.eql(['col1', 'col2']); | ||
| }); | ||
|
|
||
| it('should return new state with metrics options', () => { | ||
| const newState = exploreReducer(initialState, actions.setMetricsOpts(['metric1', 'metric2'])); | ||
| expect(newState.metricsOpts).to.eql(['metric1', 'metric2']); | ||
| }); | ||
|
|
||
| it('should return new state with filter column options', () => { | ||
| const newState = exploreReducer(initialState, actions.setFilterColumnOpts(['col1', 'col2'])); | ||
| expect(newState.filterColumnOpts).to.eql(['col1', 'col2']); | ||
| }); | ||
|
|
||
| it('should return new state with all form data reset', () => { | ||
| const newState = exploreReducer(initialState, actions.resetFormData()); | ||
| expect(newState.vizType).to.not.exist; | ||
| expect(newState.timeColumn).to.not.exist; | ||
| expect(newState.timeGrain).to.not.exist; | ||
| expect(newState.since).to.not.exist; | ||
| expect(newState.until).to.not.exist; | ||
| expect(newState.groupByColumns).to.be.empty; | ||
| expect(newState.metrics).to.be.empty; | ||
| expect(newState.columns).to.be.empty; | ||
| expect(newState.orderings).to.be.empty; | ||
| expect(newState.timeStampFormat).to.not.exist; | ||
| expect(newState.rowLimit).to.not.exist; | ||
| expect(newState.searchBox).to.be.false; | ||
| expect(newState.whereClause).to.be.empty; | ||
| expect(newState.havingClause).to.be.empty; | ||
| expect(newState.filters).to.be.empty; | ||
| }); | ||
|
|
||
| it('should clear all options in store', () => { | ||
| const newState = exploreReducer(initialState, actions.clearAllOpts()); | ||
| expect(newState.timeColumnOpts).to.be.empty; | ||
| expect(newState.timeGrainOpts).to.be.empty; | ||
| expect(newState.groupByColumnOpts).to.be.empty; | ||
| expect(newState.metricsOpts).to.be.empty; | ||
| expect(newState.filterColumnOpts).to.be.empty; | ||
| }); | ||
|
|
||
| // it('should return new state with datasource class', () => { | ||
| // const newState = exploreReducer(initialState, actions.setDatasourceClass('SqlaTable')); | ||
| // expect(newState.datasourceClass).to.equal('SqlaTable'); | ||
| // }); | ||
|
|
||
| it('should return new state with datasource id', () => { | ||
| const newState = exploreReducer(initialState, actions.setDatasource(1)); | ||
| expect(newState.datasourceId).to.equal(1); | ||
|
|
@@ -16,6 +116,36 @@ describe('reducers', () => { | |
| expect(newState.vizType).to.equal('bar'); | ||
| }); | ||
|
|
||
| it('should return new state with time column', () => { | ||
| const newState = exploreReducer(initialState, actions.setTimeColumn('ds')); | ||
| expect(newState.timeColumn).to.equal('ds'); | ||
| }); | ||
|
|
||
| it('should return new state with time grain', () => { | ||
| const newState = exploreReducer(initialState, actions.setTimeGrain('day')); | ||
| expect(newState.timeGrain).to.equal('day'); | ||
| }); | ||
|
|
||
| it('should return new state with since', () => { | ||
| const newState = exploreReducer(initialState, actions.setSince('1 day ago')); | ||
| expect(newState.since).to.equal('1 day ago'); | ||
| }); | ||
|
|
||
| it('should return new state with until', () => { | ||
| const newState = exploreReducer(initialState, actions.setUntil('now')); | ||
| expect(newState.until).to.equal('now'); | ||
| }); | ||
|
|
||
| it('should return new state with groupby columns', () => { | ||
| const newState = exploreReducer(initialState, actions.setGroupByColumns(['col1', 'col2'])); | ||
| expect(newState.groupByColumns).to.eql(['col1', 'col2']); | ||
| }); | ||
|
|
||
| it('should return new state with metrics', () => { | ||
| const newState = exploreReducer(initialState, actions.setMetrics(['sum', 'count'])); | ||
| expect(newState.metrics).to.eql(['sum', 'count']); | ||
| }); | ||
|
|
||
| it('should return new state with added column', () => { | ||
| const newColumn = 'col'; | ||
| const newState = exploreReducer(initialState, actions.addColumn(newColumn)); | ||
|
|
@@ -57,6 +187,16 @@ describe('reducers', () => { | |
| expect(newState.searchBox).to.equal(true); | ||
| }); | ||
|
|
||
| it('should return new state with where clause', () => { | ||
| const newState = exploreReducer(initialState, actions.setWhereClause('where')); | ||
| expect(newState.whereClause).to.equal('where'); | ||
| }); | ||
|
|
||
| it('should return new state with having clause', () => { | ||
| const newState = exploreReducer(initialState, actions.setHavingClause('having')); | ||
| expect(newState.havingClause).to.equal('having'); | ||
| }); | ||
|
|
||
| it('should return new state with added filter', () => { | ||
| const newFilter = { | ||
| id: shortid.generate(), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,6 +78,7 @@ class ListWidgetWithCheckboxes(ListWidget): | |
| ACCESS_REQUEST_MISSING_ERR = __( | ||
| "The access requests seem to have been deleted") | ||
| USER_MISSING_ERR = __("The user seems to have been deleted") | ||
| DATASOURCE_ACCESS_ERR = __("User does not have access to this datasource") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry forgot to add this for last PR, adding it here |
||
|
|
||
|
|
||
| def get_database_access_error_msg(database_name): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having trouble figuring this one out. I looked at multiple docs for testing ajax action creators, sinon fakeServer, nock etc. I think http://redux.js.org/docs/recipes/WritingTests.html seems to make more sense. I kind of modified some of it, but this test keeps failing. Saying the actual callCount of dispatch is 1 instead of 5. I figure the dispatch callcount may not take callbacks into account. Still trying to figure this out.