2023-02-12 02:07:28 +02:00
|
|
|
import React from "react";
|
|
|
|
import { renderHook } from "@testing-library/react-hooks";
|
|
|
|
import { TuitioContext } from "../../src/contexts";
|
|
|
|
import { useTuitioUser } from "../../src/hooks";
|
|
|
|
|
2023-02-12 03:27:22 +02:00
|
|
|
describe("useTuitioUser: positive flow", () => {
|
2023-02-12 02:07:28 +02:00
|
|
|
it("should return the userName and lastLoginDate from the TuitioContext", () => {
|
|
|
|
const testState = {
|
|
|
|
userName: "test-user",
|
|
|
|
token: {
|
|
|
|
raw: "mocked-token",
|
2023-02-12 03:27:22 +02:00
|
|
|
validFrom: new Date(2023, 1, 1),
|
|
|
|
validUntil: new Date(2023, 12, 31)
|
2023-02-12 02:07:28 +02:00
|
|
|
},
|
|
|
|
configuration: {
|
|
|
|
tuitioUrl: null
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const wrapper = ({ children }: { children?: React.ReactNode }) => (
|
|
|
|
<TuitioContext.Provider value={testState}>{children}</TuitioContext.Provider>
|
|
|
|
);
|
|
|
|
const { result } = renderHook(() => useTuitioUser(), { wrapper });
|
|
|
|
|
|
|
|
expect(result.current.userName).toEqual("test-user");
|
2023-02-12 03:27:22 +02:00
|
|
|
expect(result.current.lastLoginDate).toEqual(new Date(2023, 1, 1));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe("useTuitioUser: negative flow", () => {
|
|
|
|
it("should return the userName and lastLoginDate from the TuitioContext", () => {
|
|
|
|
const testState = {
|
|
|
|
userName: "test-user",
|
|
|
|
token: null,
|
|
|
|
configuration: {
|
|
|
|
tuitioUrl: null
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const wrapper = ({ children }: { children?: React.ReactNode }) => (
|
|
|
|
<TuitioContext.Provider value={testState}>{children}</TuitioContext.Provider>
|
|
|
|
);
|
|
|
|
const { result } = renderHook(() => useTuitioUser(), { wrapper });
|
|
|
|
|
|
|
|
expect(result.current.userName).toEqual("test-user");
|
|
|
|
expect(result.current.lastLoginDate).toBe(undefined);
|
2023-02-12 02:07:28 +02:00
|
|
|
});
|
|
|
|
});
|