import * as React from 'react' import renderer from 'react-test-renderer' import { shallow } from 'enzyme' import { Text, TextTagType } from './Text' const multipleLineText = `line1 line2 line3` describe('Text', () => { it('should have change the DOM', () => { const text = renderer.create(text).toJSON() expect(text).toMatchSnapshot() }) it('Should have the custom class', () => { const wrapper = shallow(test) expect(wrapper.hasClass('testClass')).toBe(true) }) it('Should render with the default span tag', () => { const wrapper = shallow(test) expect(wrapper.name()).toBe('span') }) it('Should render with the div tag', () => { const wrapper = shallow(test) expect(wrapper.name()).toBe('div') }) it('Should have role attribute when present and undefined otherwise', () => { const wrapper = shallow(test) expect(wrapper.prop('role')).toBeUndefined() wrapper.setProps({ role: 'alert' }) expect(wrapper.prop('role')).toBe('alert') }) it('Should have aria-label attribute when present and undefined otherwise', () => { const wrapper = shallow(test) expect(wrapper.prop('aria-label')).toBeUndefined() wrapper.setProps({ 'aria-label': 'Complementary description' }) expect(wrapper.prop('aria-label')).toBe('Complementary description') }) it('Should accept ReactNode as children', () => { const wrapper = shallow( test , ) expect(wrapper.children().first().name()).toBe('span') }) it('Should replace \\n with br tags by default', () => { const wrapper = shallow({multipleLineText}) expect(wrapper.html()).toContain( 'line1
line2
line3
', ) }) it('Should not replace \\n with br tags when newlineToBr is false', () => { const wrapper = shallow({multipleLineText}) expect(wrapper.html()).toContain( `${multipleLineText}`, ) }) it('Should display the text with color', () => { const wrapper = shallow(test) expect(wrapper.prop('style')).toEqual({ color: '#FFFFFF' }) }) it('Should not display the text with color when color not hexa', () => { const wrapper = shallow(test) expect(wrapper.prop('style')).toBeUndefined() }) })