<commit_before>import { AuctionResults_Test_QueryRawResponse } from "__generated__/AuctionResults_Test_Query.graphql"
import { AuctionResultsFixture } from "Apps/__tests__/Fixtures/Artist/Routes/AuctionResultsFixture"
import { AuctionResultsRouteFragmentContainer as AuctionResultsRoute } from "Apps/Artist/Routes/AuctionResults"
import { MockBoot, renderRelayTree } from "DevTools"
import { ReactWrapper } from "enzyme"
import React from "react"
import { act } from "react-dom/test-utils"
import { graphql } from "react-relay"
import { useTracking } from "react-tracking"
import { Breakpoint } from "Utils/Responsive"

jest.unmock("react-relay")
jest.mock("react-tracking")

describe("AuctionResults", () => {
  let wrapper: ReactWrapper

  const getWrapper = async (breakpoint: Breakpoint = "xl") => {
    return await renderRelayTree({
      Component: AuctionResultsRoute,
      query: graphql`
        query AuctionResults_Test_Query($artistID: String!) @raw_response_type {
          artist(id: $artistID) {
            ...AuctionResults_artist
          }
        }
      `,
      mockData: AuctionResultsFixture as AuctionResults_Test_QueryRawResponse,
      variables: {
        artistID: "pablo-picasso",
      },
      wrapper: children => (
        <MockBoot breakpoint={breakpoint}>{children}</MockBoot>
      ),
    })
  }

  const trackEvent = jest.fn()
  beforeAll(() => {
    ;(useTracking as jest.Mock).mockImplementation(() => {
      return {
        trackEvent,
      }
    })
  })
  afterEach(() => {
    trackEvent.mockReset()
  })

  describe("general behavior", () => {
    beforeAll(async () => {
      wrapper = await getWrapper()
    })

    it("renders proper elements", () => {
      expect(wrapper.find("SelectSmall").length).toBe(1)
      expect(wrapper.find("Pagination").length).toBe(1)
      expect(wrapper.find("ArtistAuctionResultItem").length).toBe(10)
    })

    it("renders the proper count", () => {
      expect(wrapper.html()).toContain("Showing 830 results")
    })

    it("renders proper select options", () => {
      const html = wrapper.find("SelectSmall").html()
      expect(html).toContain("Most recent")
      expect(html).toContain("Estimate")
      expect(html).toContain("Sale price")
    })

    describe("collapsed details", () => {
      it("opens the collapse", () => {
        wrapper
          .find("ArrowDownIcon")
          .first()
          .simulate("click")
        wrapper.update()
        const html = wrapper.html()
        const data =
          AuctionResultsFixture.artist.auctionResultsConnection.edges[0].node
        expect(html).toContain("Artwork Info")
        expect(html).toContain(data.dimension_text)
        expect(html).toContain(data.description)
      })
    })

    describe("user interactions", () => {
      const defaultRelayParams = {
        first: 10,
        after: null,
        artistID: "pablo-picasso",
        organizations: [],
        sort: "DATE_DESC",
      }
      let refetchSpy
      beforeEach(async () => {
        wrapper = await getWrapper()
        refetchSpy = jest.spyOn(
          (wrapper.find("AuctionResultsContainer").props() as any).relay,
          "refetch"
        )
      })
      describe("pagination", () => {
        it("triggers relay refetch with after", () => {
          const pagination = wrapper.find("Pagination")

          pagination
            .find("button")
            .at(1)
            .simulate("click")
          expect(refetchSpy).toHaveBeenCalledTimes(1)
          expect(refetchSpy.mock.calls[0][0]).toEqual(
            expect.objectContaining({
              ...defaultRelayParams,
              after: "YXJyYXljb25uZWN0aW9uOjk=",
            })
          )
        })
      })
      describe("filters", () => {
        describe("medium filter", () => {
          it("triggers relay refetch with medium list", done => {
            const filter = wrapper.find("MediumFilter")

            const checkboxes = filter.find("Checkbox")

            checkboxes.at(1).simulate("click")

            checkboxes.at(2).simulate("click")

            checkboxes.at(1).simulate("click")

            setTimeout(() => {
              expect(refetchSpy).toHaveBeenCalledTimes(3)

              expect(refetchSpy.mock.calls[0][0]).toEqual(
                expect.objectContaining({
                  ...defaultRelayParams,
                  categories: ["Work on Paper"],
                })<commit_msg>test price shows on first load<commit_after>import { AuctionResults_Test_QueryRawResponse } from "__generated__/AuctionResults_Test_Query.graphql"
import { AuctionResultsFixture } from "Apps/__tests__/Fixtures/Artist/Routes/AuctionResultsFixture"
import { AuctionResultsRouteFragmentContainer as AuctionResultsRoute } from "Apps/Artist/Routes/AuctionResults"
import { MockBoot, renderRelayTree } from "DevTools"
import { ReactWrapper } from "enzyme"
import React from "react"
import { act } from "react-dom/test-utils"
import { graphql } from "react-relay"
import { useTracking } from "react-tracking"
import { Breakpoint } from "Utils/Responsive"

jest.unmock("react-relay")
jest.mock("react-tracking")

describe("AuctionResults", () => {
  let wrapper: ReactWrapper

  const getWrapper = async (breakpoint: Breakpoint = "xl") => {
    return await renderRelayTree({
      Component: AuctionResultsRoute,
      query: graphql`
        query AuctionResults_Test_Query($artistID: String!) @raw_response_type {
          artist(id: $artistID) {
            ...AuctionResults_artist
          }
        }
      `,
      mockData: AuctionResultsFixture as AuctionResults_Test_QueryRawResponse,
      variables: {
        artistID: "pablo-picasso",
      },
      wrapper: children => (
        <MockBoot breakpoint={breakpoint}>{children}</MockBoot>
      ),
    })
  }

  const trackEvent = jest.fn()
  beforeAll(() => {
    ;(useTracking as jest.Mock).mockImplementation(() => {
      return {
        trackEvent,
      }
    })
  })
  afterEach(() => {
    trackEvent.mockReset()
  })

  describe("general behavior", () => {
    beforeAll(async () => {
      wrapper = await getWrapper()
    })

    it("renders proper elements", () => {
      expect(wrapper.find("SelectSmall").length).toBe(1)
      expect(wrapper.find("Pagination").length).toBe(1)
      expect(wrapper.find("ArtistAuctionResultItem").length).toBe(10)
    })

    it("renders the proper count", () => {
      expect(wrapper.html()).toContain("Showing 830 results")
    })

    it("renders either realized price or price not avail", () => {
      expect(wrapper.html()).toContain(
        "Price not available" || "Realized price"
      )
    })

    it("renders proper select options", () => {
      const html = wrapper.find("SelectSmall").html()
      expect(html).toContain("Most recent")
      expect(html).toContain("Estimate")
      expect(html).toContain("Sale price")
    })

    describe("collapsed details", () => {
      it("opens the collapse", () => {
        wrapper
          .find("ArrowDownIcon")
          .first()
          .simulate("click")
        wrapper.update()
        const html = wrapper.html()
        const data =
          AuctionResultsFixture.artist.auctionResultsConnection.edges[0].node
        expect(html).toContain("Artwork Info")
        expect(html).toContain(data.dimension_text)
        expect(html).toContain(data.description)
      })
    })

    describe("user interactions", () => {
      const defaultRelayParams = {
        first: 10,
        after: null,
        artistID: "pablo-picasso",
        organizations: [],
        sort: "DATE_DESC",
      }
      let refetchSpy
      beforeEach(async () => {
        wrapper = await getWrapper()
        refetchSpy = jest.spyOn(
          (wrapper.find("AuctionResultsContainer").props() as any).relay,
          "refetch"
        )
      })
      describe("pagination", () => {
        it("triggers relay refetch with after", () => {
          const pagination = wrapper.find("Pagination")

          pagination
            .find("button")
            .at(1)
            .simulate("click")
          expect(refetchSpy).toHaveBeenCalledTimes(1)
          expect(refetchSpy.mock.calls[0][0]).toEqual(
            expect.objectContaining({
              ...defaultRelayParams,
              after: "YXJyYXljb25uZWN0aW9uOjk=",
            })
          )
        })

        it("re-shows sign up to see price", () => {
          const pagination = wrapper.find("Pagination")
          pagination
            .find("button")
            .at(2)
            .simulate("click")
          wrapper.update()
          const html = wrapper.html()
          expect(html).toContain("Sign up to see price")
        })
      })
      describe("filters", () => {
        describe("medium filter", () => {
          it("triggers relay refetch with medium list", done => {
            const filter = wrapper.find("MediumFilter")

            const checkboxes = filter.find("Checkbox")

            checkboxes.at(1).simulate("click")

            checkboxes.at(2).simulate("click")

            checkboxes.at(1).simulate("click")

            setTimeout(() => {
              expect(refetchSpy).toHaveBeenCalledTimes(3)

              expect(refetchSpy.mock.calls[0][0]).toEqual(
                expect.objectContaining({
                  ...defaultRelayParams,
                  categories: ["Work on Paper"],
                })
{'fraction_non_alphanumeric': 0.1357696802294699, 'fraction_numerical': 0.0052055667693615216, 'mean_word_length': 2.396103896103896, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1695672', 'n_tokens_mistral': 2747, 'n_tokens_neox': 2704, 'n_words': 469}