mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 16:29:34 +00:00
FeaturePicker UT
This commit is contained in:
parent
5c8b368338
commit
a99b241ab5
@ -1,28 +1,81 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Enzyme from 'enzyme';
|
import { shallow } from 'enzyme';
|
||||||
|
import { Dropdown, DropdownItem, DropdownToggle } from 'reactstrap';
|
||||||
|
|
||||||
import FeaturePicker from '../index';
|
import FeaturePicker from '../index';
|
||||||
|
|
||||||
describe('<FeaturePicker />', () => {
|
describe('CTB <FeaturePicker />', () => {
|
||||||
let wrapper;
|
it('should use the defaultProps', () => {
|
||||||
const setOpen = jest.fn();
|
const {
|
||||||
const useStateSpy = jest.spyOn(React, 'useState');
|
defaultProps: { onClick },
|
||||||
useStateSpy.mockImplementation(init => [init, setOpen]);
|
} = FeaturePicker;
|
||||||
|
|
||||||
beforeEach(() => {
|
expect(onClick).toBeDefined();
|
||||||
wrapper = Enzyme.shallow(<FeaturePicker />);
|
expect(onClick()).toBe(undefined);
|
||||||
});
|
});
|
||||||
|
describe('<FeaturePicker /> render', () => {
|
||||||
|
let wrapper;
|
||||||
|
const setOpen = jest.fn();
|
||||||
|
const useStateSpy = jest.spyOn(React, 'useState');
|
||||||
|
useStateSpy.mockImplementation(init => [init, setOpen]);
|
||||||
|
let props = {
|
||||||
|
features: [
|
||||||
|
{
|
||||||
|
icon: 'fa-cube',
|
||||||
|
name: 'group1',
|
||||||
|
description: '',
|
||||||
|
fields: 2,
|
||||||
|
source: null,
|
||||||
|
isTemporary: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: 'fa-cube',
|
||||||
|
name: 'group2',
|
||||||
|
description: '',
|
||||||
|
fields: 2,
|
||||||
|
source: null,
|
||||||
|
isTemporary: false,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
it('should display source if it exists', () => {
|
||||||
|
props.main = true;
|
||||||
|
props.plugin = 'users-permissions';
|
||||||
|
|
||||||
describe('SetOpen', () => {
|
wrapper = shallow(<FeaturePicker {...props} />);
|
||||||
it('calls setOpen with true param', () => {
|
|
||||||
const buttonProps = wrapper.find('button').props();
|
|
||||||
|
|
||||||
buttonProps.onClick();
|
const span = wrapper
|
||||||
|
.find(DropdownToggle)
|
||||||
|
.find('p')
|
||||||
|
.at(0)
|
||||||
|
.find('span');
|
||||||
|
|
||||||
|
expect(span.text()).toContain('users-permissions');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call setOpen with true param', () => {
|
||||||
|
wrapper = shallow(<FeaturePicker {...props} />);
|
||||||
|
|
||||||
|
const button = wrapper.find(Dropdown);
|
||||||
|
const { toggle } = button.props();
|
||||||
|
|
||||||
|
toggle();
|
||||||
expect(setOpen).toHaveBeenCalledWith(true);
|
expect(setOpen).toHaveBeenCalledWith(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should call onClick with true param on dropdown item click', () => {
|
||||||
|
props.selectedFeature = 'group2';
|
||||||
|
props.onClick = jest.fn();
|
||||||
|
wrapper = shallow(<FeaturePicker {...props} />);
|
||||||
|
|
||||||
|
const item = wrapper.find(DropdownItem).first();
|
||||||
|
item.simulate('click');
|
||||||
|
|
||||||
|
expect(props.onClick).toHaveBeenCalledWith(props.features[0]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user