mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 05:37:20 +08:00
Co-authored-by: openhands <openhands@all-hands.dev> Co-authored-by: Hiep Le <69354317+hieptl@users.noreply.github.com> Co-authored-by: Abhay Mishra <grabhaymishra@gmail.com> Co-authored-by: Hyun Han <62870362+smosco@users.noreply.github.com> Co-authored-by: Nhan Nguyen <nhan13574@gmail.com> Co-authored-by: Bharath A V <avbharath1221@gmail.com> Co-authored-by: hieptl <hieptl.developer@gmail.com> Co-authored-by: Chloe <chloe@openhands.com> Co-authored-by: HeyItsChloe <54480367+HeyItsChloe@users.noreply.github.com>
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import { act, renderHook } from "@testing-library/react";
|
|
import { describe, expect, it } from "vitest";
|
|
import { useSelectedOrganizationStore } from "#/stores/selected-organization-store";
|
|
|
|
describe("useSelectedOrganizationStore", () => {
|
|
it("should have null as initial organizationId", () => {
|
|
const { result } = renderHook(() => useSelectedOrganizationStore());
|
|
expect(result.current.organizationId).toBeNull();
|
|
});
|
|
|
|
it("should update organizationId when setOrganizationId is called", () => {
|
|
const { result } = renderHook(() => useSelectedOrganizationStore());
|
|
|
|
act(() => {
|
|
result.current.setOrganizationId("org-123");
|
|
});
|
|
|
|
expect(result.current.organizationId).toBe("org-123");
|
|
});
|
|
|
|
it("should allow setting organizationId to null", () => {
|
|
const { result } = renderHook(() => useSelectedOrganizationStore());
|
|
|
|
act(() => {
|
|
result.current.setOrganizationId("org-123");
|
|
});
|
|
|
|
expect(result.current.organizationId).toBe("org-123");
|
|
|
|
act(() => {
|
|
result.current.setOrganizationId(null);
|
|
});
|
|
|
|
expect(result.current.organizationId).toBeNull();
|
|
});
|
|
|
|
it("should share state across multiple hook instances", () => {
|
|
const { result: result1 } = renderHook(() =>
|
|
useSelectedOrganizationStore(),
|
|
);
|
|
const { result: result2 } = renderHook(() =>
|
|
useSelectedOrganizationStore(),
|
|
);
|
|
|
|
act(() => {
|
|
result1.current.setOrganizationId("shared-organization");
|
|
});
|
|
|
|
expect(result2.current.organizationId).toBe("shared-organization");
|
|
});
|
|
});
|