Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Read the app slice instead of current-user in the redux hooks spec (#81841)

Fraser0337de20c199
diff --git a/frontend/src/metabase/redux/hooks.unit.spec.tsx b/frontend/src/metabase/redux/hooks.unit.spec.tsx
index 18eac858469..5ab125f77c4 100644
--- a/frontend/src/metabase/redux/hooks.unit.spec.tsx
+++ b/frontend/src/metabase/redux/hooks.unit.spec.tsx
@@ -1,27 +1,25 @@
import { renderWithProviders, screen } from "__support__/ui";
-import { getUser } from "metabase/current-user";
import type { State } from "metabase/redux/store";
-import { createMockUser } from "metabase-types/api/mocks";
+import { createMockAppState } from "metabase/redux/store/mocks";
import { useDispatch, useSelector } from "./hooks";
-const DEFAULT_USER = createMockUser({ email: undefined });
-const TEST_EMAIL = "[email protected]";
+const getIsNavbarOpen = (state: State) => state.app.isNavbarOpen;
describe("useSelector", () => {
it("should allow access to redux store", () => {
const Component = () => {
- const email = useSelector((state) => getUser(state)?.email);
- return <>{email || "No email found"}</>;
+ const isNavbarOpen = useSelector((state) => getIsNavbarOpen(state));
+ return <>{isNavbarOpen ? "Navbar open" : "Navbar closed"}</>;
};
renderWithProviders(<Component />, {
storeInitialState: {
- currentUser: { ...DEFAULT_USER, email: TEST_EMAIL },
+ app: createMockAppState({ isNavbarOpen: false }),
},
});
- expect(screen.getByText(TEST_EMAIL)).toBeInTheDocument();
- expect(screen.queryByText("No email found")).not.toBeInTheDocument();
+ expect(screen.getByText("Navbar closed")).toBeInTheDocument();
+ expect(screen.queryByText("Navbar open")).not.toBeInTheDocument();
});
});
@@ -49,21 +47,20 @@ describe("useDispatch", () => {
});
it("should properly dispatch thunks that use `getState`", () => {
- const foundEmailState = jest.fn();
- const didNotFindEmailState = jest.fn();
+ const foundNavbarOpenState = jest.fn();
+ const didNotFindNavbarOpenState = jest.fn();
setup({
thunk: () => (_dispatch: any, getState: () => State) => {
- const email = getUser(getState())?.email;
- if (email) {
- foundEmailState();
+ if (getIsNavbarOpen(getState())) {
+ foundNavbarOpenState();
} else {
- didNotFindEmailState();
+ didNotFindNavbarOpenState();
}
},
});
- expect(foundEmailState).toHaveBeenCalled();
- expect(didNotFindEmailState).not.toHaveBeenCalled();
+ expect(foundNavbarOpenState).toHaveBeenCalled();
+ expect(didNotFindNavbarOpenState).not.toHaveBeenCalled();
});
it("should properly dispatch thunks that use `dispatch`", () => {