Skip to content

Commit

Permalink
issue #430: disable edit and discard buttons for confirmed inspections
Browse files Browse the repository at this point in the history
  • Loading branch information
k-allagbe committed Feb 14, 2025
1 parent c0feea6 commit 79ac104
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/app/label-inspections/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ function InspectionPage() {
data-testid="discard-button"
text={t("discard")}
aria-label={t("alt.discard")}
// disabled={labelData?.confirmed}
disabled={labelData?.confirmed}
loading={discardLoading}
/>
</Box>
Expand Down
28 changes: 26 additions & 2 deletions src/app/label-inspections/__tests__/page.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { RegistrationType } from "@/types/types";
import { VERIFIED_LABEL_DATA_WITH_ID } from "@/utils/client/constants";
import {
CONFIRMED_LABEL_DATA,
VERIFIED_LABEL_DATA_WITH_ID,
} from "@/utils/client/constants";
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import axios from "axios";
import { useRouter } from "next/navigation";
Expand Down Expand Up @@ -189,7 +192,9 @@ describe("InspectionPage", () => {
expect(axios.delete).not.toHaveBeenCalled();

await waitFor(() =>
expect(screen.queryByText("confirmDiscardMessage")).not.toBeInTheDocument(),
expect(
screen.queryByText("confirmDiscardMessage"),
).not.toBeInTheDocument(),
);
});

Expand Down Expand Up @@ -218,4 +223,23 @@ describe("InspectionPage", () => {

expect(mockRouter.push).not.toHaveBeenCalled();
});

it("disables edit and discard buttons when inspection is confirmed", async () => {
(axios.get as jest.Mock).mockResolvedValue({
data: CONFIRMED_LABEL_DATA,
});

render(<InspectionPage />);
await waitFor(() =>
expect(
screen.getByText(CONFIRMED_LABEL_DATA.inspectionId),
).toBeInTheDocument(),
);

const editButton = screen.getByTestId("edit-button");
const discardButton = screen.getByTestId("discard-button");

expect(editButton).toBeDisabled();
expect(discardButton).toBeDisabled();
});
});
7 changes: 4 additions & 3 deletions src/stores/labelDataStore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { LabelData } from "@/types/types";
import { VERIFIED_LABEL_DATA } from "@/utils/client/constants";
import { create } from "zustand";

interface LabelDataState {
Expand All @@ -9,7 +10,7 @@ interface LabelDataState {
}

const useLabelDataStore = create<LabelDataState>((set) => ({
labelData: null,
labelData: VERIFIED_LABEL_DATA,

setLabelData: (newData) => {
console.debug(`[Label Store] Set label data:`, newData);
Expand All @@ -19,13 +20,13 @@ const useLabelDataStore = create<LabelDataState>((set) => ({
setComment: (comment) => {
console.debug(`[Label Store] Set comment:`, comment);
set((state) => ({
labelData: state.labelData ? { ...state.labelData, comment } : null,
labelData: state.labelData ? { ...state.labelData, comment } : VERIFIED_LABEL_DATA,
}));
},

resetLabelData: () => {
console.debug(`[Label Store] Reset label data`);
set({ labelData: null });
set({ labelData: VERIFIED_LABEL_DATA });
},
}));

Expand Down

0 comments on commit 79ac104

Please sign in to comment.