2019-01-15 18:53:27 -05:00
|
|
|
/**
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
2016-11-08 13:28:51 -05:00
|
|
|
/* eslint-disable no-unused-expressions */
|
|
|
|
import React from 'react';
|
|
|
|
import sinon from 'sinon';
|
2019-11-12 13:22:17 -05:00
|
|
|
import { shallow, mount } from 'enzyme';
|
2017-04-13 18:04:09 -04:00
|
|
|
|
2020-05-07 17:18:10 -04:00
|
|
|
import CheckboxControl from 'src/explore/components/controls/CheckboxControl';
|
|
|
|
import ControlHeader from 'src/explore/components/ControlHeader';
|
|
|
|
import Checkbox from 'src/components/Checkbox';
|
2016-11-08 13:28:51 -05:00
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
name: 'show_legend',
|
|
|
|
onChange: sinon.spy(),
|
2017-05-25 14:54:26 -04:00
|
|
|
value: false,
|
2017-08-10 20:04:44 -04:00
|
|
|
label: 'checkbox label',
|
2016-11-08 13:28:51 -05:00
|
|
|
};
|
|
|
|
|
2017-02-22 11:36:47 -05:00
|
|
|
describe('CheckboxControl', () => {
|
2016-11-08 13:28:51 -05:00
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-08-10 20:04:44 -04:00
|
|
|
wrapper = shallow(<CheckboxControl {...defaultProps} />);
|
2016-11-08 13:28:51 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders a Checkbox', () => {
|
2017-08-10 20:04:44 -04:00
|
|
|
const controlHeader = wrapper.find(ControlHeader);
|
2018-10-15 16:10:18 -04:00
|
|
|
expect(controlHeader).toHaveLength(1);
|
2017-08-10 20:04:44 -04:00
|
|
|
|
|
|
|
const headerWrapper = controlHeader.shallow();
|
2018-10-15 16:10:18 -04:00
|
|
|
expect(headerWrapper.find(Checkbox)).toHaveLength(1);
|
2016-11-08 13:28:51 -05:00
|
|
|
});
|
2019-11-12 13:22:17 -05:00
|
|
|
|
|
|
|
it('Checks the box when the label is clicked', () => {
|
2020-09-24 19:53:02 -04:00
|
|
|
const fullComponent = mount(<CheckboxControl {...defaultProps} />);
|
2019-11-12 13:22:17 -05:00
|
|
|
|
|
|
|
const spy = sinon.spy(fullComponent.instance(), 'onChange');
|
|
|
|
|
|
|
|
fullComponent.instance().forceUpdate();
|
|
|
|
|
2020-05-07 17:18:10 -04:00
|
|
|
fullComponent.find('label span').last().simulate('click');
|
2019-11-12 13:22:17 -05:00
|
|
|
|
|
|
|
expect(spy.calledOnce).toBe(true);
|
|
|
|
});
|
2016-11-08 13:28:51 -05:00
|
|
|
});
|