Skip to content

Commit

Permalink
fix the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
devksingh4 committed Jan 27, 2025
1 parent f371415 commit 332bbf5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/ui/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ const ErrorBoundary: React.FC<ErrorBoundaryProps> = ({ children }) => {

export const Router: React.FC = () => {
const { isLoggedIn } = useAuth();
console.log(isLoggedIn);
const router = isLoggedIn
? authenticatedRouter
: isLoggedIn === null
Expand Down
5 changes: 0 additions & 5 deletions src/ui/components/AuthContext/AuthCallbackHandler.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ export const AuthCallback: React.FC = () => {
setTimeout(() => {
handleCallback();
}, 100);

// Cleanup function
return () => {
console.log('Callback component unmounting'); // Debug log 8
};
}, [instance, navigate]);

return <FullScreenLoader />;
Expand Down
19 changes: 9 additions & 10 deletions src/ui/pages/profile/ManageProfileComponent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('ManageProfileComponent tests', () => {

await renderComponent(getProfile, setProfile);

expect(screen.getByText(/Loading.../i)).toBeInTheDocument();
expect(screen.getByTestId('profile-loading')).toBeInTheDocument();
});

it('renders profile form after successfully fetching profile', async () => {
Expand All @@ -53,11 +53,11 @@ describe('ManageProfileComponent tests', () => {

await renderComponent(getProfile, setProfile);

expect(screen.getByLabelText('Display Name')).toHaveValue('John Doe');
expect(screen.getByLabelText('First Name')).toHaveValue('John');
expect(screen.getByLabelText('Last Name')).toHaveValue('Doe');
expect(screen.getByLabelText('Email')).toHaveValue('john.doe@example.com');
expect(screen.getByLabelText('Discord Username')).toHaveValue('johndoe#1234');
expect(screen.getByTestId('edit-displayName')).toHaveValue('John Doe');
expect(screen.getByTestId('edit-firstName')).toHaveValue('John');
expect(screen.getByTestId('edit-lastName')).toHaveValue('Doe');
expect(screen.getByTestId('edit-email')).toHaveValue('john.doe@example.com');
expect(screen.getByTestId('edit-discordUsername')).toHaveValue('johndoe#1234');
});

it('handles profile fetch failure gracefully', async () => {
Expand All @@ -67,7 +67,6 @@ describe('ManageProfileComponent tests', () => {

await renderComponent(getProfile, setProfile);

expect(screen.getByText(/Failed to load user profile/i)).toBeInTheDocument();
expect(notificationsMock).toHaveBeenCalledWith(
expect.objectContaining({
message: 'Failed to load user profile',
Expand All @@ -94,9 +93,9 @@ describe('ManageProfileComponent tests', () => {
const user = userEvent.setup();

// Edit fields
await user.clear(screen.getByLabelText('Display Name'));
await user.type(screen.getByLabelText('Display Name'), 'Jane Doe');
await user.type(screen.getByLabelText('Discord Username'), 'janedoe#5678');
await user.clear(screen.getByTestId('edit-displayName'));
await user.type(screen.getByTestId('edit-displayName'), 'Jane Doe');
await user.type(screen.getByTestId('edit-discordUsername'), 'janedoe#5678');

// Save changes
const saveButton = screen.getByRole('button', { name: 'Save' });
Expand Down
7 changes: 6 additions & 1 deletion src/ui/pages/profile/ManageProfileComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const ManageProfileComponent: React.FC<ManageProfileComponentProps> = ({
};

if (userProfile === undefined) {
return <LoadingOverlay visible={true} />;
return <LoadingOverlay visible={true} data-testId="profile-loading" />;
}

return (
Expand Down Expand Up @@ -91,6 +91,7 @@ export const ManageProfileComponent: React.FC<ManageProfileComponentProps> = ({
}
placeholder={userProfile?.displayName}
required
data-testId="edit-displayName"
/>
<TextInput
label="First Name"
Expand All @@ -100,13 +101,15 @@ export const ManageProfileComponent: React.FC<ManageProfileComponentProps> = ({
}
placeholder={userProfile?.givenName}
required
data-testId="edit-firstName"
/>
<TextInput
label="Last Name"
value={userProfile?.surname || ''}
onChange={(e) => setUserProfile((prev) => prev && { ...prev, surname: e.target.value })}
placeholder={userProfile?.surname}
required
data-testId="edit-lastName"
/>
<TextInput
label="Email"
Expand All @@ -115,6 +118,7 @@ export const ManageProfileComponent: React.FC<ManageProfileComponentProps> = ({
placeholder={userProfile?.mail}
required
disabled
data-testId="edit-email"
/>

<TextInput
Expand All @@ -123,6 +127,7 @@ export const ManageProfileComponent: React.FC<ManageProfileComponentProps> = ({
onChange={(e) =>
setUserProfile((prev) => prev && { ...prev, discordUsername: e.target.value })
}
data-testId="edit-discordUsername"
/>

<Group mt="md">
Expand Down

0 comments on commit 332bbf5

Please sign in to comment.