test(frontend): use absolute path for src imports (#9761)

* test(frontend): use absolute path for src imports

* Upgrade prettier, fix eslint
This commit is contained in:
Jesse Yang
2020-05-07 14:18:10 -07:00
committed by GitHub
parent 6237cea952
commit 13c5b133a9
220 changed files with 827 additions and 1730 deletions

View File

@@ -18,9 +18,9 @@
*/
import React from 'react';
import { mount } from 'enzyme';
import ColumnElement from 'src/SqlLab/components/ColumnElement';
import { mockedActions, table } from './fixtures';
import ColumnElement from '../../../src/SqlLab/components/ColumnElement';
describe('ColumnElement', () => {
const mockedProps = {
@@ -33,32 +33,17 @@ describe('ColumnElement', () => {
it('renders a proper primary key', () => {
const wrapper = mount(<ColumnElement column={table.columns[0]} />);
expect(wrapper.find('i.fa-key')).toHaveLength(1);
expect(
wrapper
.find('.col-name')
.first()
.text(),
).toBe('id');
expect(wrapper.find('.col-name').first().text()).toBe('id');
});
it('renders a multi-key column', () => {
const wrapper = mount(<ColumnElement column={table.columns[1]} />);
expect(wrapper.find('i.fa-link')).toHaveLength(1);
expect(wrapper.find('i.fa-bookmark')).toHaveLength(1);
expect(
wrapper
.find('.col-name')
.first()
.text(),
).toBe('first_name');
expect(wrapper.find('.col-name').first().text()).toBe('first_name');
});
it('renders a column with no keys', () => {
const wrapper = mount(<ColumnElement column={table.columns[2]} />);
expect(wrapper.find('i')).toHaveLength(0);
expect(
wrapper
.find('.col-name')
.first()
.text(),
).toBe('last_name');
expect(wrapper.find('.col-name').first().text()).toBe('last_name');
});
});

View File

@@ -19,18 +19,17 @@
import React from 'react';
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { shallow } from 'enzyme';
import sinon from 'sinon';
import fetchMock from 'fetch-mock';
import shortid from 'shortid';
import sqlLabReducer from 'src/SqlLab/reducers/index';
import * as actions from 'src/SqlLab/actions/sqlLab';
import ExploreResultsButton from 'src/SqlLab/components/ExploreResultsButton';
import * as exploreUtils from 'src/explore/exploreUtils';
import Button from 'src/components/Button';
import { queries, queryWithBadColumns } from './fixtures';
import sqlLabReducer from '../../../src/SqlLab/reducers/index';
import * as actions from '../../../src/SqlLab/actions/sqlLab';
import ExploreResultsButton from '../../../src/SqlLab/components/ExploreResultsButton';
import * as exploreUtils from '../../../src/explore/exploreUtils';
import Button from '../../../src/components/Button';
describe('ExploreResultsButton', () => {
const middlewares = [thunk];

View File

@@ -20,8 +20,8 @@ import React from 'react';
import SyntaxHighlighter from 'react-syntax-highlighter';
import { mount, shallow } from 'enzyme';
import HighlightedSql from '../../../src/SqlLab/components/HighlightedSql';
import ModalTrigger from '../../../src/components/ModalTrigger';
import HighlightedSql from 'src/SqlLab/components/HighlightedSql';
import ModalTrigger from 'src/components/ModalTrigger';
describe('HighlightedSql', () => {
const sql =

View File

@@ -20,8 +20,8 @@ import React from 'react';
import { shallow } from 'enzyme';
import { Label } from 'react-bootstrap';
import LimitControl from '../../../src/SqlLab/components/LimitControl';
import ControlHeader from '../../../src/explore/components/ControlHeader';
import LimitControl from 'src/SqlLab/components/LimitControl';
import ControlHeader from 'src/explore/components/ControlHeader';
describe('LimitControl', () => {
const defaultProps = {
@@ -47,64 +47,43 @@ describe('LimitControl', () => {
const value = 100;
wrapper = shallow(factory({ ...defaultProps, value }));
expect(wrapper.state().textValue).toEqual(value.toString());
wrapper
.find(Label)
.first()
.simulate('click');
wrapper.find(Label).first().simulate('click');
expect(wrapper.state().showOverlay).toBe(true);
expect(wrapper.find(ControlHeader).props().validationErrors).toHaveLength(
0,
);
});
it('handles invalid value', () => {
wrapper
.find(Label)
.first()
.simulate('click');
wrapper.find(Label).first().simulate('click');
wrapper.setState({ textValue: 'invalid' });
expect(wrapper.find(ControlHeader).props().validationErrors).toHaveLength(
1,
);
});
it('handles negative value', () => {
wrapper
.find(Label)
.first()
.simulate('click');
wrapper.find(Label).first().simulate('click');
wrapper.setState({ textValue: '-1' });
expect(wrapper.find(ControlHeader).props().validationErrors).toHaveLength(
1,
);
});
it('handles value above max row', () => {
wrapper
.find(Label)
.first()
.simulate('click');
wrapper.find(Label).first().simulate('click');
wrapper.setState({ textValue: (defaultProps.maxRow + 1).toString() });
expect(wrapper.find(ControlHeader).props().validationErrors).toHaveLength(
1,
);
});
it('opens and closes', () => {
wrapper
.find(Label)
.first()
.simulate('click');
wrapper.find(Label).first().simulate('click');
expect(wrapper.state().showOverlay).toBe(true);
wrapper
.find('.ok')
.first()
.simulate('click');
wrapper.find('.ok').first().simulate('click');
expect(wrapper.state().showOverlay).toBe(false);
});
it('resets and closes', () => {
const value = 100;
wrapper = shallow(factory({ ...defaultProps, value }));
wrapper
.find(Label)
.first()
.simulate('click');
wrapper.find(Label).first().simulate('click');
expect(wrapper.state().textValue).toEqual(value.toString());
wrapper.find('.reset').simulate('click');
expect(wrapper.state().textValue).toEqual(

View File

@@ -19,7 +19,7 @@
import React from 'react';
import { shallow } from 'enzyme';
import Link from '../../../src/components/Link';
import Link from 'src/components/Link';
describe('Link', () => {
const mockedProps = {

View File

@@ -22,7 +22,7 @@ import sinon from 'sinon';
import thunk from 'redux-thunk';
import configureStore from 'redux-mock-store';
import QueryAutoRefresh from '../../../src/SqlLab/components/QueryAutoRefresh';
import QueryAutoRefresh from 'src/SqlLab/components/QueryAutoRefresh';
import { initialState, runningQuery } from './fixtures';
describe('QueryAutoRefresh', () => {

View File

@@ -22,7 +22,7 @@ import { Button } from 'react-bootstrap';
import { shallow } from 'enzyme';
import sinon from 'sinon';
import QuerySearch from '../../../src/SqlLab/components/QuerySearch';
import QuerySearch from 'src/SqlLab/components/QuerySearch';
describe('QuerySearch', () => {
const search = sinon.spy(QuerySearch.prototype, 'refreshQueries');

View File

@@ -20,7 +20,7 @@ import React from 'react';
import { Label } from 'react-bootstrap';
import { shallow } from 'enzyme';
import QueryStateLabel from '../../../src/SqlLab/components/QueryStateLabel';
import QueryStateLabel from 'src/SqlLab/components/QueryStateLabel';
describe('SavedQuery', () => {
const mockedProps = {

View File

@@ -19,9 +19,9 @@
import React from 'react';
import { shallow } from 'enzyme';
import { Table } from 'reactable-arc';
import QueryTable from 'src/SqlLab/components/QueryTable';
import { queries } from './fixtures';
import QueryTable from '../../../src/SqlLab/components/QueryTable';
describe('QueryTable', () => {
const mockedProps = {
@@ -36,18 +36,9 @@ describe('QueryTable', () => {
it('renders a proper table', () => {
const wrapper = shallow(<QueryTable {...mockedProps} />);
expect(wrapper.find(Table)).toHaveLength(1);
expect(
wrapper
.find(Table)
.shallow()
.find('table'),
).toHaveLength(1);
expect(
wrapper
.find(Table)
.shallow()
.find('table')
.find('Tr'),
).toHaveLength(2);
expect(wrapper.find(Table).shallow().find('table')).toHaveLength(1);
expect(wrapper.find(Table).shallow().find('table').find('Tr')).toHaveLength(
2,
);
});
});

View File

@@ -21,9 +21,9 @@ import { shallow } from 'enzyme';
import sinon from 'sinon';
import { Alert, ProgressBar } from 'react-bootstrap';
import FilterableTable from '../../../src/components/FilterableTable/FilterableTable';
import ExploreResultsButton from '../../../src/SqlLab/components/ExploreResultsButton';
import ResultSet from '../../../src/SqlLab/components/ResultSet';
import FilterableTable from 'src/components/FilterableTable/FilterableTable';
import ExploreResultsButton from 'src/SqlLab/components/ExploreResultsButton';
import ResultSet from 'src/SqlLab/components/ResultSet';
import { queries, stoppedQuery, runningQuery, cachedQuery } from './fixtures';
describe('ResultSet', () => {
@@ -97,12 +97,9 @@ describe('ResultSet', () => {
wrapper.setProps({ query: emptyResults });
expect(wrapper.find(FilterableTable)).toHaveLength(0);
expect(wrapper.find(Alert)).toHaveLength(1);
expect(
wrapper
.find(Alert)
.shallow()
.text(),
).toBe('The query returned no data');
expect(wrapper.find(Alert).shallow().text()).toBe(
'The query returned no data',
);
});
it('should render cached query', () => {
const wrapper = shallow(<ResultSet {...cachedQueryProps} />);

View File

@@ -20,9 +20,9 @@ import React from 'react';
import { FormControl } from 'react-bootstrap';
import { shallow } from 'enzyme';
import * as sinon from 'sinon';
import SaveQuery from '../../../src/SqlLab/components/SaveQuery';
import ModalTrigger from '../../../src/components/ModalTrigger';
import Button from '../../../src/components/Button';
import SaveQuery from 'src/SqlLab/components/SaveQuery';
import ModalTrigger from 'src/components/ModalTrigger';
import Button from 'src/components/Button';
describe('SavedQuery', () => {
const mockedProps = {
@@ -59,10 +59,7 @@ describe('SavedQuery', () => {
const wrapper = shallow(<SaveQuery {...mockedProps} onSave={saveSpy} />);
const modal = shallow(wrapper.instance().renderModalBody());
expect(modal.find(Button)).toHaveLength(2);
modal
.find(Button)
.at(0)
.simulate('click');
modal.find(Button).at(0).simulate('click');
expect(saveSpy.calledOnce).toBe(true);
});
it('has an update button if this is an existing query', () => {
@@ -77,10 +74,7 @@ describe('SavedQuery', () => {
const wrapper = shallow(<SaveQuery {...props} onUpdate={updateSpy} />);
const modal = shallow(wrapper.instance().renderModalBody());
expect(modal.find(Button)).toHaveLength(3);
modal
.find(Button)
.at(0)
.simulate('click');
modal.find(Button).at(0).simulate('click');
expect(updateSpy.calledOnce).toBe(true);
});
});

View File

@@ -24,9 +24,9 @@ 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 * as utils from 'src/utils/common';
import Button from 'src/components/Button';
import ShareSqlLabQuery from 'src/SqlLab/components/ShareSqlLabQuery';
const mockStore = configureStore([thunk]);
const store = mockStore();

View File

@@ -19,15 +19,11 @@
import React from 'react';
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import { shallow } from 'enzyme';
import { STATUS_OPTIONS } from '../../../src/SqlLab/constants';
import SouthPaneContainer, { SouthPane } from 'src/SqlLab/components/SouthPane';
import ResultSet from 'src/SqlLab/components/ResultSet';
import { STATUS_OPTIONS } from 'src/SqlLab/constants';
import { initialState } from './fixtures';
import SouthPaneContainer, {
SouthPane,
} from '../../../src/SqlLab/components/SouthPane';
import ResultSet from '../../../src/SqlLab/components/ResultSet';
describe('SouthPane', () => {
const middlewares = [thunk];
@@ -94,12 +90,7 @@ describe('SouthPane', () => {
it('should render offline when the state is offline', () => {
wrapper = getWrapper();
wrapper.setProps({ offline: true });
expect(
wrapper
.find('.m-r-3')
.render()
.text(),
).toBe(STATUS_OPTIONS.offline);
expect(wrapper.find('.m-r-3').render().text()).toBe(STATUS_OPTIONS.offline);
});
it('should pass latest query down to ResultSet component', () => {
wrapper = getWrapper();

View File

@@ -21,10 +21,10 @@ import configureStore from 'redux-mock-store';
import { shallow } from 'enzyme';
import sinon from 'sinon';
import thunk from 'redux-thunk';
import SqlEditorLeftBar from 'src/SqlLab/components/SqlEditorLeftBar';
import TableElement from 'src/SqlLab/components/TableElement';
import { table, defaultQueryEditor, initialState } from './fixtures';
import SqlEditorLeftBar from '../../../src/SqlLab/components/SqlEditorLeftBar';
import TableElement from '../../../src/SqlLab/components/TableElement';
describe('SqlEditorLeftBar', () => {
const mockedProps = {

View File

@@ -19,18 +19,18 @@
import React from 'react';
import { shallow } from 'enzyme';
import { Checkbox } from 'react-bootstrap';
import { defaultQueryEditor, initialState, queries, table } from './fixtures';
import {
SQL_EDITOR_GUTTER_HEIGHT,
SQL_EDITOR_GUTTER_MARGIN,
SQL_TOOLBAR_HEIGHT,
} from '../../../src/SqlLab/constants';
import AceEditorWrapper from '../../../src/SqlLab/components/AceEditorWrapper';
import LimitControl from '../../../src/SqlLab/components/LimitControl';
import SouthPane from '../../../src/SqlLab/components/SouthPane';
import SqlEditor from '../../../src/SqlLab/components/SqlEditor';
import SqlEditorLeftBar from '../../../src/SqlLab/components/SqlEditorLeftBar';
} from 'src/SqlLab/constants';
import AceEditorWrapper from 'src/SqlLab/components/AceEditorWrapper';
import LimitControl from 'src/SqlLab/components/LimitControl';
import SouthPane from 'src/SqlLab/components/SouthPane';
import SqlEditor from 'src/SqlLab/components/SqlEditor';
import SqlEditorLeftBar from 'src/SqlLab/components/SqlEditorLeftBar';
import { defaultQueryEditor, initialState, queries, table } from './fixtures';
const MOCKED_SQL_EDITOR_HEIGHT = 500;
@@ -109,10 +109,7 @@ describe('SqlEditor', () => {
it('allows toggling autocomplete', () => {
const wrapper = shallow(<SqlEditor {...mockedProps} />);
expect(wrapper.find(AceEditorWrapper).props().autocomplete).toBe(true);
wrapper
.find(Checkbox)
.props()
.onChange();
wrapper.find(Checkbox).props().onChange();
expect(wrapper.find(AceEditorWrapper).props().autocomplete).toBe(false);
});
});

View File

@@ -20,7 +20,7 @@ import React from 'react';
import sinon from 'sinon';
import { shallow } from 'enzyme';
import TabStatusIcon from '../../../src/SqlLab/components/TabStatusIcon';
import TabStatusIcon from 'src/SqlLab/components/TabStatusIcon';
function setup() {
const onClose = sinon.spy();

View File

@@ -20,14 +20,13 @@ import React from 'react';
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import URI from 'urijs';
import { Tab } from 'react-bootstrap';
import { shallow, mount } from 'enzyme';
import sinon from 'sinon';
import TabbedSqlEditors from 'src/SqlLab/components/TabbedSqlEditors';
import SqlEditor from 'src/SqlLab/components/SqlEditor';
import { table, initialState } from './fixtures';
import TabbedSqlEditors from '../../../src/SqlLab/components/TabbedSqlEditors';
import SqlEditor from '../../../src/SqlLab/components/SqlEditor';
describe('TabbedSqlEditors', () => {
const middlewares = [thunk];
@@ -225,18 +224,8 @@ describe('TabbedSqlEditors', () => {
});
it('should disable new tab when offline', () => {
wrapper = getWrapper();
expect(
wrapper
.find(Tab)
.last()
.props().disabled,
).toBe(false);
expect(wrapper.find(Tab).last().props().disabled).toBe(false);
wrapper.setProps({ offline: true });
expect(
wrapper
.find(Tab)
.last()
.props().disabled,
).toBe(true);
expect(wrapper.find(Tab).last().props().disabled).toBe(true);
});
});

View File

@@ -19,9 +19,9 @@
import React from 'react';
import { mount, shallow } from 'enzyme';
import Link from '../../../src/components/Link';
import TableElement from '../../../src/SqlLab/components/TableElement';
import ColumnElement from '../../../src/SqlLab/components/ColumnElement';
import Link from 'src/components/Link';
import TableElement from 'src/SqlLab/components/TableElement';
import ColumnElement from 'src/SqlLab/components/ColumnElement';
import { mockedActions, table } from './fixtures';
describe('TableElement', () => {
@@ -50,20 +50,12 @@ describe('TableElement', () => {
it('sorts columns', () => {
const wrapper = shallow(<TableElement {...mockedProps} />);
expect(wrapper.state().sortColumns).toBe(false);
expect(
wrapper
.find(ColumnElement)
.first()
.props().column.name,
).toBe('id');
expect(wrapper.find(ColumnElement).first().props().column.name).toBe('id');
wrapper.find('.sort-cols').simulate('click');
expect(wrapper.state().sortColumns).toBe(true);
expect(
wrapper
.find(ColumnElement)
.first()
.props().column.name,
).toBe('active');
expect(wrapper.find(ColumnElement).first().props().column.name).toBe(
'active',
);
});
it('calls the collapseTable action', () => {
const wrapper = mount(<TableElement {...mockedProps} />);

View File

@@ -20,8 +20,8 @@ import React from 'react';
import { mount } from 'enzyme';
import sinon from 'sinon';
import Timer from '../../../src/components/Timer';
import { now } from '../../../src/modules/dates';
import Timer from 'src/components/Timer';
import { now } from 'src/modules/dates';
describe('Timer', () => {
let wrapper;

View File

@@ -24,7 +24,7 @@ import thunk from 'redux-thunk';
import shortid from 'shortid';
import * as featureFlags from 'src/featureFlags';
import * as actions from '../../../../src/SqlLab/actions/sqlLab';
import * as actions from 'src/SqlLab/actions/sqlLab';
import { defaultQueryEditor, query } from '../fixtures';
const middlewares = [thunk];

View File

@@ -17,7 +17,7 @@
* under the License.
*/
import sinon from 'sinon';
import * as actions from '../../../src/SqlLab/actions/sqlLab';
import * as actions from 'src/SqlLab/actions/sqlLab';
export const mockedActions = sinon.stub({ ...actions });

View File

@@ -16,10 +16,11 @@
* specific language governing permissions and limitations
* under the License.
*/
import sqlLabReducer from '../../../../src/SqlLab/reducers/sqlLab';
import * as actions from '../../../../src/SqlLab/actions/sqlLab';
import sqlLabReducer from 'src/SqlLab/reducers/sqlLab';
import * as actions from 'src/SqlLab/actions/sqlLab';
import { now } from 'src/modules/dates';
import { table, initialState as mockState } from '../fixtures';
import { now } from '../../../../src/modules/dates';
const initialState = mockState.sqlLab;

View File

@@ -19,8 +19,8 @@
import {
emptyQueryResults,
clearQueryEditors,
} from '../../../../src/SqlLab/utils/reduxStateToLocalStorageHelper';
import { LOCALSTORAGE_MAX_QUERY_AGE_MS } from '../../../../src/SqlLab/constants';
} from 'src/SqlLab/utils/reduxStateToLocalStorageHelper';
import { LOCALSTORAGE_MAX_QUERY_AGE_MS } from 'src/SqlLab/constants';
import { queries, defaultQueryEditor } from '../fixtures';
describe('reduxStateToLocalStorageHelper', () => {