Skip to content

Commit

Permalink
style: cleanup comments (#96)
Browse files Browse the repository at this point in the history
## Motivation

<!-- List motivation and changes here -->

## Issues closed

<!-- List closed issues here -->
  • Loading branch information
pixelass committed Mar 23, 2024
1 parent 9d2fd9d commit 376738b
Show file tree
Hide file tree
Showing 21 changed files with 133 additions and 49 deletions.
1 change: 1 addition & 0 deletions electron-builder.yml
Expand Up @@ -18,6 +18,7 @@ nsis:
oneClick: false
allowToChangeInstallationDirectory: true
artifactName: "${productName}-Setup-${version}.${ext}"
# include: build/installer.nsh
asar: true
asarUnpack:
- "resources/python/**/*"
Expand Down
2 changes: 0 additions & 2 deletions jest.config.client.ts
@@ -1,7 +1,5 @@
import { defaults } from "jest-config";

// Adjust the import path to your tsconfig.json file

const jestConfig = {
...defaults,
roots: ["<rootDir>/src/client"],
Expand Down
2 changes: 0 additions & 2 deletions jest.config.shared.ts
@@ -1,7 +1,5 @@
import { defaults } from "jest-config";

// Adjust the import path to your tsconfig.json file

const jestConfig = {
...defaults,
roots: ["<rootDir>/src/shared"],
Expand Down
120 changes: 120 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -7,86 +7,74 @@ import { useKeyboardControlledImagesNavigation } from "../keyboard-controlled-im
describe("useKeyboardControlledImagesNavigation", () => {
it("should handle keyboard navigation correctly", async () => {
const onBeforeChangeMock = jest.fn();
// Render the hook that we are testing
renderHook(
() => useKeyboardControlledImagesNavigation({ onBeforeChange: onBeforeChangeMock }),
{
wrapper: Provider,
}
);

// Set initial state for images and selectedImage
act(() => {
fireEvent.keyDown(window, { key: "ArrowRight", altKey: true });
});

// Assertions
await waitFor(() => {
expect(onBeforeChangeMock).toHaveBeenCalledTimes(1);
});
act(() => {
fireEvent.keyDown(window, { key: "ArrowLeft", altKey: true });
});

// Assertions
await waitFor(() => {
expect(onBeforeChangeMock).toHaveBeenCalledTimes(2);
});
act(() => {
fireEvent.keyDown(window, { key: "ArrowUp", altKey: true });
});

// Assertions
await waitFor(() => {
expect(onBeforeChangeMock).toHaveBeenCalledTimes(3);
});
act(() => {
fireEvent.keyDown(window, { key: "ArrowDown", altKey: true });
});

// Assertions
await waitFor(() => {
expect(onBeforeChangeMock).toHaveBeenCalledTimes(4);
});
});
it("should not respond with alt key", async () => {
const onBeforeChangeMock = jest.fn();

// Render the hook that we are testing
renderHook(
() => useKeyboardControlledImagesNavigation({ onBeforeChange: onBeforeChangeMock }),
{
wrapper: Provider,
}
);

// Set initial state for images and selectedImage
act(() => {
fireEvent.keyDown(window, { key: "ArrowRight" });
});

// Assertions
await waitFor(() => {
expect(onBeforeChangeMock).not.toHaveBeenCalled();
});
});
it("should not respond to other keys", async () => {
const onBeforeChangeMock = jest.fn();

// Render the hook that we are testing
renderHook(
() => useKeyboardControlledImagesNavigation({ onBeforeChange: onBeforeChangeMock }),
{
wrapper: Provider,
}
);

// Set initial state for images and selectedImage
act(() => {
fireEvent.keyDown(window, { key: "Enter", altKey: true });
});

// Assertions
await waitFor(() => {
expect(onBeforeChangeMock).not.toHaveBeenCalled();
});
Expand Down
6 changes: 2 additions & 4 deletions src/client/ions/hooks/__tests__/columns.test.tsx
@@ -1,19 +1,17 @@
// UseColumns.test.tsx
import { extendTheme, ThemeProvider } from "@mui/joy/styles";
import { render } from "@testing-library/react";
import React from "react";
import "@testing-library/jest-dom";

import { useColumns } from "../columns"; // Adjust the import path as necessary
import { useColumns } from "../columns";

// Mock component to utilize the useColumns hook
function MockComponent({ xs, sm, md, lg }: { xs: number; sm: number; md: number; lg: number }) {
const columns = useColumns({ xs, sm, md, lg });
return <div data-testid="column-count">{columns}</div>;
}

describe("useColumns", () => {
const theme = extendTheme(); // Use your custom theme if you have one
const theme = extendTheme();

function renderWithTheme(properties: { xs: number; sm: number; md: number; lg: number }) {
return render(
Expand Down
2 changes: 1 addition & 1 deletion src/client/ions/hooks/__tests__/resettable-state.test.ts
@@ -1,6 +1,6 @@
import { renderHook, act } from "@testing-library/react";

import { useResettableState } from "../resettable-state"; // Adjust the import path based on your file structure
import { useResettableState } from "../resettable-state";

describe("useResettableState hook", () => {
jest.useFakeTimers();
Expand Down
6 changes: 2 additions & 4 deletions src/client/ions/hooks/__tests__/scroll-position.test.tsx
@@ -1,7 +1,7 @@
import { act, fireEvent, render } from "@testing-library/react";
import React, { useRef } from "react";

import { useScrollPosition } from "../scroll-position"; // Adjust your import path
import { useScrollPosition } from "../scroll-position";
import "@testing-library/jest-dom";

class ResizeObserver {
Expand All @@ -11,7 +11,6 @@ class ResizeObserver {
}

global.ResizeObserver = ResizeObserver;
// Test component that uses your hook
function TestComponent() {
const reference = useRef<HTMLDivElement>(null);
const scroll = useScrollPosition(reference);
Expand All @@ -34,7 +33,6 @@ function TestComponent() {

describe("useScrollPosition", () => {
beforeEach(() => {
// Mock properties before each test
Object.defineProperty(HTMLElement.prototype, "scrollWidth", {
configurable: true,
value: 300,
Expand All @@ -55,7 +53,7 @@ describe("useScrollPosition", () => {

it("should update scroll position on scroll event", async () => {
const { getByTestId } = render(<TestComponent />);
const scrollableDiv = getByTestId("scrollable-div"); // Add this data-testid to your scrollable div
const scrollableDiv = getByTestId("scrollable-div");

// Check initial state
expect(getByTestId("scrollable")).toHaveTextContent("true");
Expand Down
2 changes: 1 addition & 1 deletion src/client/ions/hooks/__tests__/vector-store.test.ts
Expand Up @@ -4,7 +4,7 @@ import { useDebounce } from "use-debounce";
import { useVectorStore } from "../vector-store";

import { buildKey } from "#/build-key";
import { ID } from "#/enums"; // Update the import path as necessary
import { ID } from "#/enums";

jest.mock("use-debounce", () => ({
useDebounce: jest.fn(),
Expand Down
2 changes: 0 additions & 2 deletions src/client/ions/hooks/resettable-state.ts
@@ -1,11 +1,9 @@
import { useCallback, useRef, useState } from "react";

export function useResettableState<T>(initialState: T, delay: number): [T, (value: T) => void] {
// Use useState to manage the state
const [state, setState] = useState<T>(initialState);
const timer = useRef(-1);

// A callback function that resets the state to its initial value after a delay
const setTemporaryState = useCallback(
(value: T) => {
setState(value);
Expand Down
4 changes: 0 additions & 4 deletions src/client/ions/hooks/resize-observer.ts
Expand Up @@ -6,7 +6,6 @@ interface Size {
height: number | undefined;
}

// Hook
export function useResizeObserver<T extends HTMLElement>(reference: RefObject<T>): Size {
const [size, setSize] = useState<Size>({ width: undefined, height: undefined });

Expand All @@ -20,10 +19,8 @@ export function useResizeObserver<T extends HTMLElement>(reference: RefObject<T>
return;
}

// For simplicity, we'll only consider the first entry
const entry = entries[0];

// Use contentRect for border-box size
setSize({
width: entry.contentRect.width,
height: entry.contentRect.height,
Expand All @@ -34,7 +31,6 @@ export function useResizeObserver<T extends HTMLElement>(reference: RefObject<T>

observer.observe(reference.current);

// Cleanup function
return () => {
observer.disconnect();
};
Expand Down
2 changes: 1 addition & 1 deletion src/client/ions/hooks/scroll-position.ts
Expand Up @@ -34,7 +34,7 @@ export function useScrollPosition(
}, [reference]);

useEffect(() => {
checkScroll(); // Initial check
checkScroll();

const currentReference = reference.current;
if (currentReference) {
Expand Down
4 changes: 2 additions & 2 deletions src/client/ions/hooks/vector-store.ts
Expand Up @@ -22,9 +22,9 @@ import type { SearchOptions, VectorStoreResponse } from "#/types/vector-store";
* // searchResults will contain an array of search responses where each item has a score above 0.5
*/
export function useVectorStore(value: string, { score_threshold }: SearchOptions = {}) {
const [query] = useDebounce(value, 300); // Debounce the search value to limit the search calls
const [query] = useDebounce(value, 300);
const [results, setResults] = useState<VectorStoreResponse[]>([]); // State to store the search results
// Effect to handle the actual search querying when the debounced query or score_threshold changes

useEffect(() => {
if (query.trim()) {
// Only proceed with a non-empty query
Expand Down
2 changes: 0 additions & 2 deletions src/client/ions/utils/__tests__/string.test.ts
Expand Up @@ -18,8 +18,6 @@ describe("capitalizeFirstLetter", () => {
});
});

// Import the function to test

describe("replaceImagePlaceholders", () => {
it("replaces all image placeholders with corresponding URLs", () => {
// Define a sample array of images
Expand Down

0 comments on commit 376738b

Please sign in to comment.