Skip to content

Commit 94b6955

Browse files
authored
Merge pull request #15137 from ethereum/story-listen-to
Fix listen-to story
2 parents 602edc0 + bc0c01d commit 94b6955

File tree

3 files changed

+50
-51
lines changed

3 files changed

+50
-51
lines changed
Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,42 @@
11
import type { Meta, StoryObj } from "@storybook/react"
2+
import { expect } from "@storybook/test"
3+
import { waitFor } from "@storybook/test"
4+
import { fireEvent } from "@storybook/test"
5+
import { within } from "@storybook/test"
26

3-
import { langViewportModes } from "../../../.storybook/modes"
4-
import { BaseLayout as BaseLayoutComponent } from "../../layouts/BaseLayout"
5-
6-
import ListenToPlayer from "."
7+
import Component from "."
78

89
const meta = {
9-
title: "Atoms / Media & Icons / ListenToPlayer / ListenToPlayer",
10-
component: BaseLayoutComponent,
11-
parameters: {
12-
layout: "fullscreen",
13-
chromatic: {
14-
modes: {
15-
...langViewportModes,
16-
},
17-
},
18-
},
19-
argTypes: {
20-
children: {
21-
table: {
22-
disable: true,
23-
},
24-
},
25-
lastDeployLocaleTimestamp: {
26-
table: {
27-
disable: true,
28-
},
29-
},
10+
title: "Atoms / Media & Icons / ListenToPlayer",
11+
component: Component,
12+
args: {
13+
slug: "/eth/",
3014
},
31-
} satisfies Meta<typeof BaseLayoutComponent>
15+
} satisfies Meta<typeof Component>
3216

3317
export default meta
3418

35-
export const BaseLayout: StoryObj<typeof meta> = {
36-
args: {
37-
children: (
38-
<div className="flex w-full flex-col items-center gap-4 px-8 py-9 md:flex-row">
39-
<ListenToPlayer slug="/eth" />
40-
</div>
41-
),
42-
// contentIsOutdated: false,
43-
// contentNotTranslated: false,
44-
lastDeployLocaleTimestamp: "May 14, 2021",
19+
type Story = StoryObj<typeof meta>
20+
21+
export const PlayerButton: Story = {}
22+
23+
export const PlayerWidget: Story = {
24+
play: async ({ canvasElement }) => {
25+
const canvas = within(canvasElement)
26+
const canvasParent = within(canvasElement.parentElement!)
27+
28+
const playerButton = canvas.getByRole("button")
29+
await waitFor(() => {
30+
// TODO: hacky way to wait for the sound to be loaded
31+
expect(playerButton.textContent).not.toContain("0 min")
32+
})
33+
34+
fireEvent.click(playerButton)
35+
36+
await waitFor(async () => {
37+
await expect(
38+
canvasParent.getByTestId("player-widget-modal")
39+
).toBeVisible()
40+
})
4541
},
4642
}

src/components/ListenToPlayer/TopOfPagePlayer/index.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { PauseCircleIcon, PlayCircleIcon } from "@/components/icons/listen-to"
2+
import { Button } from "@/components/ui/buttons/Button"
23

34
import { trackCustomEvent } from "@/lib/utils/matomo"
45

@@ -18,20 +19,21 @@ const TopOfPagePlayer = ({
1819
handlePlayPause,
1920
}: TopOfPagePlayerProps) => {
2021
return (
21-
<div className="inline-block w-full rounded-lg bg-background-low p-2 hover:bg-background-medium lg:w-auto">
22-
<div
23-
className="flex cursor-pointer flex-row items-center gap-2 text-primary hover:text-primary-hover"
24-
onClick={() => {
25-
if (startedPlaying) {
26-
trackCustomEvent({
27-
eventCategory: "Audio",
28-
eventAction: "click",
29-
eventName: "start",
30-
})
31-
}
32-
handlePlayPause()
33-
}}
34-
>
22+
<Button
23+
variant="ghost"
24+
className="inline-block w-full rounded-lg bg-background-low p-2 hover:bg-background-medium lg:w-auto"
25+
onClick={() => {
26+
if (startedPlaying) {
27+
trackCustomEvent({
28+
eventCategory: "Audio",
29+
eventAction: "click",
30+
eventName: "start",
31+
})
32+
}
33+
handlePlayPause()
34+
}}
35+
>
36+
<div className="flex flex-row items-center gap-2 text-primary hover:text-primary-hover">
3537
{startedPlaying ? (
3638
isPlaying ? (
3739
<PauseCircleIcon className="h-6 w-6 transition-transform" />
@@ -52,7 +54,7 @@ const TopOfPagePlayer = ({
5254
)}
5355
</div>
5456
</div>
55-
</div>
57+
</Button>
5658
)
5759
}
5860

src/components/ListenToPlayer/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ const ListenToPlayer = ({ slug }: { slug: string }) => {
225225
isExpanded ? "bottom-4" : "bottom-0",
226226
"fixed left-1/2 right-auto z-10 -translate-x-1/2 sm:left-auto sm:right-5 sm:translate-x-0"
227227
)}
228+
data-testid="player-widget-modal"
228229
>
229230
<div className="relative">
230231
<PlayerWidget

0 commit comments

Comments
 (0)