fix: grading settings save button stuck in pending state (#2614)

This commit is contained in:
Muhammad Anas
2025-11-14 18:54:57 +05:00
committed by GitHub
parent a1abd43a11
commit 7cf01de84c
2 changed files with 24 additions and 1 deletions

View File

@@ -42,7 +42,7 @@ const GradingSettings = ({ courseId }) => {
} = useCourseSettings(courseId);
const {
mutate: updateGradingSettings,
isLoading: savePending,
isPending: savePending,
isSuccess: savingStatus,
isError: savingFailed,
} = useGradingSettingUpdater(courseId);

View File

@@ -39,6 +39,9 @@ describe('<GradingSettings />', () => {
},
});
// jsdom doesn't implement scrollTo; mock to avoid noisy console errors.
Object.defineProperty(window, 'scrollTo', { value: jest.fn(), writable: true });
store = initializeStore();
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
axiosMock
@@ -99,6 +102,26 @@ describe('<GradingSettings />', () => {
testSaving();
});
it('should show success alert and hide save prompt after successful save', async () => {
// Trigger change to show save prompt
const segmentInputs = await screen.findAllByTestId('grading-scale-segment-input');
const segmentInput = segmentInputs[2];
fireEvent.change(segmentInput, { target: { value: 'PatchTest' } });
// Click save and verify pending state appears
const saveBtnInitial = screen.getByText(messages.buttonSaveText.defaultMessage);
fireEvent.click(saveBtnInitial);
expect(screen.getByText(messages.buttonSavingText.defaultMessage)).toBeInTheDocument();
// Wait for success alert to appear (mutation success)
const successAlert = await screen.findByText(messages.alertSuccess.defaultMessage);
expect(successAlert).toBeVisible();
// Pending label should disappear and save prompt should be hidden (button removed)
expect(screen.queryByText(messages.buttonSavingText.defaultMessage)).toBeNull();
const saveAlert = screen.queryByTestId('grading-settings-save-alert');
expect(saveAlert).toBeNull();
// Ensure original save button text is no longer present because the prompt closed
expect(screen.queryByText(messages.buttonSaveText.defaultMessage)).toBeNull();
});
it('should handle being offline gracefully', async () => {
setOnlineStatus(false);
const segmentInputs = await screen.findAllByTestId('grading-scale-segment-input');