|
6 | 6 | */ |
7 | 7 |
|
8 | 8 | import React from 'react'; |
9 | | -import { render } from 'garden-test-utils'; |
| 9 | +import { render, getRenderFn } from 'garden-test-utils'; |
10 | 10 | import { PALETTE } from '@zendeskgarden/react-theming'; |
11 | 11 | import { StyledBase } from './StyledBase'; |
| 12 | +import { Type } from '../types'; |
12 | 13 |
|
13 | 14 | describe('StyledBase', () => { |
14 | | - it('should renders the correct background, border, and foreground color for a given type', () => { |
15 | | - const { container } = render(<StyledBase $type="success" />); |
| 15 | + it.each<{ mode: 'light' | 'dark'; type: Type; color: string }>([ |
| 16 | + { mode: 'light', type: 'success', color: PALETTE.green[100] }, |
| 17 | + { mode: 'dark', type: 'success', color: PALETTE.green[1000] }, |
| 18 | + { mode: 'light', type: 'error', color: PALETTE.red[100] }, |
| 19 | + { mode: 'dark', type: 'error', color: PALETTE.red[1000] }, |
| 20 | + { mode: 'light', type: 'warning', color: PALETTE.yellow[100] }, |
| 21 | + { mode: 'dark', type: 'warning', color: PALETTE.yellow[1000] }, |
| 22 | + { mode: 'light', type: 'info', color: PALETTE.grey[100] }, |
| 23 | + { mode: 'dark', type: 'info', color: PALETTE.grey[1000] } |
| 24 | + ])('renders $mode mode $type background colors', ({ mode, type, color }) => { |
| 25 | + const { container } = getRenderFn(mode)(<StyledBase $type={type} />); |
16 | 26 |
|
17 | | - expect(container.firstChild).toHaveStyleRule('color', PALETTE.green[700]); |
18 | | - expect(container.firstChild).toHaveStyleRule('border-color', PALETTE.green[300]); |
19 | | - expect(container.firstChild).toHaveStyleRule('background-color', PALETTE.green[100]); |
| 27 | + expect(container.firstChild).toHaveStyleRule('background-color', color); |
| 28 | + }); |
| 29 | + |
| 30 | + it.each<{ mode: 'light' | 'dark'; type: Type; color: string }>([ |
| 31 | + { mode: 'light', type: 'success', color: PALETTE.green[300] }, |
| 32 | + { mode: 'dark', type: 'success', color: PALETTE.green[800] }, |
| 33 | + { mode: 'light', type: 'error', color: PALETTE.red[300] }, |
| 34 | + { mode: 'dark', type: 'error', color: PALETTE.red[800] }, |
| 35 | + { mode: 'light', type: 'warning', color: PALETTE.yellow[300] }, |
| 36 | + { mode: 'dark', type: 'warning', color: PALETTE.yellow[800] }, |
| 37 | + { mode: 'light', type: 'info', color: PALETTE.grey[300] }, |
| 38 | + { mode: 'dark', type: 'info', color: PALETTE.grey[800] } |
| 39 | + ])('renders $mode mode $type border colors', ({ mode, type, color }) => { |
| 40 | + const { container } = getRenderFn(mode)(<StyledBase $type={type} />); |
| 41 | + |
| 42 | + expect(container.firstChild).toHaveStyleRule('border-color', color); |
| 43 | + }); |
| 44 | + |
| 45 | + it.each<{ mode: 'light' | 'dark'; type: Type; color: string }>([ |
| 46 | + { mode: 'light', type: 'success', color: PALETTE.green[700] }, |
| 47 | + { mode: 'dark', type: 'success', color: PALETTE.green[400] }, |
| 48 | + { mode: 'light', type: 'error', color: PALETTE.red[700] }, |
| 49 | + { mode: 'dark', type: 'error', color: PALETTE.red[400] }, |
| 50 | + { mode: 'light', type: 'warning', color: PALETTE.yellow[700] }, |
| 51 | + { mode: 'dark', type: 'warning', color: PALETTE.yellow[400] }, |
| 52 | + { mode: 'light', type: 'info', color: PALETTE.grey[700] }, |
| 53 | + { mode: 'dark', type: 'info', color: PALETTE.grey[500] } |
| 54 | + ])('renders $mode mode $type foreground colors', ({ mode, type, color }) => { |
| 55 | + const { container } = getRenderFn(mode)(<StyledBase $type={type} />); |
| 56 | + |
| 57 | + expect(container.firstChild).toHaveStyleRule('color', color); |
20 | 58 | }); |
21 | 59 |
|
22 | 60 | it('renders neutral colors given no type', () => { |
|
0 commit comments