Don't show 'saved' on display name save error (#12600)

The save callback nees to throw on an error so the EditInPlace
component knows it's not been successful.
pull/28217/head
David Baker 2024-06-13 09:54:38 +01:00 committed by GitHub
parent 7ae50dbce5
commit 2ed9b2e95e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View File

@ -131,6 +131,7 @@ const UserProfileSettings: React.FC = () => {
setInitialDisplayName(displayName); setInitialDisplayName(displayName);
} catch (e) { } catch (e) {
setDisplayNameError(true); setDisplayNameError(true);
throw e;
} }
}, [displayName, client]); }, [displayName, client]);

View File

@ -167,6 +167,25 @@ describe("ProfileSettings", () => {
expect(client.setDisplayName).toHaveBeenCalledWith("The Value"); expect(client.setDisplayName).toHaveBeenCalledWith("The Value");
}); });
it("displays error if changing display name fails", async () => {
jest.spyOn(OwnProfileStore.instance, "displayName", "get").mockReturnValue("Alice");
mocked(client).setDisplayName.mockRejectedValue(new Error("Failed to set display name"));
renderProfileSettings(toastRack, client);
expect(editInPlaceOnSave).toBeDefined();
act(() => {
editInPlaceOnChange({
target: { value: "Not Alice any more" } as HTMLInputElement,
} as ChangeEvent<HTMLInputElement>);
});
await act(async () => {
await expect(editInPlaceOnSave()).rejects.toEqual(expect.any(Error));
});
});
it("resets on cancel", async () => { it("resets on cancel", async () => {
jest.spyOn(OwnProfileStore.instance, "displayName", "get").mockReturnValue("Alice"); jest.spyOn(OwnProfileStore.instance, "displayName", "get").mockReturnValue("Alice");