From 385dd3325b171a72fa9f3472d91e5c4c0f0537e1 Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Sun, 12 Feb 2023 02:07:28 +0200 Subject: [PATCH] useTuitioUser test --- tests/hooks/useTuitioUser.test.tsx | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/hooks/useTuitioUser.test.tsx diff --git a/tests/hooks/useTuitioUser.test.tsx b/tests/hooks/useTuitioUser.test.tsx new file mode 100644 index 0000000..53dc0fe --- /dev/null +++ b/tests/hooks/useTuitioUser.test.tsx @@ -0,0 +1,28 @@ +import React from "react"; +import { renderHook } from "@testing-library/react-hooks"; +import { TuitioContext } from "../../src/contexts"; +import { useTuitioUser } from "../../src/hooks"; + +describe("useTuitioUser", () => { + it("should return the userName and lastLoginDate from the TuitioContext", () => { + const testState = { + userName: "test-user", + token: { + raw: "mocked-token", + validFrom: new Date(2022, 1, 1), + validUntil: new Date(2022, 12, 31) + }, + configuration: { + tuitioUrl: null + } + }; + + const wrapper = ({ children }: { children?: React.ReactNode }) => ( + {children} + ); + const { result } = renderHook(() => useTuitioUser(), { wrapper }); + + expect(result.current.userName).toEqual("test-user"); + expect(result.current.lastLoginDate).toEqual(new Date(2022, 1, 1)); + }); +});