Skip to content

Loop Video: interaction stories #14232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 79 additions & 5 deletions dotcom-rendering/src/components/LoopVideo.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { breakpoints } from '@guardian/source/foundations';
import type { Meta, StoryObj } from '@storybook/react';
import { expect, userEvent, within } from '@storybook/test';
import { centreColumnDecorator } from '../../.storybook/decorators/gridDecorators';
import { LoopVideo } from './LoopVideo.importable';

export default {
const meta = {
component: LoopVideo,
title: 'Components/LoopVideo',
decorators: [centreColumnDecorator],
Expand All @@ -15,7 +16,10 @@ export default {
},
} satisfies Meta<typeof LoopVideo>;

export const Default = {
export default meta;
type Story = StoryObj<typeof LoopVideo>;

export const Default: Story = {
name: 'Default',
args: {
src: 'https://uploads.guim.co.uk/2025%2F06%2F20%2Ftesting+only%2C+please+ignore--3cb22b60-2c3f-48d6-8bce-38c956907cce-3.mp4',
Expand All @@ -26,14 +30,84 @@ export const Default = {
image: 'https://media.guim.co.uk/9bdb802e6da5d3fd249b5060f367b3a817965f0c/0_0_1800_1080/master/1800.jpg',
fallbackImage: '',
},
} satisfies StoryObj<typeof LoopVideo>;
};

export const Without5to4Ratio = {
export const Without5to4Ratio: Story = {
name: 'Without 5:4 aspect ratio',
args: {
...Default.args,
src: 'https://uploads.guim.co.uk/2024/10/01/241001HeleneLoop_2.mp4',
height: 1080,
width: 1920,
},
} satisfies StoryObj<typeof LoopVideo>;
};

export const PausePlay: Story = {
...Default,
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const videoEl = canvas.getByTestId('loop-video');

await userEvent.click(videoEl, {
delay: 300, // Allow video to start playing.
});
await canvas.findByTestId('play-icon');

const progressBar = await canvas.findByRole('progressbar');
await expect(Number(progressBar.ariaValueNow)).toBeGreaterThan(0);

// Play Video
await userEvent.click(videoEl);
await expect(canvas.queryByTestId('play-icon')).not.toBeInTheDocument();
},
};

export const UnmuteMute: Story = {
...Default,
parameters: {
test: {
// The following error is received without this flag: "TypeError: ophan.trackClickComponentEvent is not a function"
dangerouslyIgnoreUnhandledErrors: true,
},
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);

await canvas.findByTestId('unmute-icon');

await userEvent.click(canvas.getByTestId('unmute-icon'));
await canvas.findByTestId('mute-icon');

await userEvent.click(canvas.getByTestId('mute-icon'));
await canvas.findByTestId('unmute-icon');
},
};

// Function to emulate pausing between interactions
function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms));
}

export const InteractionObserver: Story = {
...Default,
render: (args) => (
<div data-testid="test-container">
<LoopVideo {...args} />
<div style={{ height: '100vh' }}></div>
<p data-testid="page-end">End of page</p>
</div>
),
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);

await sleep(500); // Allow enough time for the autoplay video to start.
canvas.getByTestId('page-end').scrollIntoView();

const progressBar = await canvas.findByRole('progressbar');
const progress = Number(progressBar.ariaValueNow);

await sleep(500); // Allow enough time to be confident that the video is paused.
await expect(Number(progressBar.ariaValueNow)).toEqual(progress);
await expect(canvas.queryByTestId('play-icon')).not.toBeInTheDocument();
},
};
10 changes: 8 additions & 2 deletions dotcom-rendering/src/components/LoopVideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ export const LoopVideoPlayer = forwardRef(
id={loopVideoId}
css={videoStyles(width, height)}
ref={ref}
role="button"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially added this as the video has click functionality - it pauses and plays the video. However, I think setting the role to button is more unhelpful than helpful to a user, given that the primary function of the video is not a button.

tabIndex={0}
data-testid="loop-video"
height={height}
width={width}
data-link-name={`gu-video-loop-${
Expand Down Expand Up @@ -180,6 +180,7 @@ export const LoopVideoPlayer = forwardRef(
onClick={handlePlayPauseClick}
css={playIconStyles}
data-link-name={`gu-video-loop-play-${atomId}`}
data-testid="play-icon"
>
<PlayIcon iconWidth="narrow" />
</button>
Expand All @@ -199,7 +200,12 @@ export const LoopVideoPlayer = forwardRef(
isMuted ? 'unmute' : 'mute'
}-${atomId}`}
>
<div css={audioIconContainerStyles}>
<div
css={audioIconContainerStyles}
data-testId={`${
isMuted ? 'unmute' : 'mute'
}-icon`}
>
<AudioIcon
size="xsmall"
theme={{
Expand Down