diff --git a/packages/core/src/renderer/components/scroll-spy/__tests__/scroll-spy.test.tsx b/packages/core/src/renderer/components/scroll-spy/__tests__/scroll-spy.test.tsx deleted file mode 100644 index 1dc21b6735..0000000000 --- a/packages/core/src/renderer/components/scroll-spy/__tests__/scroll-spy.test.tsx +++ /dev/null @@ -1,235 +0,0 @@ -/** - * Copyright (c) OpenLens Authors. All rights reserved. - * Licensed under MIT License. See LICENSE in root directory for more information. - */ - -import React from "react"; -import "@testing-library/jest-dom/extend-expect"; -import { screen, waitFor } from "@testing-library/react"; -import { ScrollSpy } from "../scroll-spy"; -import { RecursiveTreeView } from "../../tree-view"; -import { getDiForUnitTesting } from "../../../getDiForUnitTesting"; -import { type DiRender, renderFor } from "../../test-utils/renderFor"; - -const observe = jest.fn(); - -Object.defineProperty(window, "IntersectionObserver", { - writable: true, - value: jest.fn().mockImplementation(() => ({ - observe, - unobserve: jest.fn(), - })), -}); - -describe("", () => { - let render: DiRender; - - beforeEach(() => { - const di = getDiForUnitTesting({ doGeneralOverrides: true }); - - render = renderFor(di); - }); - - it("renders w/o errors", () => { - const { container } = render(( - ( -
-
-

Application

-
-
- )} - /> - )); - - expect(container).toBeInstanceOf(HTMLElement); - }); - - it("calls intersection observer", () => { - render(( - ( -
-
-

Application

-
-
- )} - /> - )); - - expect(observe).toHaveBeenCalled(); - }); - - it("renders dataTree component", async () => { - render(( - ( -
- -
-

Application

-
-
- )} - /> - )); - - expect(await screen.findByTestId("TreeView")).toBeInTheDocument(); - }); - - it("throws if no sections founded", () => { - // Prevent writing to stderr during this render. - const err = console.error; - - console.error = jest.fn(); - - expect(() => render(( - ( -
- Content -
- )} - /> - ))).toThrow(); - - // Restore writing to stderr. - console.error = err; - }); -}); - - -describe(" dataTree inside ", () => { - let render: DiRender; - - beforeEach(() => { - const di = getDiForUnitTesting({ doGeneralOverrides: true }); - - render = renderFor(di); - }); - - it("contains links to all sections", async () => { - render(( - ( -
- -
-

Application

-
-

Appearance

-
-
-

Theme

-
description
-
-
-
- )} - /> - )); - - expect(await screen.findByTitle("Application")).toBeInTheDocument(); - expect(await screen.findByTitle("Appearance")).toBeInTheDocument(); - expect(await screen.findByTitle("Theme")).toBeInTheDocument(); - }); - - it("not showing links to sections without id", async () => { - const { queryByTitle } = render(( - ( -
- -
-

Application

-
-

Kubectl

-
-
-

Appearance

-
-
-
- )} - /> - )); - - expect(await screen.findByTitle("Application")).toBeInTheDocument(); - expect(await screen.findByTitle("Appearance")).toBeInTheDocument(); - - await waitFor(() => { - expect(queryByTitle("Kubectl")).not.toBeInTheDocument(); - }); - }); - - it("expands parent sections", async () => { - render(( - ( -
- -
-

Application

-
-

Appearance

-
-
-

Theme

-
description
-
-
-
-

Kubernetes

-
-

Kubectl

-
-
-
- )} - /> - )); - - expect(await screen.findByTitle("Application")).toHaveAttribute("aria-expanded"); - expect(await screen.findByTitle("Kubernetes")).toHaveAttribute("aria-expanded"); - }); - - it("skips sections without headings", async () => { - render(( - ( -
- -
-

Application

-
-

Appearance

-
-
-

Theme

-
-
-
- )} - /> - )); - - expect(await screen.findByTitle("Application")).toBeInTheDocument(); - - await waitFor(() => { - expect(screen.queryByTitle("appearance")).not.toBeInTheDocument(); - expect(screen.queryByTitle("Appearance")).not.toBeInTheDocument(); - }); - }); -}); diff --git a/packages/core/src/renderer/components/scroll-spy/scroll-spy.tsx b/packages/core/src/renderer/components/scroll-spy/scroll-spy.tsx index b31e1cc701..9fb763d607 100644 --- a/packages/core/src/renderer/components/scroll-spy/scroll-spy.tsx +++ b/packages/core/src/renderer/components/scroll-spy/scroll-spy.tsx @@ -6,7 +6,14 @@ import { observer } from "mobx-react"; import React, { useEffect, useRef, useState } from "react"; import { useMutationObserver } from "../../hooks"; -import type { NavigationTree } from "../tree-view"; + +export interface NavigationTree { + id: string; + parentId?: string; + name: string; + selected?: boolean; + children?: NavigationTree[]; +} export interface ScrollSpyProps extends React.DOMAttributes { render: (data: NavigationTree[]) => JSX.Element;