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.
This commit is contained in:
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);
} catch (e) {
setDisplayNameError(true);
throw e;
}
}, [displayName, client]);

View file

@ -167,6 +167,25 @@ describe("ProfileSettings", () => {
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 () => {
jest.spyOn(OwnProfileStore.instance, "displayName", "get").mockReturnValue("Alice");