mirror of
https://github.com/apache/superset.git
synced 2026-05-07 08:54:23 +00:00
Prettify the frontend code (#8648)
* Add Prettier global configs * Format js/jsx/ts/tsx/less files
This commit is contained in:
@@ -164,24 +164,32 @@ describe('AlteredSliceTag', () => {
|
||||
|
||||
describe('renderTriggerNode', () => {
|
||||
it('renders a TooltipWrapper', () => {
|
||||
const triggerNode = shallow(<div>{wrapper.instance().renderTriggerNode()}</div>);
|
||||
const triggerNode = shallow(
|
||||
<div>{wrapper.instance().renderTriggerNode()}</div>,
|
||||
);
|
||||
expect(triggerNode.find(TooltipWrapper)).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('renderModalBody', () => {
|
||||
it('renders a Table', () => {
|
||||
const modalBody = shallow(<div>{wrapper.instance().renderModalBody()}</div>);
|
||||
const modalBody = shallow(
|
||||
<div>{wrapper.instance().renderModalBody()}</div>,
|
||||
);
|
||||
expect(modalBody.find(Table)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('renders a Thead', () => {
|
||||
const modalBody = shallow(<div>{wrapper.instance().renderModalBody()}</div>);
|
||||
const modalBody = shallow(
|
||||
<div>{wrapper.instance().renderModalBody()}</div>,
|
||||
);
|
||||
expect(modalBody.find(Thead)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('renders Th', () => {
|
||||
const modalBody = shallow(<div>{wrapper.instance().renderModalBody()}</div>);
|
||||
const modalBody = shallow(
|
||||
<div>{wrapper.instance().renderModalBody()}</div>,
|
||||
);
|
||||
const th = modalBody.find(Th);
|
||||
expect(th).toHaveLength(3);
|
||||
['control', 'before', 'after'].forEach((v, i) => {
|
||||
@@ -190,13 +198,17 @@ describe('AlteredSliceTag', () => {
|
||||
});
|
||||
|
||||
it('renders the correct number of Tr', () => {
|
||||
const modalBody = shallow(<div>{wrapper.instance().renderModalBody()}</div>);
|
||||
const modalBody = shallow(
|
||||
<div>{wrapper.instance().renderModalBody()}</div>,
|
||||
);
|
||||
const tr = modalBody.find(Tr);
|
||||
expect(tr).toHaveLength(7);
|
||||
});
|
||||
|
||||
it('renders the correct number of Td', () => {
|
||||
const modalBody = shallow(<div>{wrapper.instance().renderModalBody()}</div>);
|
||||
const modalBody = shallow(
|
||||
<div>{wrapper.instance().renderModalBody()}</div>,
|
||||
);
|
||||
const td = modalBody.find(Td);
|
||||
expect(td).toHaveLength(21);
|
||||
['control', 'before', 'after'].forEach((v, i) => {
|
||||
@@ -225,13 +237,20 @@ describe('AlteredSliceTag', () => {
|
||||
});
|
||||
|
||||
it('returns "Max" and "Min" for BoundsControl', () => {
|
||||
expect(wrapper.instance().formatValue([5, 6], 'y_axis_bounds')).toBe('Min: 5, Max: 6');
|
||||
expect(wrapper.instance().formatValue([5, 6], 'y_axis_bounds')).toBe(
|
||||
'Min: 5, Max: 6',
|
||||
);
|
||||
});
|
||||
|
||||
it('returns stringified objects for CollectionControl', () => {
|
||||
const value = [{ 1: 2, alpha: 'bravo' }, { sent: 'imental', w0ke: 5 }];
|
||||
const value = [
|
||||
{ 1: 2, alpha: 'bravo' },
|
||||
{ sent: 'imental', w0ke: 5 },
|
||||
];
|
||||
const expected = '{"1":2,"alpha":"bravo"}, {"sent":"imental","w0ke":5}';
|
||||
expect(wrapper.instance().formatValue(value, 'column_collection')).toBe(expected);
|
||||
expect(wrapper.instance().formatValue(value, 'column_collection')).toBe(
|
||||
expected,
|
||||
);
|
||||
});
|
||||
|
||||
it('returns boolean values as string', () => {
|
||||
@@ -278,7 +297,9 @@ describe('AlteredSliceTag', () => {
|
||||
},
|
||||
];
|
||||
const expected = 'a in [1, g, 7, ho], b not in [hu, ho, ha]';
|
||||
expect(wrapper.instance().formatValue(filters, 'adhoc_filters')).toBe(expected);
|
||||
expect(wrapper.instance().formatValue(filters, 'adhoc_filters')).toBe(
|
||||
expected,
|
||||
);
|
||||
});
|
||||
|
||||
it('correctly formats filters with string values', () => {
|
||||
@@ -299,7 +320,9 @@ describe('AlteredSliceTag', () => {
|
||||
},
|
||||
];
|
||||
const expected = 'a == gucci, b LIKE moshi moshi';
|
||||
expect(wrapper.instance().formatValue(filters, 'adhoc_filters')).toBe(expected);
|
||||
expect(wrapper.instance().formatValue(filters, 'adhoc_filters')).toBe(
|
||||
expected,
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('isEqualish', () => {
|
||||
@@ -318,12 +341,18 @@ describe('AlteredSliceTag', () => {
|
||||
it('considers deeply equal objects as equal', () => {
|
||||
const inst = wrapper.instance();
|
||||
expect(inst.isEqualish('', '')).toBe(true);
|
||||
expect(inst.isEqualish({ a: 1, b: 2, c: 3 }, { a: 1, b: 2, c: 3 })).toBe(true);
|
||||
expect(inst.isEqualish({ a: 1, b: 2, c: 3 }, { a: 1, b: 2, c: 3 })).toBe(
|
||||
true,
|
||||
);
|
||||
// Out of order
|
||||
expect(inst.isEqualish({ a: 1, b: 2, c: 3 }, { b: 2, a: 1, c: 3 })).toBe(true);
|
||||
expect(inst.isEqualish({ a: 1, b: 2, c: 3 }, { b: 2, a: 1, c: 3 })).toBe(
|
||||
true,
|
||||
);
|
||||
|
||||
// Actually not equal
|
||||
expect(inst.isEqualish({ a: 1, b: 2, z: 9 }, { a: 1, b: 2, c: 3 })).toBe(false);
|
||||
expect(inst.isEqualish({ a: 1, b: 2, z: 9 }, { a: 1, b: 2, c: 3 })).toBe(
|
||||
false,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -44,15 +44,11 @@ describe('AsyncSelect', () => {
|
||||
};
|
||||
|
||||
it('is valid element', () => {
|
||||
expect(
|
||||
React.isValidElement(<AsyncSelect {...mockedProps} />),
|
||||
).toBe(true);
|
||||
expect(React.isValidElement(<AsyncSelect {...mockedProps} />)).toBe(true);
|
||||
});
|
||||
|
||||
it('has one select', () => {
|
||||
const wrapper = shallow(
|
||||
<AsyncSelect {...mockedProps} />,
|
||||
);
|
||||
const wrapper = shallow(<AsyncSelect {...mockedProps} />);
|
||||
expect(wrapper.find(Select)).toHaveLength(1);
|
||||
});
|
||||
|
||||
@@ -67,13 +63,11 @@ describe('AsyncSelect', () => {
|
||||
});
|
||||
|
||||
describe('auto select', () => {
|
||||
it('should not call onChange if autoSelect=false', (done) => {
|
||||
it('should not call onChange if autoSelect=false', done => {
|
||||
expect.assertions(2);
|
||||
|
||||
const onChangeSpy = jest.fn();
|
||||
shallow(
|
||||
<AsyncSelect {...mockedProps} onChange={onChangeSpy} />,
|
||||
);
|
||||
shallow(<AsyncSelect {...mockedProps} onChange={onChangeSpy} />);
|
||||
|
||||
setTimeout(() => {
|
||||
expect(fetchMock.calls(dataGlob)).toHaveLength(1);
|
||||
@@ -82,7 +76,7 @@ describe('AsyncSelect', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should auto select the first option if autoSelect=true', (done) => {
|
||||
it('should auto select the first option if autoSelect=true', done => {
|
||||
expect.assertions(3);
|
||||
|
||||
const onChangeSpy = jest.fn();
|
||||
@@ -98,12 +92,17 @@ describe('AsyncSelect', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should not auto select when value prop is set and autoSelect=true', (done) => {
|
||||
it('should not auto select when value prop is set and autoSelect=true', done => {
|
||||
expect.assertions(3);
|
||||
|
||||
const onChangeSpy = jest.fn();
|
||||
const wrapper = shallow(
|
||||
<AsyncSelect {...mockedProps} value={2} onChange={onChangeSpy} autoSelect />,
|
||||
<AsyncSelect
|
||||
{...mockedProps}
|
||||
value={2}
|
||||
onChange={onChangeSpy}
|
||||
autoSelect
|
||||
/>,
|
||||
);
|
||||
|
||||
setTimeout(() => {
|
||||
@@ -114,7 +113,7 @@ describe('AsyncSelect', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should call onAsyncError if there is an error fetching options', (done) => {
|
||||
it('should call onAsyncError if there is an error fetching options', done => {
|
||||
expect.assertions(3);
|
||||
|
||||
const errorEndpoint = 'async/error/';
|
||||
@@ -123,7 +122,11 @@ describe('AsyncSelect', () => {
|
||||
|
||||
const onAsyncError = jest.fn();
|
||||
shallow(
|
||||
<AsyncSelect {...mockedProps} dataEndpoint={errorEndpoint} onAsyncError={onAsyncError} />,
|
||||
<AsyncSelect
|
||||
{...mockedProps}
|
||||
dataEndpoint={errorEndpoint}
|
||||
onAsyncError={onAsyncError}
|
||||
/>,
|
||||
);
|
||||
|
||||
setTimeout(() => {
|
||||
|
||||
@@ -29,14 +29,10 @@ describe('CachedLabel', () => {
|
||||
};
|
||||
|
||||
it('is valid', () => {
|
||||
expect(
|
||||
React.isValidElement(<CachedLabel {...defaultProps} />),
|
||||
).toBe(true);
|
||||
expect(React.isValidElement(<CachedLabel {...defaultProps} />)).toBe(true);
|
||||
});
|
||||
it('renders', () => {
|
||||
const wrapper = shallow(
|
||||
<CachedLabel {...defaultProps} />,
|
||||
);
|
||||
const wrapper = shallow(<CachedLabel {...defaultProps} />);
|
||||
expect(wrapper.find(Label)).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,7 +29,7 @@ describe('Checkbox', () => {
|
||||
};
|
||||
|
||||
let wrapper;
|
||||
const factory = (o) => {
|
||||
const factory = o => {
|
||||
const props = Object.assign({}, defaultProps, o);
|
||||
return shallow(<Checkbox {...props} />);
|
||||
};
|
||||
@@ -49,7 +49,10 @@ describe('Checkbox', () => {
|
||||
});
|
||||
it('unchecks when clicked', () => {
|
||||
expect(wrapper.find('i.fa-check.text-transparent')).toHaveLength(0);
|
||||
wrapper.find('i').first().simulate('click');
|
||||
wrapper
|
||||
.find('i')
|
||||
.first()
|
||||
.simulate('click');
|
||||
expect(defaultProps.onChange.calledOnce).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -60,17 +60,24 @@ describe('ColumnOption', () => {
|
||||
it('shows a label with column_name when no verbose_name', () => {
|
||||
props.column.verbose_name = null;
|
||||
wrapper = shallow(factory(props));
|
||||
expect(wrapper.find('.option-label').first().text()).toBe('foo');
|
||||
expect(
|
||||
wrapper
|
||||
.find('.option-label')
|
||||
.first()
|
||||
.text(),
|
||||
).toBe('foo');
|
||||
});
|
||||
it('shows a column type label when showType is true', () => {
|
||||
wrapper = shallow(factory({
|
||||
...props,
|
||||
showType: true,
|
||||
column: {
|
||||
expression: null,
|
||||
type: 'str',
|
||||
},
|
||||
}));
|
||||
wrapper = shallow(
|
||||
factory({
|
||||
...props,
|
||||
showType: true,
|
||||
column: {
|
||||
expression: null,
|
||||
type: 'str',
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(wrapper.find(ColumnTypeLabel)).toHaveLength(1);
|
||||
});
|
||||
it('column with expression has correct column label if showType is true', () => {
|
||||
@@ -80,14 +87,16 @@ describe('ColumnOption', () => {
|
||||
expect(wrapper.find(ColumnTypeLabel).props().type).toBe('expression');
|
||||
});
|
||||
it('shows no column type label when type is null', () => {
|
||||
wrapper = shallow(factory({
|
||||
...props,
|
||||
showType: true,
|
||||
column: {
|
||||
expression: null,
|
||||
type: null,
|
||||
},
|
||||
}));
|
||||
wrapper = shallow(
|
||||
factory({
|
||||
...props,
|
||||
showType: true,
|
||||
column: {
|
||||
expression: null,
|
||||
type: null,
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(wrapper.find(ColumnTypeLabel)).toHaveLength(0);
|
||||
});
|
||||
it('dttm column has correct column label if showType is true', () => {
|
||||
|
||||
@@ -34,7 +34,9 @@ describe('ColumnOption', () => {
|
||||
}
|
||||
|
||||
it('is a valid element', () => {
|
||||
expect(React.isValidElement(<ColumnTypeLabel {...defaultProps} />)).toBe(true);
|
||||
expect(React.isValidElement(<ColumnTypeLabel {...defaultProps} />)).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
it('string type shows ABC icon', () => {
|
||||
const lbl = getWrapper({}).find('.type-label');
|
||||
|
||||
@@ -26,8 +26,8 @@ describe('CopyToClipboard', () => {
|
||||
};
|
||||
|
||||
it('renders', () => {
|
||||
expect(
|
||||
React.isValidElement(<CopyToClipboard {...defaultProps} />),
|
||||
).toBe(true);
|
||||
expect(React.isValidElement(<CopyToClipboard {...defaultProps} />)).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,7 +18,9 @@
|
||||
*/
|
||||
import React from 'react';
|
||||
import { mount } from 'enzyme';
|
||||
import FilterableTable, { MAX_COLUMNS_FOR_TABLE } from '../../../../src/components/FilterableTable/FilterableTable';
|
||||
import FilterableTable, {
|
||||
MAX_COLUMNS_FOR_TABLE,
|
||||
} from '../../../../src/components/FilterableTable/FilterableTable';
|
||||
|
||||
describe('FilterableTable', () => {
|
||||
const mockedProps = {
|
||||
@@ -35,7 +37,9 @@ describe('FilterableTable', () => {
|
||||
wrapper = mount(<FilterableTable {...mockedProps} />);
|
||||
});
|
||||
it('is valid element', () => {
|
||||
expect(React.isValidElement(<FilterableTable {...mockedProps} />)).toBe(true);
|
||||
expect(React.isValidElement(<FilterableTable {...mockedProps} />)).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
it('renders a grid with 2 Table rows', () => {
|
||||
expect(wrapper.find('.ReactVirtualized__Grid')).toHaveLength(1);
|
||||
@@ -44,13 +48,22 @@ describe('FilterableTable', () => {
|
||||
it('renders a grid with 2 Grid rows for wide tables', () => {
|
||||
const wideTableColumns = MAX_COLUMNS_FOR_TABLE + 1;
|
||||
const wideTableMockedProps = {
|
||||
orderedColumnKeys: Array.from(Array(wideTableColumns), (_, x) => `col_${x}`),
|
||||
orderedColumnKeys: Array.from(
|
||||
Array(wideTableColumns),
|
||||
(_, x) => `col_${x}`,
|
||||
),
|
||||
data: [
|
||||
Object.assign(...Array.from(Array(wideTableColumns)).map((val, x) => ({ [`col_${x}`]: x }))),
|
||||
Object.assign(
|
||||
...Array.from(Array(wideTableColumns)).map((val, x) => ({
|
||||
[`col_${x}`]: x,
|
||||
})),
|
||||
),
|
||||
],
|
||||
height: 500,
|
||||
};
|
||||
const wideTableWrapper = mount(<FilterableTable {...wideTableMockedProps} />);
|
||||
const wideTableWrapper = mount(
|
||||
<FilterableTable {...wideTableMockedProps} />,
|
||||
);
|
||||
expect(wideTableWrapper.find('.ReactVirtualized__Grid')).toHaveLength(2);
|
||||
});
|
||||
it('filters on a string', () => {
|
||||
|
||||
@@ -55,5 +55,4 @@ describe('FormRow', () => {
|
||||
expect(wrapper.find(Row)).toHaveLength(1);
|
||||
expect(wrapper.find(Col)).toHaveLength(2);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -61,7 +61,12 @@ describe('MetricOption', () => {
|
||||
it('shows a label with metric_name when no verbose_name', () => {
|
||||
props.metric.verbose_name = null;
|
||||
wrapper = shallow(factory(props));
|
||||
expect(wrapper.find('.option-label').first().text()).toBe('foo');
|
||||
expect(
|
||||
wrapper
|
||||
.find('.option-label')
|
||||
.first()
|
||||
.text(),
|
||||
).toBe('foo');
|
||||
});
|
||||
it('shows only 1 InfoTooltipWithTrigger when no descr and no warning', () => {
|
||||
props.metric.warning_text = null;
|
||||
|
||||
@@ -28,8 +28,6 @@ describe('ModalTrigger', () => {
|
||||
};
|
||||
|
||||
it('is a valid element', () => {
|
||||
expect(
|
||||
React.isValidElement(<ModalTrigger {...defaultProps} />),
|
||||
).toBe(true);
|
||||
expect(React.isValidElement(<ModalTrigger {...defaultProps} />)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -83,8 +83,8 @@ describe('OnPasteSelect', () => {
|
||||
});
|
||||
|
||||
it('calls onChange with pasted new line separated values', () => {
|
||||
evt.clipboardData.getData = sinon.spy(() =>
|
||||
'United States\nChina\nRussian Federation\nIndia',
|
||||
evt.clipboardData.getData = sinon.spy(
|
||||
() => 'United States\nChina\nRussian Federation\nIndia',
|
||||
);
|
||||
wrapper.instance().onPaste(evt);
|
||||
expected = [
|
||||
@@ -99,8 +99,8 @@ describe('OnPasteSelect', () => {
|
||||
});
|
||||
|
||||
it('calls onChange with pasted tab separated values', () => {
|
||||
evt.clipboardData.getData = sinon.spy(() =>
|
||||
'Russian Federation\tMexico\tIndia\tCanada',
|
||||
evt.clipboardData.getData = sinon.spy(
|
||||
() => 'Russian Federation\tMexico\tIndia\tCanada',
|
||||
);
|
||||
wrapper.instance().onPaste(evt);
|
||||
expected = [
|
||||
@@ -115,8 +115,8 @@ describe('OnPasteSelect', () => {
|
||||
});
|
||||
|
||||
it('calls onChange without duplicate values and adds new comma separated values', () => {
|
||||
evt.clipboardData.getData = sinon.spy(() =>
|
||||
'China, China, China, China, Mexico, Mexico, Chi na, Mexico, ',
|
||||
evt.clipboardData.getData = sinon.spy(
|
||||
() => 'China, China, China, China, Mexico, Mexico, Chi na, Mexico, ',
|
||||
);
|
||||
expected = [
|
||||
props.options[1],
|
||||
@@ -132,14 +132,10 @@ describe('OnPasteSelect', () => {
|
||||
});
|
||||
|
||||
it('calls onChange without duplicate values and parses new line separated values', () => {
|
||||
evt.clipboardData.getData = sinon.spy(() =>
|
||||
'United States\nCanada\nMexico\nUnited States\nCanada',
|
||||
evt.clipboardData.getData = sinon.spy(
|
||||
() => 'United States\nCanada\nMexico\nUnited States\nCanada',
|
||||
);
|
||||
expected = [
|
||||
props.options[0],
|
||||
props.options[3],
|
||||
props.options[6],
|
||||
];
|
||||
expected = [props.options[0], props.options[3], props.options[6]];
|
||||
wrapper.instance().onPaste(evt);
|
||||
expect(props.onChange.calledWith(expected)).toBe(true);
|
||||
expect(evt.preventDefault.called).toBe(true);
|
||||
@@ -147,25 +143,25 @@ describe('OnPasteSelect', () => {
|
||||
});
|
||||
|
||||
it('calls onChange without duplicate values and parses tab separated values', () => {
|
||||
evt.clipboardData.getData = sinon.spy(() =>
|
||||
'China\tIndia\tChina\tRussian Federation\tJapan\tJapan',
|
||||
);
|
||||
expected = [
|
||||
props.options[1],
|
||||
props.options[2],
|
||||
props.options[4],
|
||||
props.options[5],
|
||||
];
|
||||
wrapper.instance().onPaste(evt);
|
||||
expect(props.onChange.calledWith(expected)).toBe(true);
|
||||
expect(evt.preventDefault.called).toBe(true);
|
||||
expect(props.isValidNewOption.callCount).toBe(24);
|
||||
});
|
||||
evt.clipboardData.getData = sinon.spy(
|
||||
() => 'China\tIndia\tChina\tRussian Federation\tJapan\tJapan',
|
||||
);
|
||||
expected = [
|
||||
props.options[1],
|
||||
props.options[2],
|
||||
props.options[4],
|
||||
props.options[5],
|
||||
];
|
||||
wrapper.instance().onPaste(evt);
|
||||
expect(props.onChange.calledWith(expected)).toBe(true);
|
||||
expect(evt.preventDefault.called).toBe(true);
|
||||
expect(props.isValidNewOption.callCount).toBe(24);
|
||||
});
|
||||
|
||||
it('calls onChange with currently selected values and new comma separated values', () => {
|
||||
props.value = ['United States', 'Canada', 'Mexico'];
|
||||
evt.clipboardData.getData = sinon.spy(() =>
|
||||
'United States, Canada, Japan, India',
|
||||
evt.clipboardData.getData = sinon.spy(
|
||||
() => 'United States, Canada, Japan, India',
|
||||
);
|
||||
wrapper = shallow(<OnPasteSelect {...props} />);
|
||||
expected = [
|
||||
@@ -183,9 +179,7 @@ describe('OnPasteSelect', () => {
|
||||
|
||||
it('calls onChange with currently selected values and new "new line" separated values', () => {
|
||||
props.value = ['China', 'India', 'Japan'];
|
||||
evt.clipboardData.getData = sinon.spy(() =>
|
||||
'Mexico\nJapan\nIndia',
|
||||
);
|
||||
evt.clipboardData.getData = sinon.spy(() => 'Mexico\nJapan\nIndia');
|
||||
wrapper = shallow(<OnPasteSelect {...props} />);
|
||||
expected = [
|
||||
props.options[1],
|
||||
@@ -200,23 +194,23 @@ describe('OnPasteSelect', () => {
|
||||
});
|
||||
|
||||
it('calls onChange with currently selected values and new tab separated values', () => {
|
||||
props.value = ['United States', 'Canada', 'Mexico', 'Russian Federation'];
|
||||
evt.clipboardData.getData = sinon.spy(() =>
|
||||
'United States\tCanada\tJapan\tIndia',
|
||||
);
|
||||
wrapper = shallow(<OnPasteSelect {...props} />);
|
||||
expected = [
|
||||
props.options[0],
|
||||
props.options[3],
|
||||
props.options[6],
|
||||
props.options[4],
|
||||
props.options[5],
|
||||
props.options[2],
|
||||
];
|
||||
wrapper.instance().onPaste(evt);
|
||||
expect(props.onChange.calledWith(expected)).toBe(true);
|
||||
expect(evt.preventDefault.called).toBe(true);
|
||||
expect(props.isValidNewOption.callCount).toBe(29);
|
||||
});
|
||||
props.value = ['United States', 'Canada', 'Mexico', 'Russian Federation'];
|
||||
evt.clipboardData.getData = sinon.spy(
|
||||
() => 'United States\tCanada\tJapan\tIndia',
|
||||
);
|
||||
wrapper = shallow(<OnPasteSelect {...props} />);
|
||||
expected = [
|
||||
props.options[0],
|
||||
props.options[3],
|
||||
props.options[6],
|
||||
props.options[4],
|
||||
props.options[5],
|
||||
props.options[2],
|
||||
];
|
||||
wrapper.instance().onPaste(evt);
|
||||
expect(props.onChange.calledWith(expected)).toBe(true);
|
||||
expect(evt.preventDefault.called).toBe(true);
|
||||
expect(props.isValidNewOption.callCount).toBe(29);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -31,7 +31,7 @@ describe('PopoverSection', () => {
|
||||
};
|
||||
|
||||
let wrapper;
|
||||
const factory = (overrideProps) => {
|
||||
const factory = overrideProps => {
|
||||
const props = Object.assign({}, defaultProps, overrideProps || {});
|
||||
return shallow(<PopoverSection {...props} />);
|
||||
};
|
||||
@@ -39,7 +39,9 @@ describe('PopoverSection', () => {
|
||||
wrapper = factory();
|
||||
});
|
||||
it('renders', () => {
|
||||
expect(React.isValidElement(<PopoverSection {...defaultProps} />)).toBe(true);
|
||||
expect(React.isValidElement(<PopoverSection {...defaultProps} />)).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
it('is show an icon when selected', () => {
|
||||
expect(wrapper.find('.fa-check')).toHaveLength(1);
|
||||
|
||||
@@ -81,12 +81,10 @@ describe('TableSelector', () => {
|
||||
afterAll(fetchMock.reset);
|
||||
|
||||
it('should handle empty', () =>
|
||||
inst
|
||||
.getTableNamesBySubStr('')
|
||||
.then((data) => {
|
||||
expect(data).toEqual({ options: [] });
|
||||
return Promise.resolve();
|
||||
}));
|
||||
inst.getTableNamesBySubStr('').then(data => {
|
||||
expect(data).toEqual({ options: [] });
|
||||
return Promise.resolve();
|
||||
}));
|
||||
|
||||
it('should handle table name', () => {
|
||||
fetchMock.get(GET_TABLE_NAMES_GLOB, tables, { overwriteRoutes: true });
|
||||
@@ -94,28 +92,29 @@ describe('TableSelector', () => {
|
||||
return wrapper
|
||||
.instance()
|
||||
.getTableNamesBySubStr('my table')
|
||||
.then((data) => {
|
||||
.then(data => {
|
||||
expect(fetchMock.calls(GET_TABLE_NAMES_GLOB)).toHaveLength(1);
|
||||
expect(data).toEqual({
|
||||
options: [
|
||||
{
|
||||
value: 'birth_names',
|
||||
schema: 'main',
|
||||
label: 'birth_names',
|
||||
title: 'birth_names',
|
||||
},
|
||||
{
|
||||
value: 'energy_usage',
|
||||
schema: 'main',
|
||||
label: 'energy_usage',
|
||||
title: 'energy_usage',
|
||||
},
|
||||
{
|
||||
value: 'wb_health_population',
|
||||
schema: 'main',
|
||||
label: 'wb_health_population',
|
||||
title: 'wb_health_population',
|
||||
}],
|
||||
{
|
||||
value: 'birth_names',
|
||||
schema: 'main',
|
||||
label: 'birth_names',
|
||||
title: 'birth_names',
|
||||
},
|
||||
{
|
||||
value: 'energy_usage',
|
||||
schema: 'main',
|
||||
label: 'energy_usage',
|
||||
title: 'energy_usage',
|
||||
},
|
||||
{
|
||||
value: 'wb_health_population',
|
||||
schema: 'main',
|
||||
label: 'wb_health_population',
|
||||
title: 'wb_health_population',
|
||||
},
|
||||
],
|
||||
});
|
||||
return Promise.resolve();
|
||||
});
|
||||
@@ -130,8 +129,9 @@ describe('TableSelector', () => {
|
||||
.instance()
|
||||
.getTableNamesBySubStr('slashed/table')
|
||||
.then(() => {
|
||||
expect(fetchMock.lastUrl(GET_TABLE_GLOB))
|
||||
.toContain('/slashed%252Fschema/slashed%252Ftable');
|
||||
expect(fetchMock.lastUrl(GET_TABLE_GLOB)).toContain(
|
||||
'/slashed%252Fschema/slashed%252Ftable',
|
||||
);
|
||||
return Promise.resolve();
|
||||
});
|
||||
});
|
||||
@@ -149,37 +149,39 @@ describe('TableSelector', () => {
|
||||
|
||||
it('should fetch table options', () => {
|
||||
fetchMock.get(FETCH_TABLES_GLOB, tables, { overwriteRoutes: true });
|
||||
return inst
|
||||
.fetchTables(true, 'birth_names')
|
||||
.then(() => {
|
||||
expect(wrapper.state().tableOptions).toHaveLength(3);
|
||||
expect(wrapper.state().tableOptions).toEqual([
|
||||
{
|
||||
value: 'birth_names',
|
||||
schema: 'main',
|
||||
label: 'birth_names',
|
||||
title: 'birth_names',
|
||||
},
|
||||
{
|
||||
value: 'energy_usage',
|
||||
schema: 'main',
|
||||
label: 'energy_usage',
|
||||
title: 'energy_usage',
|
||||
},
|
||||
{
|
||||
value: 'wb_health_population',
|
||||
schema: 'main',
|
||||
label: 'wb_health_population',
|
||||
title: 'wb_health_population',
|
||||
},
|
||||
]);
|
||||
return Promise.resolve();
|
||||
});
|
||||
return inst.fetchTables(true, 'birth_names').then(() => {
|
||||
expect(wrapper.state().tableOptions).toHaveLength(3);
|
||||
expect(wrapper.state().tableOptions).toEqual([
|
||||
{
|
||||
value: 'birth_names',
|
||||
schema: 'main',
|
||||
label: 'birth_names',
|
||||
title: 'birth_names',
|
||||
},
|
||||
{
|
||||
value: 'energy_usage',
|
||||
schema: 'main',
|
||||
label: 'energy_usage',
|
||||
title: 'energy_usage',
|
||||
},
|
||||
{
|
||||
value: 'wb_health_population',
|
||||
schema: 'main',
|
||||
label: 'wb_health_population',
|
||||
title: 'wb_health_population',
|
||||
},
|
||||
]);
|
||||
return Promise.resolve();
|
||||
});
|
||||
});
|
||||
|
||||
// Test needs to be fixed: Github issue #7768
|
||||
xit('should dispatch a danger toast on error', () => {
|
||||
fetchMock.get(FETCH_TABLES_GLOB, { throws: 'error' }, { overwriteRoutes: true });
|
||||
fetchMock.get(
|
||||
FETCH_TABLES_GLOB,
|
||||
{ throws: 'error' },
|
||||
{ overwriteRoutes: true },
|
||||
);
|
||||
|
||||
wrapper
|
||||
.instance()
|
||||
@@ -202,7 +204,9 @@ describe('TableSelector', () => {
|
||||
const schemaOptions = {
|
||||
schemas: ['main', 'erf', 'superset'],
|
||||
};
|
||||
fetchMock.get(FETCH_SCHEMAS_GLOB, schemaOptions, { overwriteRoutes: true });
|
||||
fetchMock.get(FETCH_SCHEMAS_GLOB, schemaOptions, {
|
||||
overwriteRoutes: true,
|
||||
});
|
||||
|
||||
return wrapper
|
||||
.instance()
|
||||
|
||||
@@ -33,7 +33,9 @@ describe('URLShortLinkButton', () => {
|
||||
function setup() {
|
||||
const mockStore = configureStore([]);
|
||||
const store = mockStore({});
|
||||
return shallow(<URLShortLinkButton {...defaultProps} />, { context: { store } }).dive();
|
||||
return shallow(<URLShortLinkButton {...defaultProps} />, {
|
||||
context: { store },
|
||||
}).dive();
|
||||
}
|
||||
|
||||
it('renders OverlayTrigger', () => {
|
||||
|
||||
@@ -33,7 +33,9 @@ describe('URLShortLinkModal', () => {
|
||||
function setup() {
|
||||
const mockStore = configureStore([]);
|
||||
const store = mockStore({});
|
||||
return shallow(<URLShortLinkModal {...defaultProps} />, { context: { store } }).dive();
|
||||
return shallow(<URLShortLinkModal {...defaultProps} />, {
|
||||
context: { store },
|
||||
}).dive();
|
||||
}
|
||||
|
||||
it('renders ModalTrigger', () => {
|
||||
|
||||
@@ -34,9 +34,7 @@ const defaultProps = {
|
||||
};
|
||||
|
||||
function TestOption({ option }) {
|
||||
return (
|
||||
<span>{option.label}</span>
|
||||
);
|
||||
return <span>{option.label}</span>;
|
||||
}
|
||||
TestOption.propTypes = {
|
||||
option: PropTypes.object.isRequired,
|
||||
@@ -75,14 +73,18 @@ describe('VirtualizedRendererWrap', () => {
|
||||
props.option = props.focusedOption;
|
||||
wrapper = shallow(<RendererWrap {...props} />);
|
||||
const optionDiv = wrapper.find('div');
|
||||
expect(optionDiv.props().className).toBe('VirtualizedSelectOption VirtualizedSelectFocusedOption');
|
||||
expect(optionDiv.props().className).toBe(
|
||||
'VirtualizedSelectOption VirtualizedSelectFocusedOption',
|
||||
);
|
||||
});
|
||||
|
||||
it('renders disabled option with the correct class', () => {
|
||||
props.option.disabled = true;
|
||||
wrapper = shallow(<RendererWrap {...props} />);
|
||||
const optionDiv = wrapper.find('div');
|
||||
expect(optionDiv.props().className).toBe('VirtualizedSelectOption VirtualizedSelectDisabledOption');
|
||||
expect(optionDiv.props().className).toBe(
|
||||
'VirtualizedSelectOption VirtualizedSelectDisabledOption',
|
||||
);
|
||||
props.option.disabled = false;
|
||||
});
|
||||
|
||||
@@ -90,14 +92,18 @@ describe('VirtualizedRendererWrap', () => {
|
||||
props.valueArray = [props.option, props.focusedOption];
|
||||
wrapper = shallow(<RendererWrap {...props} />);
|
||||
const optionDiv = wrapper.find('div');
|
||||
expect(optionDiv.props().className).toBe('VirtualizedSelectOption VirtualizedSelectSelectedOption');
|
||||
expect(optionDiv.props().className).toBe(
|
||||
'VirtualizedSelectOption VirtualizedSelectSelectedOption',
|
||||
);
|
||||
});
|
||||
|
||||
it('renders options with custom classes', () => {
|
||||
props.option.className = 'CustomClass';
|
||||
wrapper = shallow(<RendererWrap {...props} />);
|
||||
const optionDiv = wrapper.find('div');
|
||||
expect(optionDiv.props().className).toBe('VirtualizedSelectOption CustomClass');
|
||||
expect(optionDiv.props().className).toBe(
|
||||
'VirtualizedSelectOption CustomClass',
|
||||
);
|
||||
});
|
||||
|
||||
it('calls focusedOption on its own option onMouseEnter', () => {
|
||||
|
||||
Reference in New Issue
Block a user