Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('renders a text field with the correct props when the editable prop is true', () => {
let slider = renderIntoDocument();
let texts = scryRenderedComponentsWithType(slider, TextField);
expect(texts.length).toBe(0);
slider = renderIntoDocument();
texts = scryRenderedComponentsWithType(slider, TextField);
expect(texts.length).toBe(1);
const [text] = texts;
expect(text.props.type).toBe('number');
expect(text.props.value).toBe(slider.state.value);
expect(text.props.onChange).toBe(slider._handleTextFieldChange);
expect(text.props.step).toBe(Slider.defaultProps.step);
});
it('renders an input tag when the rows prop is undefined', () => {
const props = {};
let field = renderIntoDocument();
let inputs = scryRenderedDOMComponentsWithTag(field, 'input');
let areas = scryRenderedComponentsWithType(field, TextArea);
expect(inputs.length).toBe(1);
expect(areas.length).toBe(0);
props.rows = 2;
field = renderIntoDocument();
inputs = scryRenderedDOMComponentsWithTag(field, 'input');
areas = scryRenderedComponentsWithType(field, TextArea);
expect(inputs.length).toBe(0);
expect(areas.length).toBe(1);
});
it('displays a picker control for selecting the year and a picker control for selecting the calendar', () => {
const DateTimeFormat = require('../../utils/DateUtils/DateTimeFormat');
const props = {
changeCalendarMode: jest.fn(),
DateTimeFormat,
locales: 'en-US',
calendarTempDate: new Date(2016, 1, 1),
calendarMode: 'year',
};
const header = renderIntoDocument();
const controls = scryRenderedComponentsWithType(header, PickerControl);
expect(controls.length).toBe(2);
const [year, calendar] = controls;
expect(year.props.onClick).toBe(header._selectYear);
expect(calendar.props.onClick).toBe(header._selectCalendar);
});
it('renders the CardTitleBlock with the correct props', () => {
const props = { title: 'Woop', id: 'boop', subtitle: 'noop' };
const title = renderIntoDocument();
const blocks = scryRenderedComponentsWithType(title, CardTitleBlock);
expect(blocks.length).toBe(1);
const bProps = blocks[0].props;
expect(bProps.id).toBe(props.id);
expect(bProps.title).toBe(props.title);
expect(bProps.subtitle).toBe(props.subtitle);
});
});
it('renders the number of years from yearsDisplayed', () => {
const props = {
calendarTempDate: new Date(2016, 1, 1),
onCalendarYearClick: jest.fn(),
yearsDisplayed: 100,
};
let yearPicker = renderIntoDocument();
let years = scryRenderedComponentsWithType(yearPicker, Year);
expect(years.length).toBe(props.yearsDisplayed);
props.yearsDisplayed = 5;
yearPicker = renderIntoDocument();
years = scryRenderedComponentsWithType(yearPicker, Year);
expect(years.length).toBe(props.yearsDisplayed);
});
export function scryRenderedComponentsWithTypeAndProps(root, type, props) {
if (!root) { throw new Error("Must supply a root to scryRenderedComponentsWithTypeAndProps"); }
return _.compact(_.map(ReactTestUtils.scryRenderedComponentsWithType(root, type), (el) => {
if (_.isEqual(_.pick(el.props, Object.keys(props)), props)) {
return el;
}
return false;
}));
}
const mountSticky = (component) => {
this.stickyContainer = mount();
this.sticky = ReactTestUtils.scryRenderedComponentsWithType(this.stickyContainer, Sticky)[0];
};
okPrimary: false,
onOkClick: jest.fn(),
cancelLabel: 'a',
cancelPrimary: false,
onCancelClick: jest.fn(),
DateTimeFormat,
locales: 'en-US',
calendarDate: new Date(),
calendarTempDate: new Date(),
calendarMode: 'year',
changeCalendarMode: jest.fn(),
onSwipeChange: jest.fn(),
};
const picker = renderIntoDocument();
const calendars = scryRenderedComponentsWithType(picker, DatePickerCalendar);
const years = scryRenderedComponentsWithType(picker, YearPicker);
expect(calendars.length).toBe(0);
expect(years.length).toBe(1);
});
});
it('does not return an icon', () => {
const nonSortableHeader = TestUtils.scryRenderedComponentsWithType(instance, TableHeader)[0];
expect(nonSortableHeader.sortIconHTML).toEqual(null);
});
style={ { width: '50px' } }
/>
);
instanceSortable = TestUtils.renderIntoDocument(
<table>
</table>
);
sortableColumn = TestUtils.findRenderedDOMComponentWithTag(instanceSortable, 'th');
sortableHeader = TestUtils.scryRenderedComponentsWithType(instanceSortable, TableHeader)[0];
});