@@ -3,21 +3,31 @@ import '@testing-library/jest-dom';
33import { CallToActionAtom } from './CallToActionAtom' ;
44
55describe ( 'CallToActionAtom' , ( ) => {
6- it ( 'should render with url and button text' , ( ) => {
6+ it ( 'should render with url and a default button text when not provided ' , ( ) => {
77 const { getByRole } = render (
88 < CallToActionAtom
99 linkUrl = "https://example.com"
1010 backgroundImage = "https://example.com/image.jpg"
11- buttonText = "Click here"
1211 /> ,
1312 ) ;
1413
15- const link = getByRole ( 'link' ) ;
14+ const link = getByRole ( 'link' , { name : 'Learn more' } ) ;
1615 expect ( link ) . toBeInTheDocument ( ) ;
1716 expect ( link ) . toHaveAttribute ( 'href' , 'https://example.com' ) ;
17+ } ) ;
18+
19+ it ( 'should display custom button text when provided' , ( ) => {
20+ const { getByRole } = render (
21+ < CallToActionAtom
22+ linkUrl = "https://example.com"
23+ backgroundImage = "https://example.com/image.jpg"
24+ buttonText = "Click here"
25+ /> ,
26+ ) ;
1827
19- const button = getByRole ( 'button' , { name : 'Click here' } ) ;
20- expect ( button ) . toBeInTheDocument ( ) ;
28+ const link = getByRole ( 'link' , { name : 'Click here' } ) ;
29+ expect ( link ) . toBeInTheDocument ( ) ;
30+ expect ( link ) . toHaveAttribute ( 'href' , 'https://example.com' ) ;
2131 } ) ;
2232
2333 it ( 'should display the label when provided' , ( ) => {
@@ -47,21 +57,34 @@ describe('CallToActionAtom', () => {
4757 expect ( heading ) . not . toBeInTheDocument ( ) ;
4858 } ) ;
4959
50- it ( 'should have correct link wrapping the entire component ' , ( ) => {
60+ it ( 'should apply the accent colour to the button when provided ' , ( ) => {
5161 const { getByRole } = render (
5262 < CallToActionAtom
5363 linkUrl = "https://example.com"
54- buttonText = "Learn more"
55- text = "Important Info"
5664 backgroundImage = "https://example.com/image.jpg"
65+ buttonText = "Click here"
66+ accentColor = "#d71920"
5767 /> ,
5868 ) ;
5969
60- const link = getByRole ( 'link' ) ;
61- expect ( link ) . toHaveAttribute ( 'href' , 'https://example.com' ) ;
70+ const link = getByRole ( 'link' , { name : 'Click here' } ) ;
71+ const computedStyle = window . getComputedStyle ( link ) ;
72+ expect ( computedStyle . color ) . toBe ( 'rgb(255, 255, 255)' ) ;
73+ expect ( computedStyle . backgroundColor ) . toBe ( 'rgb(215, 25, 32)' ) ;
74+ } ) ;
75+
76+ it ( 'should apply the default theme to the button when no accent colour is provided' , ( ) => {
77+ const { getByRole } = render (
78+ < CallToActionAtom
79+ linkUrl = "https://example.com"
80+ backgroundImage = "https://example.com/image.jpg"
81+ buttonText = "Click here"
82+ /> ,
83+ ) ;
6284
63- // Check that the button is within the link
64- const button = getByRole ( 'button' , { name : 'Learn more' } ) ;
65- expect ( link ) . toContainElement ( button ) ;
85+ const link = getByRole ( 'link' , { name : 'Click here' } ) ;
86+ const computedStyle = window . getComputedStyle ( link ) ;
87+ expect ( computedStyle . color ) . toBe ( 'rgb(0, 0, 0)' ) ;
88+ expect ( computedStyle . backgroundColor ) . toBe ( 'rgb(255, 255, 255)' ) ;
6689 } ) ;
6790} ) ;
0 commit comments