/* eslint-disable react/button-has-type */ import React from 'react' import renderer from 'react-test-renderer' import { mount, shallow } from 'enzyme' import { render, screen } from '@testing-library/react' import { Button } from '../../button' import { ChevronIcon } from '../../icon/chevronIcon' import { ClockIcon } from '../../icon/clockIcon' import { Text } from '../../text' import { Item as StyledItem } from './index' import { Item } from './Item' describe('Item', () => { it('Should not have changed', () => { const item = renderer .create( } />, ) .toJSON() expect(item).toMatchSnapshot() }) it('Should be displayed in default state without props', () => { const wrapper = shallow() expect(wrapper.hasClass('kirk-item')).toBe(true) expect(wrapper.type()).toBe('div') }) it('Should accept a custom `className`', () => { const customClassName = 'custom' const wrapper = shallow() expect(wrapper.hasClass(customClassName)).toBe(true) }) it('Should be highlighted', () => { const wrapper = shallow() expect(wrapper.hasClass('kirk-item--highlighted')).toBe(true) }) it("Shouldn't be wrappable by default", () => { render(} />) expect(screen.getByRole('button', { name: 'Test' })).not.toHaveClass('kirk-item--wrappable') }) it('Should be wrappable', () => { render(} isWrappable />) expect(screen.getByRole('button', { name: 'Test' })).toHaveClass('kirk-item--wrappable') }) it('Should deactivate background hover color properly', () => { const wrapperWithHoverBackground = shallow() expect(wrapperWithHoverBackground.hasClass('kirk-item--hideHoverBackground')).toBe(false) const wrapperWithoutHoverBackground = shallow() expect(wrapperWithoutHoverBackground.hasClass('kirk-item--hideHoverBackground')).toBe(true) }) it('Should trigger click on button info', () => { const onButtonClick = jest.fn() const wrapper = mount( More info} />, ) wrapper.find('.kirk-item-title--withButtonAddon button').simulate('click') expect(onButtonClick).toHaveBeenCalledTimes(1) }) it('Should use correct button type for normal buttons', () => { const wrapper = mount(} />) expect(wrapper.find('button[type="button"]').exists()).toBe(true) }) it('Should not add type=button to anchors', () => { // The Item uses a } />, ) expect(wrapper.find('.kirk-item-title--withButtonAddon button').exists()).toBe(false) }) it("Should't display left button addon if Item is clickable", () => { const wrapper = mount( } leftTitle="Left title" leftTitleButtonAddon={} />, ) expect(wrapper.find('.kirk-item-title--withButtonAddon button').exists()).toBe(false) }) it('Should accept a custom `tag`', () => { const wrapper = shallow(} />) expect(wrapper.type()).toBe('li') }) it('Should not return an href prop when no href is pass to the item', () => { const wrapper = shallow() expect(wrapper.prop('href')).toBeUndefined() }) it('Should return a tag A when href is a string', () => { const wrapper = shallow() expect(wrapper.type()).toBe('a') expect(wrapper.prop('href')).toBe('#') }) it('Should return a tag of a with its href when href is a component a', () => { const wrapper = shallow(} />) expect(wrapper.type()).toEqual('a') expect(wrapper.prop('href')).toEqual('#') }) it('Should return a tag without extra attribrutes when href is a string', () => { const wrapper = shallow(} />) expect(wrapper.type()).toEqual('a') expect(wrapper.prop('type')).toBe(undefined) }) it('Should display a left add-on', () => { const wrapper = shallow(} />) expect(wrapper.find(ClockIcon).exists()).toBe(true) }) it('Should display a right add-on', () => { const wrapper = shallow(} />) expect(wrapper.find(ClockIcon).exists()).toBe(true) }) it('Should display a chevron', () => { const wrapper = shallow() expect(wrapper.find(ChevronIcon).exists()).toBe(true) }) it('Should display left body annotation', () => { const wrapper = mount() expect(wrapper.find('.kirk-item-body-annotation').exists()).toBe(true) }) it('Should display left body', () => { const wrapper = mount() expect(wrapper.find('.kirk-item-body').exists()).toBe(true) }) it('Should display strickthrough right title', () => { const wrapper = mount() expect(wrapper.find('.kirk-item--strikethrough').exists()).toBe(true) }) it("Shouldn't display strickthrough right title", () => { const wrapper = mount() expect(wrapper.find('.kirk-item--strikethrough').exists()).toBe(false) }) it('Should display aria-label on right title', () => { const wrapper = mount( , ) expect(wrapper.find(Text).prop('aria-label')).toBe('Right title aria-label') }) })