diff --git a/src/components/app/MenuButtons/index.js b/src/components/app/MenuButtons/index.js index c5987f06fb..062bbc7cb6 100644 --- a/src/components/app/MenuButtons/index.js +++ b/src/components/app/MenuButtons/index.js @@ -89,7 +89,7 @@ type DispatchProps = {| type Props = ConnectedProps; type State = $ReadOnly<{| - metaInfoPanelState: 'initial' | 'delete-confirmation' | 'profile-deleted', + metaInfoPanelState: 'initial' | 'delete-confirmation', |}>; class MenuButtonsImpl extends React.PureComponent { @@ -129,9 +129,6 @@ class MenuButtonsImpl extends React.PureComponent { _onProfileDeleted = () => { this.props.profileRemotelyDeleted(); - this.setState({ - metaInfoPanelState: 'profile-deleted', - }); }; _resetMetaInfoState = () => { @@ -196,42 +193,37 @@ class MenuButtonsImpl extends React.PureComponent { ); } - case 'delete-confirmation': { - if (!currentProfileUploadedInformation) { - throw new Error( - `We're in the state "delete-confirmation" but there's no stored data for this profile, this should not happen.` - ); - } - - const { name, profileToken, jwtToken } = - currentProfileUploadedInformation; - - if (!jwtToken) { - throw new Error( - `We're in the state "delete-confirmation" but there's no JWT token for this profile, this should not happen.` + case 'delete-confirmation': + if (currentProfileUploadedInformation) { + const { name, profileToken, jwtToken } = + currentProfileUploadedInformation; + + if (!jwtToken) { + throw new Error( + `We're in the state "delete-confirmation" but there's no JWT token for this profile, this should not happen.` + ); + } + + const slicedProfileToken = profileToken.slice(0, 6); + const profileName = name ? name : `Profile #${slicedProfileToken}`; + return ( + ); } - const slicedProfileToken = profileToken.slice(0, 6); - const profileName = name ? name : `Profile #${slicedProfileToken}`; - return ( - - ); - } + // The profile data has been deleted - case 'profile-deleted': // Note that can also render // in some situations. However it's not suitable for this case, because // we still have to pass jwtToken / profileToken, and we don't have // these values anymore when we're in this state. return ; - default: throw assertExhaustiveCheck(metaInfoPanelState); } diff --git a/src/test/components/ProfileName.test.js b/src/test/components/ProfileName.test.js index a57571cbd3..6d16b8dd7e 100644 --- a/src/test/components/ProfileName.test.js +++ b/src/test/components/ProfileName.test.js @@ -75,7 +75,7 @@ describe('ProfileName', function () { expect(getProfileNameFromUrl(getState())).toBe(null); // Click the button to activate it. - button.click(); + fireEvent.click(button); const input = getByDisplayValue(defaultName); expect(queryByText('Custom name')).not.toBeInTheDocument(); @@ -92,7 +92,7 @@ describe('ProfileName', function () { withAnalyticsMock(() => { const { getByText, getByDisplayValue } = setup(); const button = getByText(defaultName); - button.click(); + fireEvent.click(button); const input = getByDisplayValue(defaultName); fireEvent.change(input, { target: { value: 'Custom name' } }); fireEvent.blur(input);