Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
feat(ToggleRefinement): add noRefinement class
Browse files Browse the repository at this point in the history
  • Loading branch information
samouss committed Sep 18, 2018
1 parent d937b84 commit 0f1c9d9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ import { createClassNames } from '../core/utils';

const cx = createClassNames('ToggleRefinement');

const ToggleRefinement = ({ currentRefinement, label, refine, className }) => (
<div className={classNames(cx(''), className)}>
const ToggleRefinement = ({
currentRefinement,
label,
canRefine,
refine,
className,
}) => (
<div className={classNames(cx('', !canRefine && '-noRefinement'), className)}>
<label className={cx('label')}>
<input
className={cx('checkbox')}
Expand All @@ -22,6 +28,7 @@ const ToggleRefinement = ({ currentRefinement, label, refine, className }) => (
ToggleRefinement.propTypes = {
currentRefinement: PropTypes.bool.isRequired,
label: PropTypes.string.isRequired,
canRefine: PropTypes.bool.isRequired,
refine: PropTypes.func.isRequired,
className: PropTypes.string,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('ToggleRefinement', () => {
const defaultProps = {
currentRefinement: true,
label: 'toggle the refinement',
canRefine: true,
refine: () => {},
};

Expand All @@ -33,6 +34,17 @@ describe('ToggleRefinement', () => {
expect(wrapper).toMatchSnapshot();
});

it('expect to render with a negative canRefine', () => {
const props = {
...defaultProps,
canRefine: false,
};

const wrapper = shallow(<ToggleRefinement {...props} />);

expect(wrapper).toMatchSnapshot();
});

it('expect to render with custom className', () => {
const props = {
...defaultProps,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`ToggleRefinement expect to render with a negative canRefine 1`] = `
<div
className="ais-ToggleRefinement ais-ToggleRefinement--noRefinement"
>
<label
className="ais-ToggleRefinement-label"
>
<input
checked={true}
className="ais-ToggleRefinement-checkbox"
onChange={[Function]}
type="checkbox"
/>
<span
className="ais-ToggleRefinement-labelText"
>
toggle the refinement
</span>
</label>
</div>
`;

exports[`ToggleRefinement expect to render with a negative currentRefinement 1`] = `
<div
className="ais-ToggleRefinement"
Expand Down

0 comments on commit 0f1c9d9

Please sign in to comment.