Skip to content

Commit 5b1c683

Browse files
committed
Updated unit tests and add new ones and added a comment for button hover
1 parent 5f0d502 commit 5b1c683

4 files changed

Lines changed: 47 additions & 26 deletions

File tree

dotcom-rendering/src/components/CallToActionAtom.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const WithAccentColour = () => {
2525
backgroundImage="https://media.guim.co.uk/2c2ad59a167c43496ff709d0d9a83e8d46c30674/0_0_1300_375/1300.jpg"
2626
text="Proactive security starts here"
2727
buttonText="Explore more"
28-
accentColour="#d71920"
28+
accentColor="#d71920"
2929
/>
3030
);
3131
};

dotcom-rendering/src/components/CallToActionAtom.test.tsx

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,31 @@ import '@testing-library/jest-dom';
33
import { CallToActionAtom } from './CallToActionAtom';
44

55
describe('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
});

dotcom-rendering/src/components/CallToActionAtom.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type CallToActionProps = {
1414
backgroundImage?: string;
1515
text?: string;
1616
buttonText?: string;
17-
accentColour?: string;
17+
accentColor?: string;
1818
};
1919

2020
const overlayMaskGradientStyles = (angle: string, startPosition: number) => {
@@ -117,7 +117,7 @@ export const CallToActionAtom = ({
117117
backgroundImage,
118118
text,
119119
buttonText,
120-
accentColour,
120+
accentColor,
121121
}: CallToActionProps) => {
122122
return (
123123
<picture
@@ -151,18 +151,18 @@ export const CallToActionAtom = ({
151151
icon={<SvgExternal />}
152152
theme={{
153153
// We also still need to implement the dark mode based on the provided designs which should be the same as not providing an accent colour.
154-
textPrimary: accentColour
154+
textPrimary: accentColor
155155
? sourcePalette.neutral[100]
156156
: sourcePalette.neutral[0],
157157
backgroundPrimary:
158-
accentColour ?? sourcePalette.neutral[100],
159-
backgroundPrimaryHover: transparentColour(
160-
accentColour ?? sourcePalette.neutral[100],
161-
0.8,
162-
),
158+
accentColor ?? sourcePalette.neutral[100],
159+
// This should be changed with `calculateHoverColour()` once we have the function available as DCR needs to upgrade Source to 12.1.0 to use it.
160+
// Check https://github.com/guardian/csnx/blob/857116cf826dc700742f14c5a5f005bd6d39f1be/libs/%40guardian/source/CHANGELOG.md?plain=1#L20
161+
backgroundPrimaryHover:
162+
accentColor ?? sourcePalette.neutral[100],
163163
}}
164164
>
165-
{buttonText}
165+
{buttonText ?? 'Learn more'}
166166
</LinkButton>
167167
</div>
168168
</picture>

dotcom-rendering/src/layouts/HostedArticleLayout.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,7 @@ export const HostedArticleLayout = (props: WebProps | AppProps) => {
350350
backgroundImage={cta.image}
351351
text={cta.label}
352352
buttonText={cta.btnText}
353-
accentColour={
354-
branding?.hostedCampaignColour
355-
}
353+
accentColor={branding?.hostedCampaignColour}
356354
/>
357355
</div>
358356
)}

0 commit comments

Comments
 (0)