@@ -3,56 +3,61 @@ import { render, screen } from '@testing-library/react'
33import { ChangeArrow } from './change-arrow'
44
55jest . mock ( '@heroicons/react/24/solid' , ( ) => ( {
6- ArrowUpRightIcon : ( { className } : { className : string } ) => (
7- < span className = { className } > ↑</ span >
6+ ArrowUpRightIcon : ( { className, ...props } : { className : string } ) => (
7+ < span className = { className } { ...props } >
8+ ↑
9+ </ span >
810 ) ,
9- ArrowDownRightIcon : ( { className } : { className : string } ) => (
10- < span className = { className } > ↓</ span >
11+ ArrowDownRightIcon : ( { className, ...props } : { className : string } ) => (
12+ < span className = { className } { ...props } >
13+ ↓
14+ </ span >
1115 )
1216} ) )
1317
14- it ( 'renders green for positive change' , ( ) => {
18+ it ( 'renders up arrow for positive change' , ( ) => {
1519 render ( < ChangeArrow change = { 1 } className = "text-xs" metric = "visitors" /> )
1620
1721 const arrowElement = screen . getByTestId ( 'change-arrow' )
1822
1923 expect ( arrowElement ) . toHaveTextContent ( '↑ 1%' )
20- expect ( arrowElement . children [ 0 ] ) . toHaveClass ( 'text-green-500 ')
24+ expect ( arrowElement . children [ 0 ] ) . toHaveAttribute ( 'data-direction' , 'up ')
2125} )
2226
23- it ( 'renders red for positive change' , ( ) => {
27+ it ( 'renders down arrow for negative change' , ( ) => {
2428 render ( < ChangeArrow change = { - 10 } className = "text-xs" metric = "visitors" /> )
2529
2630 const arrowElement = screen . getByTestId ( 'change-arrow' )
2731
2832 expect ( arrowElement ) . toHaveTextContent ( '↓ 10%' )
29- expect ( arrowElement . children [ 0 ] ) . toHaveClass ( 'text-red-400 ')
33+ expect ( arrowElement . children [ 0 ] ) . toHaveAttribute ( 'data-direction' , 'down ')
3034} )
3135
32- it ( 'renders tilde for no change' , ( ) => {
36+ it ( 'renders no arrow for no change' , ( ) => {
3337 render ( < ChangeArrow change = { 0 } className = "text-xs" metric = "visitors" /> )
3438
3539 const arrowElement = screen . getByTestId ( 'change-arrow' )
3640
3741 expect ( arrowElement ) . toHaveTextContent ( '0%' )
42+ expect ( arrowElement . children ) . toHaveLength ( 0 )
3843} )
3944
40- it ( 'inverts colors for positive bounce_rate change' , ( ) => {
45+ it ( 'inverts arrow direction for positive bounce_rate change' , ( ) => {
4146 render ( < ChangeArrow change = { 15 } className = "text-xs" metric = "bounce_rate" /> )
4247
4348 const arrowElement = screen . getByTestId ( 'change-arrow' )
4449
4550 expect ( arrowElement ) . toHaveTextContent ( '↑ 15%' )
46- expect ( arrowElement . children [ 0 ] ) . toHaveClass ( 'text-red-400 ')
51+ expect ( arrowElement . children [ 0 ] ) . toHaveAttribute ( 'data-direction' , 'up ')
4752} )
4853
49- it ( 'inverts colors for negative bounce_rate change' , ( ) => {
54+ it ( 'inverts arrow direction for negative bounce_rate change' , ( ) => {
5055 render ( < ChangeArrow change = { - 3 } className = "text-xs" metric = "bounce_rate" /> )
5156
5257 const arrowElement = screen . getByTestId ( 'change-arrow' )
5358
5459 expect ( arrowElement ) . toHaveTextContent ( '↓ 3%' )
55- expect ( arrowElement . children [ 0 ] ) . toHaveClass ( 'text-green-500 ')
60+ expect ( arrowElement . children [ 0 ] ) . toHaveAttribute ( 'data-direction' , 'down ')
5661} )
5762
5863it ( 'renders with text hidden' , ( ) => {
@@ -63,7 +68,7 @@ it('renders with text hidden', () => {
6368 const arrowElement = screen . getByTestId ( 'change-arrow' )
6469
6570 expect ( arrowElement ) . toHaveTextContent ( '↓' )
66- expect ( arrowElement . children [ 0 ] ) . toHaveClass ( 'text-red-400 ')
71+ expect ( arrowElement . children [ 0 ] ) . toHaveAttribute ( 'data-direction' , 'down ')
6772} )
6873
6974it ( 'renders no content with text hidden and 0 change' , ( ) => {
0 commit comments