generated from cloudoperators/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(utils): move useEndlessScrollList to juno-ui-components, deprea…
…cate juno-utils package (#585) * chore(ui): include useEndlessScrollList hook into ui components * chore(juno): change imports for useEndlessScroll * chore(ui): modify tests and add types * chore(ui): epoxrt useEndlessScrollList proper * chore(utils): depreacte utils package * chore(ui): add changeset * chore(ui): remove comments * chore(ui): fix regression of scroll --------- Co-authored-by: Andreas Pfau <[email protected]>
- Loading branch information
Showing
12 changed files
with
158 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
"@cloudoperators/juno-ui-components": minor | ||
"@cloudoperators/juno-app-greenhouse": patch | ||
"@cloudoperators/juno-app-supernova": patch | ||
"@cloudoperators/juno-utils": patch | ||
"@cloudoperators/juno-app-example": patch | ||
"@cloudoperators/juno-app-doop": patch | ||
--- | ||
|
||
Replace useEndlessScrollList from utils to ui-componetns and utils deprecation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
packages/ui-components/src/hooks/useEndlessScrollList.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Juno contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { render, queryByAttribute, renderHook } from "@testing-library/react" | ||
import { useEndlessScrollList } from "./useEndlessScrollList" | ||
|
||
const intersectionObserverMock = () => ({ | ||
observe: () => null, | ||
disconnect: () => null, | ||
}) | ||
window.IntersectionObserver = vi.fn().mockImplementation(intersectionObserverMock) | ||
|
||
describe("useEndlessScrollList", () => { | ||
it("return no scroll items if items not all provided", () => { | ||
const { result } = renderHook(() => useEndlessScrollList([])) | ||
expect(result?.current?.scrollListItems?.length).toBe(0) | ||
}) | ||
|
||
describe("scrollListItems", () => { | ||
it("return all items if the whole amount is less then 20", () => { | ||
const { result } = renderHook(() => useEndlessScrollList(["1", "2", "3"])) | ||
expect(result?.current?.scrollListItems?.length).toBe(3) | ||
}) | ||
it("return 20 items if the whole amount is more then 20", () => { | ||
const newArray = Array.from({ length: 30 }, (_, i) => `${i + 1}`) | ||
const { result } = renderHook(() => useEndlessScrollList(newArray)) | ||
expect(result?.current?.scrollListItems?.length).toBe(20) | ||
}) | ||
}) | ||
|
||
describe("iterator", () => { | ||
it("returns a map function which iterates over all scrollListItems and adds the intersection ref if nothing else specified in options", () => { | ||
const { result } = renderHook(() => useEndlessScrollList(["1", "2", "3"])) | ||
const mapFunction = result.current.iterator.map( | ||
// eslint-disable-next-line no-unused-vars | ||
(item: unknown, index: number, array: unknown[]): React.JSX.Element => item as React.JSX.Element | ||
) | ||
const getById = queryByAttribute.bind(null, "id") | ||
const dom = render(mapFunction) | ||
const intersectionRefElement = getById(dom.container, "endlessScrollListLastItemRef") | ||
expect(intersectionRefElement).toBeTruthy() | ||
}) | ||
|
||
it("returns a map function which iterates over all scrollListItems and do not include the intersection ref or do not call refFunction if showRef is set to false in options", () => { | ||
const refFunction = vi.fn() | ||
const { result } = renderHook(() => | ||
useEndlessScrollList(["1", "2", "3"], { | ||
showRef: false, | ||
refFunction: refFunction, | ||
}) | ||
) | ||
const mapFunction = result.current.iterator.map( | ||
// eslint-disable-next-line no-unused-vars | ||
(item: unknown, index: number, array: unknown[]): React.JSX.Element => item as React.JSX.Element | ||
) | ||
const getById = queryByAttribute.bind(null, "id") | ||
const dom = render(mapFunction) | ||
const intersectionRefElement = getById(dom.container, "endlessScrollListLastItemRef") | ||
expect(intersectionRefElement).toBeFalsy() | ||
expect(refFunction).not.toHaveBeenCalled() | ||
}) | ||
|
||
it("returns a map function which iterates over all scrollListItems and does not add an intersection ref element", () => { | ||
const refFunction = vi.fn() | ||
const { result } = renderHook(() => | ||
useEndlessScrollList(["1", "2", "3"], { | ||
refFunction: refFunction, | ||
}) | ||
) | ||
const mapFunction = result.current.iterator.map( | ||
// eslint-disable-next-line no-unused-vars | ||
(item: unknown, index: number, array: unknown[]): React.JSX.Element => item as React.JSX.Element | ||
) | ||
const getById = queryByAttribute.bind(null, "id") | ||
const dom = render(mapFunction) | ||
const intersectionRefElement = getById(dom.container, "endlessScrollListLastItemRef") | ||
expect(intersectionRefElement).toBeFalsy() | ||
expect(refFunction).toHaveBeenCalled() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "./tsconfig.build.json", | ||
"include": ["./src/hooks/*.ts", "./types/hooks/*.ts", "./src/hooks/*.tsx"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters