@thepalaceproject/circulation-admin 1.22.0-post.1 → 1.22.0-post.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
2
|
+
import {
|
|
3
|
+
useAppAdmin,
|
|
4
|
+
useAppContext,
|
|
5
|
+
useAppEmail,
|
|
6
|
+
useAppFeatureFlags,
|
|
7
|
+
useCsrfToken,
|
|
8
|
+
} from "../../../src/context/appContext";
|
|
9
|
+
import { componentWithProviders } from "../testUtils/withProviders";
|
|
10
|
+
import { ContextProviderProps } from "../../../src/components/ContextProvider";
|
|
11
|
+
import { FeatureFlags } from "../../../src/interfaces";
|
|
12
|
+
|
|
13
|
+
// TODO: These tests may need to be adjusted in the future.
|
|
14
|
+
// Currently, an AppContext.Provider is injected into the component tree
|
|
15
|
+
// by the ContextProvider, which itself uses a legacy context API. (See
|
|
16
|
+
// https://legacy.reactjs.org/docs/legacy-context.html)
|
|
17
|
+
// but that will change once uses of that API have been removed.
|
|
18
|
+
|
|
19
|
+
describe("AppContext", () => {
|
|
20
|
+
const expectedCsrfToken = "token";
|
|
21
|
+
const expectedEmail = "email";
|
|
22
|
+
const expectedFeatureFlags: FeatureFlags = {
|
|
23
|
+
// @ts-expect-error - "testTrue" & "testFalse" aren't valid feature flags
|
|
24
|
+
testTrue: true,
|
|
25
|
+
testFalse: false,
|
|
26
|
+
};
|
|
27
|
+
const expectedRoles = [{ role: "system" }];
|
|
28
|
+
|
|
29
|
+
const contextProviderProps: ContextProviderProps = {
|
|
30
|
+
csrfToken: expectedCsrfToken,
|
|
31
|
+
featureFlags: expectedFeatureFlags,
|
|
32
|
+
roles: expectedRoles,
|
|
33
|
+
email: expectedEmail,
|
|
34
|
+
};
|
|
35
|
+
const wrapper = componentWithProviders({ contextProviderProps });
|
|
36
|
+
|
|
37
|
+
it("provides useAppContext context hook", () => {
|
|
38
|
+
const { result } = renderHook(() => useAppContext(), { wrapper });
|
|
39
|
+
const value = result.current;
|
|
40
|
+
expect(value.csrfToken).toEqual(expectedCsrfToken);
|
|
41
|
+
expect(value.admin.email).toEqual(expectedEmail);
|
|
42
|
+
expect(value.admin.roles).toEqual(expectedRoles);
|
|
43
|
+
expect(value.featureFlags).toEqual(expectedFeatureFlags);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("provides useAppAdmin context hook", () => {
|
|
47
|
+
const { result } = renderHook(() => useAppAdmin(), { wrapper });
|
|
48
|
+
const admin = result.current;
|
|
49
|
+
expect(admin.email).toEqual(expectedEmail);
|
|
50
|
+
expect(admin.roles).toEqual(expectedRoles);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("provides useAppEmail context hook", () => {
|
|
54
|
+
const { result } = renderHook(() => useAppEmail(), { wrapper });
|
|
55
|
+
const email = result.current;
|
|
56
|
+
expect(email).toEqual(expectedEmail);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("provides useCsrfToken context hook", () => {
|
|
60
|
+
const { result } = renderHook(() => useCsrfToken(), { wrapper });
|
|
61
|
+
const token = result.current;
|
|
62
|
+
expect(token).toEqual(expectedCsrfToken);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("provides useAppFeatureFlags context hook", () => {
|
|
66
|
+
const { result } = renderHook(() => useAppFeatureFlags(), {
|
|
67
|
+
wrapper,
|
|
68
|
+
});
|
|
69
|
+
const flags = result.current;
|
|
70
|
+
expect(flags).toEqual(expectedFeatureFlags);
|
|
71
|
+
});
|
|
72
|
+
});
|