From c006a94c4db580603843c773a843fc9306186d24 Mon Sep 17 00:00:00 2001 From: Ilia Mashkov Date: Tue, 24 Mar 2026 19:57:27 +0300 Subject: [PATCH] feat(auth): add selectStatusIsLoading selector to get information whether auth store status equals "loading" --- src/features/auth/model/selectors/index.ts | 1 + .../selectStatusIsLoading.spec.ts | 18 ++++++++++++++++++ .../selectStatusIsLoading.ts | 4 ++++ 3 files changed, 23 insertions(+) create mode 100644 src/features/auth/model/selectors/selectStatusIsLoading/selectStatusIsLoading.spec.ts create mode 100644 src/features/auth/model/selectors/selectStatusIsLoading/selectStatusIsLoading.ts diff --git a/src/features/auth/model/selectors/index.ts b/src/features/auth/model/selectors/index.ts index f81592d..9358ad5 100644 --- a/src/features/auth/model/selectors/index.ts +++ b/src/features/auth/model/selectors/index.ts @@ -1,2 +1,3 @@ export * from "./selectFormValid/selectFormValid"; export * from "./selectAuthData/selectAuthData"; +export * from "./selectStatusIsLoading/selectStatusIsLoading"; diff --git a/src/features/auth/model/selectors/selectStatusIsLoading/selectStatusIsLoading.spec.ts b/src/features/auth/model/selectors/selectStatusIsLoading/selectStatusIsLoading.spec.ts new file mode 100644 index 0000000..495b1bd --- /dev/null +++ b/src/features/auth/model/selectors/selectStatusIsLoading/selectStatusIsLoading.spec.ts @@ -0,0 +1,18 @@ +import { useAuthStore } from "../../stores"; +import { selectStatusIsLoading } from "./selectStatusIsLoading"; + +describe("selectStatusIsLoading", () => { + afterEach(() => { + useAuthStore.getState().reset(); + }); + + it("should return true when status is 'loading'", () => { + useAuthStore.setState({ status: "loading" }); + expect(selectStatusIsLoading(useAuthStore.getState())).toBe(true); + }); + + it("should return false when status is not 'loading'", () => { + useAuthStore.setState({ status: "idle" }); + expect(selectStatusIsLoading(useAuthStore.getState())).toBe(false); + }); +}); diff --git a/src/features/auth/model/selectors/selectStatusIsLoading/selectStatusIsLoading.ts b/src/features/auth/model/selectors/selectStatusIsLoading/selectStatusIsLoading.ts new file mode 100644 index 0000000..c30f6a1 --- /dev/null +++ b/src/features/auth/model/selectors/selectStatusIsLoading/selectStatusIsLoading.ts @@ -0,0 +1,4 @@ +import type { AuthStore } from "../../types/store"; + +export const selectStatusIsLoading = (state: AuthStore) => + state.status === "loading";