import { composeStories } from "@storybook/react"
import { screen } from "@testing-library/react"
import { userEvent } from "@testing-library/user-event"
import React from "react"
import { expect, describe, test } from "vitest"
import { render } from "../../../tests/render"
import * as stories from "./RadioButtonGroup.stories"

const { Default, DisabledGroup, DisabledItem } = composeStories(stories)

describe("<RadioButtonGroup />", () => {
  test("Default", async () => {
    render(<Default />)

    expect(screen.getByLabelText("Option one", { exact: false })).toBeChecked()

    await userEvent.click(screen.getByLabelText("Option two", { exact: false }))

    expect(screen.getByLabelText("Option two", { exact: false })).toBeChecked()
  })

  test("DisabledGroup", async () => {
    render(<DisabledGroup />)

    expect(screen.getByLabelText("Option one", { exact: false })).toBeDisabled()
    expect(screen.getByLabelText("Option two", { exact: false })).toBeDisabled()
  })

  test("DisabledItem", async () => {
    render(<DisabledItem />)

    expect(screen.getByLabelText("Option one", { exact: false })).toBeEnabled()
    expect(screen.getByLabelText("Option two", { exact: false })).toBeDisabled()
  })
})
