import React from "react"
import * as util from "../util"

describe("jsXTextContent", () => {
  it("returns an empty string if children is null", () => {
    expect(util.jsxTextContent(null)).toEqual("")
  })

  it("returns the passed argument if it is a string", () => {
    expect(util.jsxTextContent("foo")).toEqual("foo")
  })

  it("returns the text content of the children", () => {
    const children = [
      "foo",
      <div key="a">
        bar
        <div>baz</div>
      </div>,
      "qux"
    ]
    expect(util.jsxTextContent(children)).toEqual("foobarbazqux")
  })

  it("returns the text content of the children recursively", () => {
    const children = [
      "foo",
      <div key="a">
        bar
        <div>baz</div>
      </div>,
      <div key="b">
        qux
        <div>quux</div>
      </div>
    ]
    expect(util.jsxTextContent(children)).toEqual("foobarbazquxquux")
  })
})
