wix-style-react
Version:
wix-style-react
99 lines (79 loc) • 3.51 kB
JavaScript
import React from 'react';
import ReactTestUtils from 'react-dom/test-utils';
import checkboxDriverFactory from './Checkbox.driver';
import { createDriverFactory } from 'wix-ui-test-utils/driver-factory';
import { checkboxTestkitFactory } from '../../testkit';
import Checkbox from './Checkbox';
import { checkboxTestkitFactory as enzymeCheckboxTestkitFactory } from '../../testkit/enzyme';
import { mount } from 'enzyme';
var cachedConsoleWarn = global.console.warn;
describe('Checkbox', function () {
var createDriver = createDriverFactory(checkboxDriverFactory);
it('should be unchecked and not disabled by default', function () {
var driver = createDriver(React.createElement(Checkbox, null));
expect(driver.isChecked()).toBeFalsy();
expect(driver.isDisabled()).toBeFalsy();
});
it('should be checked', function () {
var driver = createDriver(React.createElement(Checkbox, { checked: true }));
expect(driver.isChecked()).toBeTruthy();
});
it('should be disabled', function () {
var driver = createDriver(React.createElement(Checkbox, { disabled: true }));
expect(driver.isDisabled()).toBeTruthy();
});
it('should have an error state', function () {
var driver = createDriver(React.createElement(Checkbox, { hasError: true }));
expect(driver.hasError()).toBeTruthy();
});
it('should call onChange when clicking the Checkbox', function () {
var onChange = jest.fn();
var driver = createDriver(React.createElement(Checkbox, { onChange: onChange }));
driver.click();
expect(onChange).toBeCalledWith(expect.objectContaining({ target: { checked: true } }));
});
it('should not call onChange when clicking disabled Checkbox', function () {
var onChange = jest.fn();
var driver = createDriver(React.createElement(Checkbox, { onChange: onChange, disabled: true }));
driver.click();
expect(onChange).not.toBeCalled();
});
it('should not run in indeterminate mode when not specified', function () {
var driver = createDriver(React.createElement(Checkbox, null));
expect(driver.isIndeterminate()).toBeFalsy();
});
it('should run in indeterminate mode when specified', function () {
var driver = createDriver(React.createElement(Checkbox, { indeterminate: true }));
expect(driver.isIndeterminate()).toBeTruthy();
});
it('should not warn with deprecation warning, if no size', function () {
global.console.warn = jest.fn();
createDriver(React.createElement(Checkbox, null));
expect(global.console.warn).not.toBeCalled();
global.console.warn = cachedConsoleWarn;
});
describe('testkit', function () {
it('should exist', function () {
var div = document.createElement('div');
var dataHook = 'myDataHook';
var wrapper = div.appendChild(ReactTestUtils.renderIntoDocument(React.createElement(
'div',
null,
React.createElement(Checkbox, { dataHook: dataHook })
)));
var checkboxTestkit = checkboxTestkitFactory({ wrapper: wrapper, dataHook: dataHook });
expect(checkboxTestkit.exists()).toBeTruthy();
});
});
describe('enzyme testkit', function () {
it('should exist', function () {
var dataHook = 'myDataHook';
var wrapper = mount(React.createElement(Checkbox, { dataHook: dataHook }));
var checkboxTestkit = enzymeCheckboxTestkitFactory({
wrapper: wrapper,
dataHook: dataHook
});
expect(checkboxTestkit.exists()).toBeTruthy();
});
});
});