|
| 1 | +import { BooleanPill } from './BooleanPill'; |
| 2 | +import { BooleanPillState } from './BooleanPillState.type'; |
| 3 | +import { render, screen } from '../../tests/render'; |
| 4 | + |
| 5 | +describe('BooleanPill', () => { |
| 6 | + const states: BooleanPillState[] = ['default', 'disabled']; |
| 7 | + const selected = [false, true]; |
| 8 | + const pillPointer = 'boolean-pill'; |
| 9 | + |
| 10 | + it('should render the BooleanPill ', () => { |
| 11 | + render(<BooleanPill text="Value" />); |
| 12 | + const pill = screen.getByTestId(pillPointer); |
| 13 | + expect(pill).toBeInTheDocument(); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should be disabled if disabled state is passed', () => { |
| 17 | + render(<BooleanPill text="Value" state="disabled" />); |
| 18 | + const pill = screen.getByTestId(pillPointer); |
| 19 | + expect(pill).toHaveStyle('pointer-events: none'); |
| 20 | + expect(pill).toHaveStyle('opacity: 0.5'); |
| 21 | + }); |
| 22 | + |
| 23 | + states.forEach((state) => { |
| 24 | + describe(`State: ${state}`, () => { |
| 25 | + it('should render the BooleanPill', () => { |
| 26 | + render(<BooleanPill text="Value" state={state} />); |
| 27 | + const pill = screen.getByTestId(pillPointer); |
| 28 | + expect(pill).toBeInTheDocument(); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should render correct text', () => { |
| 32 | + render(<BooleanPill state={state} text="Hello there!" />); |
| 33 | + const pill = screen.getByTestId(pillPointer); |
| 34 | + expect(pill).toHaveTextContent('Hello there!'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('should not render avatar if avatar prop is not passed', () => { |
| 38 | + render(<BooleanPill text="Value" state={state} />); |
| 39 | + const pill = screen.getByTestId(pillPointer); |
| 40 | + const avatar = screen.queryByTestId('boolean-pill-avatar'); |
| 41 | + expect(pill).toBeInTheDocument(); |
| 42 | + expect(avatar).not.toBeInTheDocument(); |
| 43 | + }); |
| 44 | + |
| 45 | + it('should render avatar if avatar prop is passed', () => { |
| 46 | + render( |
| 47 | + <BooleanPill |
| 48 | + text="Value" |
| 49 | + state={state} |
| 50 | + avatar={{ appearance: 'magenta', initials: 'M' }} |
| 51 | + />, |
| 52 | + ); |
| 53 | + const pill = screen.getByTestId(pillPointer); |
| 54 | + const avatar = screen.getByTestId('boolean-pill-avatar'); |
| 55 | + expect(pill).toBeInTheDocument(); |
| 56 | + expect(avatar).toBeInTheDocument(); |
| 57 | + }); |
| 58 | + |
| 59 | + selected.forEach((isSelected) => { |
| 60 | + describe(`isSelected ${isSelected}`, () => { |
| 61 | + it('should correctly render the checkmark', () => { |
| 62 | + render( |
| 63 | + <BooleanPill |
| 64 | + text="Value" |
| 65 | + state={state} |
| 66 | + isSelected={isSelected} |
| 67 | + />, |
| 68 | + ); |
| 69 | + const pill = screen.getByTestId(pillPointer); |
| 70 | + const checkmark = screen.queryByTestId('boolean-pill-checkmark'); |
| 71 | + expect(pill).toBeInTheDocument(); |
| 72 | + |
| 73 | + if (isSelected) { |
| 74 | + expect(checkmark).toBeInTheDocument(); |
| 75 | + } else { |
| 76 | + expect(checkmark).not.toBeInTheDocument(); |
| 77 | + } |
| 78 | + }); |
| 79 | + }); |
| 80 | + }); |
| 81 | + }); |
| 82 | + }); |
| 83 | +}); |
0 commit comments