github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/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 { AnalyticsAction, AnalyticsType } from "./analytics"
     6  import {
     7    cleanupMockAnalyticsCalls,
     8    expectIncrs,
     9    mockAnalyticsCalls,
    10  } from "./analytics_test_helpers"
    11  import Features, { FeaturesTestProvider, Flag } from "./feature"
    12  import { OverviewTableDisplayOptions } from "./OverviewTableDisplayOptions"
    13  import { ResourceGroupsContextProvider } from "./ResourceGroupsContext"
    14  import {
    15    ResourceListOptions,
    16    ResourceListOptionsProvider,
    17  } from "./ResourceListOptionsContext"
    18  import { nResourceWithLabelsView, TestDataView } from "./testdata"
    19  
    20  // Helpers
    21  const DisplayOptions = ({
    22    view,
    23    resourceListOptions,
    24  }: {
    25    view: TestDataView
    26    resourceListOptions?: ResourceListOptions
    27  }) => {
    28    const features = new Features({
    29      [Flag.Labels]: true,
    30    })
    31    return (
    32      <MemoryRouter initialEntries={["/"]}>
    33        <FeaturesTestProvider value={features}>
    34          <ResourceGroupsContextProvider>
    35            <ResourceListOptionsProvider
    36              initialValuesForTesting={resourceListOptions}
    37            >
    38              <OverviewTableDisplayOptions resources={view.uiResources} />
    39            </ResourceListOptionsProvider>
    40          </ResourceGroupsContextProvider>
    41        </FeaturesTestProvider>
    42      </MemoryRouter>
    43    )
    44  }
    45  
    46  beforeEach(() => {
    47    mockAnalyticsCalls()
    48  })
    49  
    50  afterEach(() => {
    51    cleanupMockAnalyticsCalls()
    52  })
    53  
    54  describe("expand-all button", () => {
    55    it("sends analytics onclick", () => {
    56      let view = nResourceWithLabelsView(3)
    57      const { container } = render(DisplayOptions({ view }))
    58      userEvent.click(screen.getByTitle("Expand All"))
    59      expectIncrs({
    60        name: "ui.web.expandAllGroups",
    61        tags: { action: AnalyticsAction.Click, type: AnalyticsType.Grid },
    62      })
    63    })
    64  })
    65  
    66  describe("collapse-all button", () => {
    67    it("sends analytics onclick", () => {
    68      let view = nResourceWithLabelsView(3)
    69      const { container } = render(DisplayOptions({ view }))
    70      userEvent.click(screen.getByTitle("Collapse All"))
    71      expectIncrs({
    72        name: "ui.web.collapseAllGroups",
    73        tags: { action: AnalyticsAction.Click, type: AnalyticsType.Grid },
    74      })
    75    })
    76  })