11import React from 'react' ;
22import CardImage from './CardImage' ;
3- import { CardType , CardStatus } from '../../types' ;
3+ import { CardType } from '../../types' ;
44import { renderScreen } from '../../../../../util/test/renderWithProvider' ;
55import { backgroundState } from '../../../../../util/test/initial-root-state' ;
66
7- jest . mock ( '../../util/truncateAddress' , ( ) => ( {
8- truncateAddress : jest . fn (
9- ( address : string ) => `${ address . slice ( 0 , 6 ) } ...${ address . slice ( - 4 ) } ` ,
10- ) ,
11- } ) ) ;
12-
137function renderWithProvider ( component : React . ComponentType ) {
148 return renderScreen (
159 component ,
@@ -27,144 +21,57 @@ function renderWithProvider(component: React.ComponentType) {
2721}
2822
2923describe ( 'CardImage Component' , ( ) => {
30- it ( 'renders virtual card image for VIRTUAL type' , ( ) => {
31- const { getByTestId } = renderWithProvider ( ( ) => (
32- < CardImage
33- type = { CardType . VIRTUAL }
34- status = { CardStatus . ACTIVE }
35- testID = "virtual-card-image"
36- />
37- ) ) ;
38-
39- expect ( getByTestId ( 'virtual-card-image' ) ) . toBeOnTheScreen ( ) ;
40- } ) ;
41-
42- it ( 'renders metal card image for PHYSICAL type' , ( ) => {
43- const { getByTestId } = renderWithProvider ( ( ) => (
44- < CardImage
45- type = { CardType . PHYSICAL }
46- status = { CardStatus . ACTIVE }
47- testID = "physical-card-image"
48- />
49- ) ) ;
50-
51- expect ( getByTestId ( 'physical-card-image' ) ) . toBeOnTheScreen ( ) ;
52- } ) ;
53-
54- it ( 'renders metal card image for METAL type' , ( ) => {
55- const { getByTestId } = renderWithProvider ( ( ) => (
56- < CardImage
57- type = { CardType . METAL }
58- status = { CardStatus . ACTIVE }
59- testID = "metal-card-image"
60- />
61- ) ) ;
62-
63- expect ( getByTestId ( 'metal-card-image' ) ) . toBeOnTheScreen ( ) ;
64- } ) ;
65-
66- it ( 'applies lower opacity when status is FROZEN' , ( ) => {
67- const { getByTestId } = renderWithProvider ( ( ) => (
68- < CardImage
69- type = { CardType . VIRTUAL }
70- status = { CardStatus . FROZEN }
71- testID = "frozen-card"
72- />
73- ) ) ;
74-
75- expect ( getByTestId ( 'frozen-card' ) ) . toBeOnTheScreen ( ) ;
76- } ) ;
77-
78- it ( 'applies lower opacity when status is BLOCKED' , ( ) => {
79- const { getByTestId } = renderWithProvider ( ( ) => (
80- < CardImage
81- type = { CardType . VIRTUAL }
82- status = { CardStatus . BLOCKED }
83- testID = "blocked-card"
84- />
24+ it ( 'renders virtual card image when type is VIRTUAL' , ( ) => {
25+ const { toJSON, getByTestId } = renderWithProvider ( ( ) => (
26+ < CardImage type = { CardType . VIRTUAL } testID = "virtual-card-image" />
8527 ) ) ;
8628
87- expect ( getByTestId ( 'blocked-card' ) ) . toBeOnTheScreen ( ) ;
29+ expect ( getByTestId ( 'virtual-card-image' ) ) . toBeDefined ( ) ;
30+ expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
8831 } ) ;
8932
90- it ( 'renders with full opacity when status is ACTIVE' , ( ) => {
91- const { getByTestId } = renderWithProvider ( ( ) => (
92- < CardImage
93- type = { CardType . VIRTUAL }
94- status = { CardStatus . ACTIVE }
95- testID = "active-card"
96- />
33+ it ( 'renders metal card image when type is PHYSICAL' , ( ) => {
34+ const { toJSON, getByTestId } = renderWithProvider ( ( ) => (
35+ < CardImage type = { CardType . PHYSICAL } testID = "physical-card-image" />
9736 ) ) ;
9837
99- expect ( getByTestId ( 'active-card' ) ) . toBeOnTheScreen ( ) ;
38+ expect ( getByTestId ( 'physical-card-image' ) ) . toBeDefined ( ) ;
39+ expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
10040 } ) ;
10141
102- it ( 'renders with truncated address when address prop provided' , ( ) => {
103- const { getByTestId } = renderWithProvider ( ( ) => (
104- < CardImage
105- type = { CardType . VIRTUAL }
106- status = { CardStatus . ACTIVE }
107- address = "0x1234567890123456789012345678901234567890"
108- testID = "card-with-address"
109- />
42+ it ( 'renders metal card image when type is METAL' , ( ) => {
43+ const { toJSON, getByTestId } = renderWithProvider ( ( ) => (
44+ < CardImage type = { CardType . METAL } testID = "metal-card-image" />
11045 ) ) ;
11146
112- expect ( getByTestId ( 'card-with-address' ) ) . toBeOnTheScreen ( ) ;
47+ expect ( getByTestId ( 'metal-card-image' ) ) . toBeDefined ( ) ;
48+ expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
11349 } ) ;
11450
115- it ( 'renders without address when address prop not provided ' , ( ) => {
116- const { getByTestId } = renderWithProvider ( ( ) => (
51+ it ( 'renders with custom SVG properties ' , ( ) => {
52+ const { toJSON } = renderWithProvider ( ( ) => (
11753 < CardImage
11854 type = { CardType . VIRTUAL }
119- status = { CardStatus . ACTIVE }
120- testID = "card-without-address"
55+ width = { 200 }
56+ height = { 100 }
57+ fill = "red"
58+ stroke = "blue"
59+ opacity = { 0.5 }
60+ testID = "custom-card-image"
12161 />
12262 ) ) ;
12363
124- expect ( getByTestId ( 'card-without-address' ) ) . toBeOnTheScreen ( ) ;
64+ expect ( toJSON ( ) ) . toMatchSnapshot ( ) ;
12565 } ) ;
12666
12767 it . each ( [ CardType . VIRTUAL , CardType . PHYSICAL , CardType . METAL ] as const ) (
128- 'renders %s card type with ACTIVE status ' ,
68+ 'renders %s card type without errors ' ,
12969 ( cardType ) => {
130- const { getByTestId } = renderWithProvider ( ( ) => (
131- < CardImage
132- type = { cardType }
133- status = { CardStatus . ACTIVE }
134- testID = { `${ cardType } -card` }
135- />
136- ) ) ;
137-
138- expect ( getByTestId ( `${ cardType } -card` ) ) . toBeOnTheScreen ( ) ;
139- } ,
140- ) ;
141-
142- it . each ( [ CardStatus . ACTIVE , CardStatus . FROZEN , CardStatus . BLOCKED ] as const ) (
143- 'renders VIRTUAL card with %s status' ,
144- ( status ) => {
145- const { getByTestId } = renderWithProvider ( ( ) => (
146- < CardImage
147- type = { CardType . VIRTUAL }
148- status = { status }
149- testID = { `card-${ status } ` }
150- />
70+ const { toJSON } = renderWithProvider ( ( ) => (
71+ < CardImage type = { cardType } />
15172 ) ) ;
15273
153- expect ( getByTestId ( `card- ${ status } ` ) ) . toBeOnTheScreen ( ) ;
74+ expect ( toJSON ( ) ) . toBeDefined ( ) ;
15475 } ,
15576 ) ;
156-
157- it ( 'renders with custom SVG properties' , ( ) => {
158- const { getByTestId } = renderWithProvider ( ( ) => (
159- < CardImage
160- type = { CardType . VIRTUAL }
161- status = { CardStatus . ACTIVE }
162- width = { 200 }
163- height = { 100 }
164- testID = "custom-card-image"
165- />
166- ) ) ;
167-
168- expect ( getByTestId ( 'custom-card-image' ) ) . toBeOnTheScreen ( ) ;
169- } ) ;
17077} ) ;
0 commit comments