Skip to content

Commit

Permalink
resolve mismatch uri
Browse files Browse the repository at this point in the history
  • Loading branch information
wayneleon1 committed Jun 27, 2024
1 parent f85bd02 commit 4882768
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ jobs:
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
env:
VITE_BASE_URL: ${{ secrets.VITE_BASE_URL }}
8 changes: 3 additions & 5 deletions src/__test__/signInSlice.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('signInSlice', () => {
token: 'testToken',
loading: false,
error: null,
message: 'Login successful',
message: 'Logout Successfully',
role: 'Admin',
needsVerification: false,
needs2FA: false,
Expand Down Expand Up @@ -162,10 +162,9 @@ describe('SignIn Component', () => {
fireEvent.click(submitButton);

await waitFor(() => {
expect(screen.queryByText(/Loading.../i)).toBeInTheDocument();
expect(screen.getByTestId('Loading')).toBeInTheDocument();
});
});

it('displays error messages for invalid input', async () => {
const emailInput = screen.getByPlaceholderText('Enter your email');
const passwordInput = screen.getByPlaceholderText('Enter your password');
Expand Down Expand Up @@ -196,11 +195,10 @@ describe('SignIn Component', () => {
it('submits the form successfully', async () => {
const emailInput = screen.getByPlaceholderText('Enter your email');
const passwordInput = screen.getByPlaceholderText('Enter your password');
const submitButton = screen.getByText(/Sign In/);

fireEvent.change(emailInput, { target: { value: 'test@example.com' } });
fireEvent.change(passwordInput, { target: { value: 'password123' } });
fireEvent.click(submitButton);
fireEvent.submit(screen.getByTestId('form'));

await waitFor(() => {
expect(screen.queryByText(/Loading.../i)).not.toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export const initialState: SignInState = {
};

const apiUrl = `${import.meta.env.VITE_BASE_URL}/user/login`;

export const loginUser = createAsyncThunk<LoginResponse, Credentials>(
'signIn/loginUser',
async (credentials: Credentials, thunkAPI) => {
Expand All @@ -57,6 +56,7 @@ const signInSlice = createSlice({
initialState,
reducers: {
logout(state) {
localStorage.removeItem('token');
return {
...state,
token: null,
Expand Down Expand Up @@ -101,12 +101,12 @@ const signInSlice = createSlice({
};
}
);
//
builder.addCase(loginUser.rejected, (state, action: PayloadAction<any>) => {
return {
...state,
loading: false,
error: action.payload.message,
message: null,
needsVerification: action.payload.message.includes('verify your email'),
};
});
Expand Down
15 changes: 11 additions & 4 deletions src/pages/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useEffect } from 'react';
import { Link, useNavigate } from 'react-router-dom';
import { useFormik } from 'formik';
import * as yup from 'yup';
import BeatLoader from 'react-spinners/BeatLoader';
import { MdOutlineEmail } from 'react-icons/md';
import { PiLockKeyBold } from 'react-icons/pi';
import { FcGoogle } from 'react-icons/fc';
Expand Down Expand Up @@ -67,7 +68,7 @@ function SignIn() {
</h1>
{error && <p className="text-center text-red-500">{error}</p>}
{message && <p className="text-center text-green-500">{message}</p>}
<div className="flex flex-col gap-5">
<form className="flex flex-col gap-5" data-testid="form">
<div>
<HSInput
data-testid="email"
Expand Down Expand Up @@ -130,13 +131,19 @@ function SignIn() {
</div>
<Button
data-testid="Sign In"
title={loading ? 'Loading...' : 'Sign In'}
title={
loading ? (
<BeatLoader data-testid="Loading" color="#ffffff" size={8} />
) : (
'Sign In'
)
}
onClick={formik.handleSubmit}
/>
<div>
<p className="text-center">
Don&apos;t have an account?{' '}
<Link to="/" className="text-primary">
<Link to="/signUp" className="text-primary">
Sign up
</Link>
</p>
Expand All @@ -160,7 +167,7 @@ function SignIn() {
<FaFacebook color="white" size={16} />
</Link>
</div>
</div>
</form>
<Link to="/" className="text-primary font-light mt-4 block text-center">
&larr; Back to Home
</Link>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function SignUp() {
dispatch(registerUser(values))
.then(() => {
actions.setSubmitting(false);
navigate('/login');
navigate('/signIn');
})
.catch(() => {
actions.setSubmitting(false);
Expand Down Expand Up @@ -101,7 +101,7 @@ function SignUp() {
return (
<div className="flex justify-center items-center h-[90vh] sm:h-screen bg-white m-2">
<div className="w-[80%] md:w-[60%] lg:w-[40%] p-5 shadow-lg border-[1px] border-gray-300 rounded-md ">
<h1 className="text-center font-bold text-3xl mb-4 text-xl">Sign Up</h1>
<h1 className="text-center font-bold text-3xl mb-4 ">Sign Up</h1>
<Formik
initialValues={{
firstName: '',
Expand Down

0 comments on commit 4882768

Please sign in to comment.