import { create } from "react-test-renderer"

import * as React from "react"
import ActionPanel from "../ActionPanel"
import { Link } from "jamplay-common/routing"
const { book } = require("./bluekiss.book.json").data

describe("ActionPanel test", () => {
  it("should display amount as - if loading state", () => {
    const t = create(<ActionPanel />)
    t.root.find((node) => true)
  })

  it("should render data correctly", () => {
    const onfollow = jest.fn()
    const t = create(<ActionPanel book={book} onFollowBookClick={onfollow} />)
    const readLink = t.root.find((node) => {
      return node.type === (Link.ReadEpisode as any)
    })
    expect(readLink.props.params.category).toEqual("yaoi-yuri")

    const readLinks  = t.root.findAll((node) => {
      return node.props.params && node.props.params.category
    })

    for (const link of readLinks) {
      expect(link.props.params.category).toEqual("yaoi-yuri")
    }

  })

  it("should render data with category all link if categories is not provide", () => {
    const onfollow = jest.fn()
    const t = create(
      <ActionPanel
        book={{
          ...book,
          categories: undefined
        }}
        onFollowBookClick={onfollow}
      />
    )
    const readLink = t.root.find((node) => {
      return node.type === (Link.ReadEpisode as any)
    })
    expect(readLink.props.params.category).toEqual("all")
  })
})
