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

test: Adds tests to the filter scope components #13887

Merged
merged 1 commit into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
/* eslint-disable no-unused-expressions */
import React from 'react';
import sinon from 'sinon';
import { shallow, mount } from 'enzyme';

import { mount } from 'enzyme';
import { ThemeProvider, supersetTheme } from '@superset-ui/core';
import CheckboxControl from 'src/explore/components/controls/CheckboxControl';
import ControlHeader from 'src/explore/components/ControlHeader';
import Checkbox from 'src/components/Checkbox';
Expand All @@ -36,20 +36,21 @@ describe('CheckboxControl', () => {
let wrapper;

beforeEach(() => {
wrapper = shallow(<CheckboxControl {...defaultProps} />);
wrapper = mount(
<ThemeProvider theme={supersetTheme}>
<CheckboxControl {...defaultProps} />
</ThemeProvider>,
);
});

it('renders a Checkbox', () => {
const controlHeader = wrapper.find(ControlHeader);
const controlHeader = wrapper.childAt(0).find(ControlHeader);
expect(controlHeader).toHaveLength(1);

const headerWrapper = controlHeader.shallow();
expect(headerWrapper.find(Checkbox)).toHaveLength(1);
expect(controlHeader.find(Checkbox)).toHaveLength(1);
});

it('Checks the box when the label is clicked', () => {
const fullComponent = mount(<CheckboxControl {...defaultProps} />);

const fullComponent = wrapper.childAt(0);
const spy = sinon.spy(fullComponent.instance(), 'onChange');

fullComponent.instance().forceUpdate();
Expand Down
103 changes: 58 additions & 45 deletions superset-frontend/src/components/Checkbox/CheckboxIcons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,64 @@
* under the License.
*/
import React from 'react';
import { useTheme } from '@superset-ui/core';

export const CheckboxChecked = () => (
<svg
width="18"
height="18"
viewBox="0 0 18 18"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M16 0H2C0.89 0 0 0.9 0 2V16C0 17.1 0.89 18 2 18H16C17.11 18 18 17.1 18 16V2C18 0.9 17.11 0 16 0Z"
fill="#20A7C9"
/>
<path d="M7 14L2 9L3.41 7.59L7 11.17L14.59 3.58L16 5L7 14Z" fill="white" />
</svg>
);
export const CheckboxChecked = () => {
const theme = useTheme();
return (
<svg
width="18"
height="18"
viewBox="0 0 18 18"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M16 0H2C0.89 0 0 0.9 0 2V16C0 17.1 0.89 18 2 18H16C17.11 18 18 17.1 18 16V2C18 0.9 17.11 0 16 0Z"
fill={theme.colors.primary.base}
/>
<path
d="M7 14L2 9L3.41 7.59L7 11.17L14.59 3.58L16 5L7 14Z"
fill="white"
/>
</svg>
);
};

export const CheckboxHalfChecked = () => (
<svg
width="18"
height="18"
viewBox="0 0 18 18"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M16 0H2C0.9 0 0 0.9 0 2V16C0 17.1 0.9 18 2 18H16C17.1 18 18 17.1 18 16V2C18 0.9 17.1 0 16 0Z"
fill="#999999"
/>
<path d="M14 10H4V8H14V10Z" fill="white" />
</svg>
);
export const CheckboxHalfChecked = () => {
const theme = useTheme();
return (
<svg
width="18"
height="18"
viewBox="0 0 18 18"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M16 0H2C0.9 0 0 0.9 0 2V16C0 17.1 0.9 18 2 18H16C17.1 18 18 17.1 18 16V2C18 0.9 17.1 0 16 0Z"
fill={theme.colors.grayscale.light1}
/>
<path d="M14 10H4V8H14V10Z" fill="white" />
</svg>
);
};

export const CheckboxUnchecked = () => (
<svg
width="18"
height="18"
viewBox="0 0 18 18"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M16 0H2C0.9 0 0 0.9 0 2V16C0 17.1 0.9 18 2 18H16C17.1 18 18 17.1 18 16V2C18 0.9 17.1 0 16 0Z"
fill="#CCCCCC"
/>
<path d="M16 2V16H2V2H16V2Z" fill="white" />
</svg>
);
export const CheckboxUnchecked = () => {
const theme = useTheme();
return (
<svg
width="18"
height="18"
viewBox="0 0 18 18"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M16 0H2C0.9 0 0 0.9 0 2V16C0 17.1 0.9 18 2 18H16C17.1 18 18 17.1 18 16V2C18 0.9 17.1 0 16 0Z"
fill={theme.colors.grayscale.light2}
/>
<path d="M16 2V16H2V2H16V2Z" fill="white" />
</svg>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import cx from 'classnames';

import FormLabel from 'src/components/FormLabel';

const propTypes = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@
import React from 'react';
import PropTypes from 'prop-types';
import CheckboxTree from 'react-checkbox-tree';

import { filterScopeSelectorTreeNodePropShape } from 'src/dashboard/util/propShapes';
import treeIcons from './treeIcons';
import renderFilterFieldTreeNodes from './renderFilterFieldTreeNodes';
import { filterScopeSelectorTreeNodePropShape } from '../../util/propShapes';

const propTypes = {
activeKey: PropTypes.string,
Expand Down
Loading