github.com/tilt-dev/tilt@v0.36.0/web/src/OverviewTableDisplayOptions.test.tsx (about)

     1  import { render, screen } from "@testing-library/react"
     2  import userEvent from "@testing-library/user-event"
     3  import React from "react"
     4  import { MemoryRouter } from "react-router"
     5  import Features, { FeaturesTestProvider, Flag } from "./feature"
     6  import { OverviewTableDisplayOptions } from "./OverviewTableDisplayOptions"
     7  import { ResourceGroupsContextProvider } from "./ResourceGroupsContext"
     8  import {
     9    ResourceListOptions,
    10    ResourceListOptionsProvider,
    11  } from "./ResourceListOptionsContext"
    12  import { nResourceWithLabelsView, TestDataView } from "./testdata"
    13  
    14  // Helpers
    15  const DisplayOptions = ({
    16    view,
    17    resourceListOptions,
    18  }: {
    19    view: TestDataView
    20    resourceListOptions?: ResourceListOptions
    21  }) => {
    22    const features = new Features({
    23      [Flag.Labels]: true,
    24    })
    25    return (
    26      <MemoryRouter initialEntries={["/"]}>
    27        <FeaturesTestProvider value={features}>
    28          <ResourceGroupsContextProvider>
    29            <ResourceListOptionsProvider
    30              initialValuesForTesting={resourceListOptions}
    31            >
    32              <OverviewTableDisplayOptions resources={view.uiResources} />
    33            </ResourceListOptionsProvider>
    34          </ResourceGroupsContextProvider>
    35        </FeaturesTestProvider>
    36      </MemoryRouter>
    37    )
    38  }
    39  
    40  describe("expand-all button", () => {
    41    it("sends analytics onclick", () => {
    42      let view = nResourceWithLabelsView(3)
    43      const { container } = render(DisplayOptions({ view }))
    44      userEvent.click(screen.getByTitle("Expand All"))
    45    })
    46  })
    47  
    48  describe("collapse-all button", () => {
    49    it("sends analytics onclick", () => {
    50      let view = nResourceWithLabelsView(3)
    51      const { container } = render(DisplayOptions({ view }))
    52      userEvent.click(screen.getByTitle("Collapse All"))
    53    })
    54  })