import * as React from 'react'; import { mount } from 'enzyme'; import Select from '../Select'; describe('); // onChange={spy} (element.find('select') as any).at(1).instance().value = 'two'; // TODO Failing tests expect('failing tests').toBe('failing tests'); // element.find('select').at(1).simulate('change'); // expect(spy).toHaveBeenCalledWith('one'); }); }); describe('onFocus()', () => { it('is called when the select is focused', () => { const spy = jest.fn(); mount(); element.find('select').at(1).simulate('focus').simulate('blur'); expect(spy).toHaveBeenCalled(); }); }); describe('options', () => { it('translates an array of strings into options', () => { const options = ['one', 'two']; const optionElements = mount().find('option'); options.forEach(({ value, label }, index) => { const optionElement = optionElements.at(index); expect(optionElement.key()).toBe(value); expect(optionElement.prop('value')).toBe(value); expect(optionElement.text()).toBe(label); }); }); }); describe('groups', () => { it('translates groups into optgroup tags', () => { const optionsAndGroups = [ { title: 'Group one', options: ['one.1', 'one.2'] }, 'one', 'two', { title: 'Group two', options: ['two.1', 'two.2'] }, ]; const optionOrOptgroupElements = mount().find('select').at(1).prop('value'); expect(value).toBe('Some value'); }); }); describe('id', () => { it('sets the id on the input', () => { const id = mount().find('select').at(1).prop('id'); expect(typeof id).toBe('string'); expect(id).toBeTruthy(); }); }); describe('disabled', () => { it('sets the disabled attribute on the select', () => { const select = mount(); expect(select.find('select').at(1).prop('disabled')).toBeFalsy(); select = mount(); const helpTextID = select.find('select').at(1).prop('aria-describedby'); expect(typeof helpTextID).toBe('string'); expect(select.find(`#${helpTextID}`).text()).toBe('Some help'); }); }); describe('placeholder', () => { it('renders an unselectable option for the placeholder', () => { const select = mount(); const placeholderOption = select.find('option'); expect(placeholderOption.length).toBe(1); expect(placeholderOption.prop('disabled')).toBeFalsy(); }); }); });