From 511d6fcafdb344a368e1a908b59f87e7558e6569 Mon Sep 17 00:00:00 2001 From: Jonas Hungershausen Date: Mon, 18 Nov 2024 11:28:21 +0100 Subject: [PATCH] chore: add more missing tests --- .../src/context/form-state.test.ts | 11 +++++++ .../utils/__tests__/attributes.test.ts | 31 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 packages/elements-react/src/theme/default/utils/__tests__/attributes.test.ts diff --git a/packages/elements-react/src/context/form-state.test.ts b/packages/elements-react/src/context/form-state.test.ts index d029fad0..876d4ce4 100644 --- a/packages/elements-react/src/context/form-state.test.ts +++ b/packages/elements-react/src/context/form-state.test.ts @@ -17,6 +17,17 @@ test('should initialize with "provide_identifier" state', () => { expect(state).toEqual({ current: "provide_identifier" }) }) +test('should initialize with "settings" state for settings flows', () => { + const { result } = renderHook(() => + useFormStateReducer({ + flowType: FlowType.Settings, + } as unknown as OryFlowContainer), + ) + + const [state] = result.current + expect(state).toEqual({ current: "settings" }) +}) + test('should transition to "method_active" state when "action_select_method" is dispatched', () => { const { result } = renderHook(() => useFormStateReducer(init)) const [, dispatch] = result.current diff --git a/packages/elements-react/src/theme/default/utils/__tests__/attributes.test.ts b/packages/elements-react/src/theme/default/utils/__tests__/attributes.test.ts new file mode 100644 index 00000000..fda1d3e1 --- /dev/null +++ b/packages/elements-react/src/theme/default/utils/__tests__/attributes.test.ts @@ -0,0 +1,31 @@ +import { omit } from "../attributes" + +test("deletes keys from object", () => { + const obj = { + a: 1, + b: 2, + c: 3, + } + const result = omit(obj, ["a", "c"]) + expect(result).toEqual({ b: 2 }) +}) + +test("ignores unknown keys", () => { + const obj = { + a: 1, + b: 2, + c: 3, + } + const result = omit(obj, ["a", "x"] as (keyof typeof obj)[]) + expect(result).toEqual({ b: 2, c: 3 }) +}) + +test("returns object if keys are empty", () => { + const obj = { + a: 1, + b: 2, + c: 3, + } + const result = omit(obj, []) + expect(result).toEqual({ a: 1, b: 2, c: 3 }) +})