Skip to content

Commit ff53da0

Browse files
add interactions to storybook
1 parent 9b6995a commit ff53da0

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

dotcom-rendering/src/components/CarouselNavigationButtons.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export const CarouselNavigationButtons = ({
101101
}
102102
size="small"
103103
disabled={!previousButtonEnabled}
104+
data-testid="carousel-back-button"
104105
aria-label="previous"
105106
value="previous"
106107
data-link-name={dataLinkNamePreviousButton}
@@ -109,6 +110,7 @@ export const CarouselNavigationButtons = ({
109110
<Button
110111
hideLabel={true}
111112
iconSide="left"
113+
data-testid="carousel-forward-button"
112114
icon={<SvgChevronRightSingle />}
113115
onClick={onClickNextButton}
114116
priority="tertiary"

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

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ArticleDesign, ArticleDisplay, Pillar } from '../lib/articleFormat';
66
import { ScrollableProduct } from './ScrollableProduct.importable';
77

88
const meta = {
9-
title: 'Article Carousel/Scrollable Products',
9+
title: 'Components/Scrollable Products',
1010
component: ScrollableProduct,
1111
parameters: {
1212
chromatic: {
@@ -19,15 +19,32 @@ const meta = {
1919
},
2020
args: {
2121
products: [
22-
{ ...exampleProduct, h2Id: 'product' },
2322
{
2423
...exampleProduct,
24+
primaryHeadingHtml: '<em>Product 0</em>',
25+
h2Id: 'product',
26+
},
27+
{
28+
...exampleProduct,
29+
primaryHeadingHtml: '<em>Product 1</em>',
2530
h2Id: 'product-1',
2631
productName: 'Lorem ipsum dolor sit amet',
2732
},
28-
{ ...exampleProduct, h2Id: 'product-2' },
29-
{ ...exampleProduct, h2Id: 'product-3' },
30-
{ ...exampleProduct, h2Id: 'product-4' },
33+
{
34+
...exampleProduct,
35+
primaryHeadingHtml: '<em>Product 2</em>',
36+
h2Id: 'product-2',
37+
},
38+
{
39+
...exampleProduct,
40+
primaryHeadingHtml: '<em>Product 3</em>',
41+
h2Id: 'product-3',
42+
},
43+
{
44+
...exampleProduct,
45+
primaryHeadingHtml: '<em>Product 4</em>',
46+
h2Id: 'product-4',
47+
},
3148
],
3249
format: {
3350
design: ArticleDesign.Review,
@@ -78,3 +95,24 @@ export default meta;
7895
type Story = StoryObj<typeof meta>;
7996

8097
export const With5Cards = {} satisfies Story;
98+
99+
export const ClickForwardArrow = {
100+
play: async ({ canvas, userEvent }) => {
101+
await userEvent.click(canvas.getByTestId('carousel-forward-button'));
102+
},
103+
} satisfies Story;
104+
105+
// Function to emulate pausing between interactions
106+
function sleep(ms: number) {
107+
return new Promise((resolve) => setTimeout(resolve, ms));
108+
}
109+
110+
export const ClickForwardTwiceAndBackOnce = {
111+
play: async ({ canvas, userEvent }) => {
112+
await userEvent.click(canvas.getByTestId('carousel-forward-button'));
113+
await sleep(500);
114+
await userEvent.click(canvas.getByTestId('carousel-forward-button'));
115+
await sleep(500);
116+
await userEvent.click(canvas.getByTestId('carousel-back-button'));
117+
},
118+
} satisfies Story;

0 commit comments

Comments
 (0)