import * as fc from 'fast-check' import * as Enzyme from 'enzyme' import * as Axe from 'jest-axe' import * as React from 'react' import Select from './Select' import stringify from '../../services/stringify' it('should exist', () => { expect(Select).toBeDefined() }) it('should be a component', () => { expect(Select).toBeComponent() }) it('should render without crashing given required props', () => { expect(() => ) expect(wrapper.find('label')).toHaveLength(1) }) it('should render a select component for choosing values', () => { const wrapper = Enzyme.shallow() expect(wrapper.find('label').find('span')).toHaveLength(1) }) it('should render the label text', () => { fc.assert( fc.property(fc.anything(), (label) => { const wrapper = Enzyme.shallow() const renderedLabel = stringify(label) if (renderedLabel.length > 0) { expect(wrapper.find('div').children()).toHaveLength(5) expect(wrapper.find('div').childAt(3)).toHaveText(`(${renderedLabel})`) } else { expect(wrapper.find('div').children()).toHaveLength(3) } }), ) }) describe('on being declared a block component', () => { const BLOCK_DISPLAYS = ['block', 'grid', 'flex', 'table'] it('should render the base element fullwidth', () => { const wrapper = Enzyme.shallow() expect(wrapper.find('label').find('select')).toHaveStyle('width', '100%') }) it('should render the input as block element', () => { const wrapper = Enzyme.shallow() expect(wrapper.find('div')).toHaveStyle('opacity', 0.5) }) it('should allow selection of multiple values', () => { const wrapper = Enzyme.shallow() const results = await Axe.axe(wrapper.getDOMNode()) expect(results).toHaveNoViolations() }), ) })