wix-style-react
Version:
wix-style-react
122 lines (109 loc) • 4.33 kB
JavaScript
import React from 'react';
import FieldWithSelectionComposite from './FieldWithSelectionComposite';
import Label from '../../Label';
import Input from '../../Input';
import InputArea from '../../InputArea';
import Checkbox from '../../Checkbox';
import FieldWithSelectionCompositeDriverFactory from './FieldWithSelectionComposite.driver';
import { createDriverFactory } from 'wix-ui-test-utils/driver-factory';
import Tooltip from '../../Tooltip/Tooltip';
describe('FieldWithSelectionComposite', function () {
var createCompositeDriverFactory = createDriverFactory(FieldWithSelectionCompositeDriverFactory);
it('should remove label wrapping when label not given', function () {
var driver = createCompositeDriverFactory(React.createElement(
FieldWithSelectionComposite,
null,
React.createElement(Input, null),
React.createElement(Checkbox, null)
));
expect(driver.hasLabel()).toBe(false);
expect(driver.getNumberOfChildren()).toBe(1);
expect(driver.hasInput()).toBe(true);
expect(driver.hasSelectionInput()).toBe(true);
});
it('should render Label with Input', function () {
var driver = createCompositeDriverFactory(React.createElement(
FieldWithSelectionComposite,
null,
React.createElement(
Label,
null,
'myLabel'
),
React.createElement(Input, null),
React.createElement(Checkbox, null)
));
expect(driver.hasLabel()).toBe(true);
expect(driver.getLabel()).toBe('myLabel');
expect(driver.hasInput()).toBe(true);
expect(driver.hasSelectionInput()).toBe(true);
});
it('should render Label with InputArea', function () {
var driver = createCompositeDriverFactory(React.createElement(
FieldWithSelectionComposite,
null,
React.createElement(Label, null),
React.createElement(InputArea, null),
React.createElement(Checkbox, null)
));
expect(driver.hasLabel()).toBe(true);
expect(driver.hasInput()).toBe(true);
expect(driver.hasSelectionInput()).toBe(true);
});
describe('input properties', function () {
it('should verify that onBlur callback was called', function () {
var onBlur = jest.fn();
var driver = createCompositeDriverFactory(React.createElement(
FieldWithSelectionComposite,
null,
React.createElement(Label, null),
React.createElement(Input, { onBlur: onBlur }),
React.createElement(Checkbox, null)
));
driver.triggerInputBlur();
expect(onBlur).toHaveBeenCalled();
});
});
describe('label attributes', function () {
it('should FieldLabelAttributes not exists if all attributes empty or false', function () {
var driver = createCompositeDriverFactory(React.createElement(
FieldWithSelectionComposite,
null,
React.createElement(Label, null),
React.createElement(InputArea, null),
React.createElement(Checkbox, null)
));
expect(driver.hasFieldLabelAttributes()).toBe(false);
});
it('should FieldLabelAttributes exists if required', function () {
var driver = createCompositeDriverFactory(React.createElement(
FieldWithSelectionComposite,
{ required: true },
React.createElement(Label, null),
React.createElement(InputArea, null),
React.createElement(Checkbox, null)
));
expect(driver.hasFieldLabelAttributes()).toBe(true);
});
it('should FieldLabelAttributes exists if info', function () {
var driver = createCompositeDriverFactory(React.createElement(
FieldWithSelectionComposite,
{ info: 'info' },
React.createElement(Label, null),
React.createElement(InputArea, null),
React.createElement(Checkbox, null)
));
expect(driver.hasFieldLabelAttributes()).toBe(true);
});
it('should FieldLabelAttributes exists if tooltip', function () {
var driver = createCompositeDriverFactory(React.createElement(
FieldWithSelectionComposite,
{ tooltip: React.createElement(Tooltip, { content: 'content' }) },
React.createElement(Label, null),
React.createElement(InputArea, null),
React.createElement(Checkbox, null)
));
expect(driver.hasFieldLabelAttributes()).toBe(true);
});
});
});