wix-style-react
Version:
wix-style-react
65 lines (61 loc) • 1.94 kB
JavaScript
import React from 'react';
import { mount } from 'enzyme';
import { BulkSelectionConsumer } from './BulkSelectionConsumer';
import { BulkSelection } from './BulkSelection';
describe('BulkSelection', function () {
describe('BulkSelectionConsumer error', function () {
it('should throw error when consumer is not within a BulkSelection', function () {
var create = function create() {
return mount(React.createElement(
BulkSelectionConsumer,
null,
function () {
return null;
}
));
};
expect(create).toThrow();
});
it('should throw custom error when consumer is not within a BulkSelection', function () {
var create = function create() {
return mount(React.createElement(
BulkSelectionConsumer,
{
consumerCompName: 'Consumer',
providerCompName: 'Provider'
},
function () {
return null;
}
));
};
expect(create).toThrow('Consumer cannot be rendered outside the Provider component');
});
});
it('setSelectionIds & isSelected', function () {
var _setSelectedIds = void 0,
_isSelected = void 0;
mount(React.createElement(
BulkSelection,
{ allIds: [1, 2, 3] },
React.createElement(
BulkSelectionConsumer,
null,
function (_ref) {
var setSelectedIds = _ref.setSelectedIds,
isSelected = _ref.isSelected;
_setSelectedIds = setSelectedIds;
_isSelected = isSelected;
return React.createElement('div', null);
}
)
));
expect(_isSelected(1)).toBeFalsy();
expect(_isSelected(2)).toBeFalsy();
expect(_isSelected(3)).toBeFalsy();
_setSelectedIds([1, 2]);
expect(_isSelected(1)).toBeTruthy();
expect(_isSelected(2)).toBeTruthy();
expect(_isSelected(3)).toBeFalsy();
});
});