Skip to content

Commit

Permalink
Merge pull request #2 from Messaging-Application/MA-16-user-registration
Browse files Browse the repository at this point in the history
MA 16 - user registration
  • Loading branch information
nefelitav authored Feb 21, 2024
2 parents c9ddbe1 + 262b74c commit 576869e
Show file tree
Hide file tree
Showing 9 changed files with 529 additions and 8 deletions.
5 changes: 1 addition & 4 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
'react-refresh/only-export-components':"off",
},
}
159 changes: 159 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
"identity-obj-proxy": "^3.0.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-fetch-mock": "^3.0.3",
"node-fetch": "^3.3.2",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"typescript": "^5.2.2",
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/Login.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { render, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom'
import fetchMock from 'jest-fetch-mock';
fetchMock.enableMocks();

import Login from '../components/Login';

Expand Down
67 changes: 67 additions & 0 deletions src/__tests__/Register.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { render, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom'

import Register from '../components/Register';

describe('Register component', () => {
test('renders username, password, confirm fields', () => {
const { getByLabelText } = render(<Register />);
const usernameInput = getByLabelText('Username');
const passwordInput = getByLabelText('Password');
const confirmInput = getByLabelText('Confirm Password');
const emailInput = getByLabelText('Email');
const firstnameInput = getByLabelText('Firstname');
const lastnameInput = getByLabelText('Lastname');

expect(emailInput).toBeInTheDocument();
expect(firstnameInput).toBeInTheDocument();
expect(lastnameInput).toBeInTheDocument();
expect(usernameInput).toBeInTheDocument();
expect(passwordInput).toBeInTheDocument();
expect(confirmInput).toBeInTheDocument();
});

test('allows user to enter username, password, confirm', () => {
const { getByLabelText } = render(<Register />);
const usernameInput = getByLabelText('Username');
const passwordInput = getByLabelText('Password');
const confirmInput = getByLabelText('Confirm Password');
const emailInput = getByLabelText('Email');
const firstnameInput = getByLabelText('Firstname');
const lastnameInput = getByLabelText('Lastname');

fireEvent.change(usernameInput, { target: { value: 'testuser' } });
fireEvent.change(passwordInput, { target: { value: 'testpassword' } });
fireEvent.change(confirmInput, { target: { value: 'testpassword2' } });
fireEvent.change(emailInput, { target: { value: '[email protected]' } });
fireEvent.change(firstnameInput, { target: { value: 'testfisrtname' } });
fireEvent.change(lastnameInput, { target: { value: 'testlastname' } });

expect(emailInput).toHaveValue('[email protected]');
expect(firstnameInput).toHaveValue('testfisrtname');
expect(lastnameInput).toHaveValue('testlastname');
expect(usernameInput).toHaveValue('testuser');
expect(passwordInput).toHaveValue('testpassword');
expect(confirmInput).toHaveValue('testpassword2');
});

test('submits form with username, password, confirm when Sign up button is clicked', async () => {
const { getByLabelText } = render(<Register />);
const usernameInput = getByLabelText('Username');
const passwordInput = getByLabelText('Password');
const confirmInput = getByLabelText('Confirm Password');
const emailInput = getByLabelText('Email');
const firstnameInput = getByLabelText('Firstname');
const lastnameInput = getByLabelText('Lastname');
// const signUpButton = getByText('Sign up');

fireEvent.change(usernameInput, { target: { value: 'testuser' } });
fireEvent.change(passwordInput, { target: { value: 'testpassword' } });
fireEvent.change(confirmInput, { target: { value: 'testpassword2' } });
fireEvent.change(emailInput, { target: { value: '[email protected]' } });
fireEvent.change(firstnameInput, { target: { value: 'testfisrtname' } });
fireEvent.change(lastnameInput, { target: { value: 'testlastname' } });
// fireEvent.click(signUpButton);
});

});
Loading

0 comments on commit 576869e

Please sign in to comment.