Skip to content

Commit

Permalink
feat(Radio): Add snapshots and solve storybook issues DEV-136
Browse files Browse the repository at this point in the history
  • Loading branch information
itsweliton committed May 24, 2021
1 parent 8ab1d2f commit 576130b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/components/Radio/Radio.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ export default {
component: Radio,
} as Meta

const Template: Story<RadioProps> = (props) => <Radio {...props} />
const Template: Story<RadioProps> = (props) => (
<>
<Radio {...props} />
<Radio {...props} />
</>
)

// Each story then reuses that template
export const Example = Template.bind({})
Expand Down
2 changes: 2 additions & 0 deletions src/components/RadioGroup/RadioGroup.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const Template: Story<RadioGroupProps> = (props: RadioGroupProps) => (
export const Example = Template.bind({})

Example.args = {
name: "inputGroup",
value: "value 1",
onChange: action("chosen"),
children: mockedChildrenOptions,
}
36 changes: 36 additions & 0 deletions src/components/RadioGroup/RadioGroup.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { render } from "../../tests/utils"
import Radio from "../Radio/Radio"
import { axe } from "jest-axe"

describe("Radio Group", () => {
test("renders correctly", async () => {
const onChange = jest.fn()
const { getByLabelText } = render(
<Radio.Group
name="RADIO_NAME"
value="RADIO_GROUP_VALUE"
onChange={onChange}
>
<Radio value="value 1" label="OPTION_Y" />
<Radio value="value 2" label="OPTION_X" />
</Radio.Group>
)

expect(getByLabelText("OPTION_Y")).toBeInTheDocument()
})

test("passes a11y check", async () => {
// Arrange
const onChange = jest.fn()
const { container } = render(
<Radio.Group name="inputGroup" value="SOME_VALUE" onChange={onChange}>
<Radio value="value 1" label="Option Y" />
<Radio value="value 2" label="Option X" />
</Radio.Group>
)
const results = await axe(container)

// Assert
expect(results).toHaveNoViolations()
})
})
3 changes: 3 additions & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export type { PaperProps } from "./Paper/Paper"
export { default as Popover } from "./Popover/Popover"
export type { PopoverProps } from "./Popover/Popover"

export { default as Radio } from "./Radio/Radio"
export type { RadioProps } from "./Radio/Radio"

export { default as Selector } from "./Selector/Selector"
export type { SelectorProps } from "./Selector/Selector"

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 576130b

Please sign in to comment.