import * as React from "react"
import { BookSuggestionResultItem} from "../SearchTextInput"
import * as renderer from "react-test-renderer"
import { generateHighlightTextMarkup } from "../../utils"
describe("SearchTextInput test", () => {
it("should generateHightlightTextMarkup work correctly", () => {
let value = "อล"
expect(generateHighlightTextMarkup("อลวนหัวใจมาสคอตซ่อนรัก", value)).toMatchSnapshot()
expect(generateHighlightTextMarkup("[The Mask Singer 3 มงเพชรXนางอาย] อลวนวุ่นรัก", value)).toMatchSnapshot()
expect(generateHighlightTextMarkup("Lovely Girlfriend อลวนหัวใจตกหลุมรักสาวใสจอมวุ่น", value)).toMatchSnapshot()
value = "น้"
expect(generateHighlightTextMarkup("น้ำเอยน้ำใจ น้ำใส น้าสาว", value)).toMatchSnapshot()
expect(generateHighlightTextMarkup("น้องนาง นู้ นี้ น้าม", value)).toMatchSnapshot()
})
it("should highlight multiple match word correctly", () => {
const value = "ความรัก ที่ ไม่สมหวัง"
expect(generateHighlightTextMarkup("นายจอมยุ่งกับความรักอลวนที่ไม่สมหวังสักทีไอ่สั้ด", value)).toMatchSnapshot()
})
it("should search book category is Y", () => {
const book = require("./search-result-data-3.json").data.autoSuggestion.books[0]
const component = renderer.create(
)
const aLink = component.root.findAll((node) => {
const isLink = node.type === "a"
return isLink && node.props.href === "/yaoi-yuri/book5ad6f2ca8b7c1b000fac2177"
})
expect(aLink.length).toBe(1)
})
it("should search book category is romantic", () => {
const book = require("./search-result-data-3.json").data.autoSuggestion.books[1]
const component = renderer.create(
)
const aLink = component.root.findAll((node) => {
const isLink = node.type === "a"
return isLink && node.props.href === "/romantic/book5a3c8f755905644d284e36db"
})
expect(aLink.length).toBe(1)
})
it("should search book category is empty", () => {
const book = require("./search-result-data-3.json").data.autoSuggestion.books[2]
const component = renderer.create(
)
const aLink = component.root.findAll((node) => {
const isLink = node.type === "a"
return isLink && node.props.href === "/all/book5a3c8f755905644d284e36db"
})
expect(aLink.length).toBe(1)
})
it("should search author", () => {
const author = require("./search-result-data-3.json").data.autoSuggestion.authors[0]
const component = renderer.create(
)
const aLink = component.root.findAll((node) => {
const isLink = node.type === "a"
return isLink && node.props.href === "/author/5a546408ae59280013499406"
})
expect(aLink.length).toBe(1)
})
})