import * as React from "react" import { create } from "react-test-renderer" import { RatingStarIndicator } from "../" import { getStars } from "../RatingStarIndicator" import { Icon } from "../../../icon" it("should getStars calculate correctly", () => { const stars = [0, 1, 2, 3, 4, 5] const onClick = jest.fn() const onMouseEnter = jest.fn() for (const s of stars) { const starComponents = getStars(s, onClick, onMouseEnter) expect(starComponents).toBeDefined() const t = create(
{starComponents}
) const blank = t.root.findAll((node) => node.type === (Icon as any) && node.props.name === "star-o") const solid = t.root.findAll((node) => node.type === (Icon as any) && node.props.name === "star") expect(blank.length).toEqual(5 - s) expect(solid.length).toEqual(s) } }) it("should getStars with 4.8 avg and return 5 fill stars", () => { const t = create() const blank = t.root.findAll((node) => node.type === (Icon as any) && node.props.name === "star-o") const solid = t.root.findAll((node) => node.type === (Icon as any) && node.props.name === "star") expect(blank.length).toEqual(0) expect(solid.length).toEqual(5) }) it("should getStars with 4.3 avg and return 5 fill stars", () => { const t = create() const blank = t.root.findAll((node) => node.type === (Icon as any) && node.props.name === "star-o") const solid = t.root.findAll((node) => node.type === (Icon as any) && node.props.name === "star") expect(blank.length).toEqual(1) expect(solid.length).toEqual(4) }) it("should have maximum 5 stars", () => { let t = create() let stars = t.root.findAll((node) => node.type === (Icon as any)) expect(stars.length).toBeLessThanOrEqual(5) t = create() stars = t.root.findAll((node) => node.type === (Icon as any)) expect(stars.length).toBeLessThanOrEqual(5) t = create() stars = t.root.findAll((node) => node.type === (Icon as any)) expect(stars.length).toBeLessThanOrEqual(5) })