Skip to content

Commit

Permalink
Merge pull request #273 from wethegit/feature/icon-alt-tests
Browse files Browse the repository at this point in the history
feature: add tests for aria-hidden and aria-label for icon component
  • Loading branch information
rvno authored Jul 3, 2024
2 parents 74573cc + ba708ef commit 5335787
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Meta, StoryObj } from "@storybook/react"
import { expect, within } from "@storybook/test"

import { Icon, IconDefs, IconSymbol } from "@local/components"

Expand Down Expand Up @@ -28,4 +29,31 @@ type Story = StoryObj<typeof Icon>

export const Default: Story = {
render: (args) => <Icon {...args} />,
play: async ({ canvasElement }) => {
const canvas = within(canvasElement)

const icon = canvas.getByRole("img", { hidden: true })

expect(icon).toBeInTheDocument()

// without an alt prop provided, aria-hidden should be true
expect(icon.getAttribute("aria-hidden")).toEqual("true")
expect(icon.hasAttribute("aria-label")).toBe(false)
},
}

export const WithAlt: Story = {
render: (args) => {
return <Icon {...args} />
},
play: async ({ args, canvasElement }) => {
const canvas = within(canvasElement)
if (args.alt) {
const icon = canvas.getByLabelText(args.alt)

expect(icon).toBeInTheDocument()
expect(icon.getAttribute("aria-label")).toEqual(args.alt)
expect(icon.getAttribute("aria-hidden")).toEqual("false")
}
},
}

0 comments on commit 5335787

Please sign in to comment.