Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "Profile Update Not Working on Admin Portal #1508" #1698

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/GraphQl/Mutations/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,16 @@ export const UPDATE_USER_MUTATION = gql`
$firstName: String
$lastName: String
$email: EmailAddress
$appLanguageCode: String
$file: String
) {
updateUserProfile(
data: { firstName: $firstName, lastName: $lastName, email: $email }
data: {
firstName: $firstName
lastName: $lastName
email: $email
appLanguageCode: $appLanguageCode
}
file: $file
) {
_id
Expand Down
44 changes: 23 additions & 21 deletions src/components/UserUpdate/UserUpdate.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,28 @@ describe('Testing User Update', () => {

global.alert = jest.fn();

test('should display warnings for blank form submission', async () => {
jest.spyOn(toast, 'warning');

render(
<MockedProvider addTypename={false} link={link}>
<I18nextProvider i18n={i18nForTest}>
<Router>
<UserUpdate {...props} />
</Router>
</I18nextProvider>
</MockedProvider>,
);

await wait();

userEvent.click(screen.getByText(/Save Changes/i));

expect(toast.warning).toHaveBeenCalledWith('First Name cannot be blank!');
expect(toast.warning).toHaveBeenCalledWith('Last Name cannot be blank!');
expect(toast.warning).toHaveBeenCalledWith('Email cannot be blank!');
});

test('should render props and text elements test for the page component', async () => {
render(
<MockedProvider addTypename={false} link={link}>
Expand All @@ -115,6 +137,7 @@ describe('Testing User Update', () => {
);
userEvent.type(screen.getByPlaceholderText(/Email/i), formData.email);
userEvent.selectOptions(screen.getByTestId('applangcode'), 'Français');

userEvent.upload(screen.getByLabelText(/Display Image:/i), formData.image);
await wait();

Expand All @@ -134,25 +157,4 @@ describe('Testing User Update', () => {
expect(screen.getByPlaceholderText(/Email/i)).toBeInTheDocument();
expect(screen.getByText(/Display Image/i)).toBeInTheDocument();
});
test('should display warnings for blank form submission', async () => {
jest.spyOn(toast, 'warning');

render(
<MockedProvider addTypename={false} link={link}>
<I18nextProvider i18n={i18nForTest}>
<Router>
<UserUpdate {...props} />
</Router>
</I18nextProvider>
</MockedProvider>,
);

await wait();

userEvent.click(screen.getByText(/Save Changes/i));

expect(toast.warning).toHaveBeenCalledWith('First Name cannot be blank!');
expect(toast.warning).toHaveBeenCalledWith('Last Name cannot be blank!');
expect(toast.warning).toHaveBeenCalledWith('Email cannot be blank!');
});
});
13 changes: 6 additions & 7 deletions src/components/UserUpdate/UserUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const UserUpdate: React.FC<InterfaceUserUpdateProps> = ({
lastName: '',
email: '',
password: '',
applangcode: '',
appLanguageCode: '',
file: '',
});

Expand All @@ -56,7 +56,7 @@ const UserUpdate: React.FC<InterfaceUserUpdateProps> = ({
firstName: data?.user?.firstName,
lastName: data?.user?.lastName,
email: data?.user?.email,
applangcode: data?.user?.applangcode,
appLanguageCode: data?.user?.appLanguageCode,
});
}
}, [data]);
Expand All @@ -75,7 +75,7 @@ const UserUpdate: React.FC<InterfaceUserUpdateProps> = ({
const firstName = formState.firstName;
const lastName = formState.lastName;
const email = formState.email;
const applangcode = formState.applangcode;
const appLanguageCode = formState.appLanguageCode;
const file = formState.file;
let toSubmit = true;
if (firstName.trim().length == 0 || !firstName) {
Expand All @@ -98,7 +98,7 @@ const UserUpdate: React.FC<InterfaceUserUpdateProps> = ({
firstName,
lastName,
email,
applangcode,
appLanguageCode,
file,
},
});
Expand All @@ -109,7 +109,7 @@ const UserUpdate: React.FC<InterfaceUserUpdateProps> = ({
lastName: '',
email: '',
password: '',
applangcode: '',
appLanguageCode: '',
file: '',
});

Expand Down Expand Up @@ -138,7 +138,6 @@ const UserUpdate: React.FC<InterfaceUserUpdateProps> = ({
<>
<div id="userupdate" className={styles.userupdatediv}>
<form>
{/* <h3 className={styles.settingstitle}>Update Your Details</h3> */}
<div className={styles.dispflex}>
<div>
<label>{t('firstName')}</label>
Expand Down Expand Up @@ -207,7 +206,7 @@ const UserUpdate: React.FC<InterfaceUserUpdateProps> = ({
onChange={(e): void => {
setFormState({
...formState,
applangcode: e.target.value,
appLanguageCode: e.target.value,
});
}}
>
Expand Down
Loading