- import React from 'react';
- import { shallow } from 'enzyme';
- import { LoginPage } from './LoginPage';
- import { UserModel } from '../../../model/user-model';
- import { UserController } from '../../../controllers/user-controller';
- describe('LoginPage', () => {
- const userModel = new UserModel();
- const userController = new UserController(userModel);
- it('should render without errors', () => {
- const wrapper = shallow(
- <LoginPage userModel={userModel} userController={userController} />,
- );
- expect(wrapper.exists()).toBe(true);
- });
- it('should update the state when the login input field changes', () => {
- const wrapper = shallow(
- <LoginPage userModel={userModel} userController={userController} />,
- );
- const loginInput = wrapper.find('.frame__auth__login-field');
- const newLogin = 'testuser';
- loginInput.simulate('input', { target: { value: newLogin } });
- expect(wrapper.state().login).toEqual(newLogin);
- });
- it('should update the state when the password input field changes', () => {
- const wrapper = shallow(
- <LoginPage userModel={userModel} userController={userController} />,
- );
- const passwordInput = wrapper.find('.frame__auth__password-field');
- const newPassword = 'testpassword';
- passwordInput.simulate('input', { target: { value: newPassword } });
- expect(wrapper.state().password).toEqual(newPassword);
- });
- it('should call the authorize method on form submission', () => {
- const authorize = jest.fn();
- userController.authorize = authorize;
- const wrapper = shallow(
- <LoginPage userModel={userModel} userController={userController} />,
- );
- const form = wrapper.find('.frame__auth');
- form.simulate('submit', { preventDefault: jest.fn() });
- expect(authorize).toHaveBeenCalledTimes(1);
- });
- it('should set isRegisterMode to true when the register button is clicked', () => {
- const wrapper = shallow(
- <LoginPage userModel={userModel} userController={userController} />,
- );
- const registerButton = wrapper.find('.frame__auth__register-button');
- registerButton.simulate('click');
- expect(userModel.isRegisterMode).toBe(true);
- });
- });
[text] 1211
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: