Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Don't show 'saved' on display name save error
Browse files Browse the repository at this point in the history
The save callback nees to throw on an error so the EditInPlace
component knows it's not been successful.
  • Loading branch information
dbkr committed Jun 11, 2024
1 parent 930b4e2 commit 5835a8c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/components/views/settings/UserProfileSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const UserProfileSettings: React.FC = () => {
setInitialDisplayName(displayName);
} catch (e) {
setDisplayNameError(true);
throw e;
}
}, [displayName, client]);

Expand Down
19 changes: 19 additions & 0 deletions test/components/views/settings/UserProfileSettings-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down

0 comments on commit 5835a8c

Please sign in to comment.