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
parent
7ae50dbce5
commit
2ed9b2e95e
|
@ -131,6 +131,7 @@ const UserProfileSettings: React.FC = () => {
|
|||
setInitialDisplayName(displayName);
|
||||
} catch (e) {
|
||||
setDisplayNameError(true);
|
||||
throw e;
|
||||
}
|
||||
}, [displayName, client]);
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
Loading…
Reference in New Issue