Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from "react";
- import { BrowserRouter } from "react-router-dom";
- import { mount, shallow } from "enzyme";
- import { LoginPage } from "../../../views/LoginPage";
- describe("Login Page", () => {
- const props = {
- actions: {
- login: jest.fn()
- },
- dispatch: jest.fn(),
- classes: {},
- user: {
- isLoggedIn: false,
- loggingIn: false
- },
- location: {
- hash: "",
- key: "y960da",
- pathname: "/login",
- search: ""
- }
- };
- const initialState = {
- cardAnimation: "cardHidden",
- email: "bernard@neucleans.com",
- password: "password",
- rememberMe: true
- };
- const user = {
- email: 'user@test.com',
- password: 'Password1',
- };
- const mockChangeEvent = (name, value) => ({
- target: {
- name,
- value,
- },
- });
- let wrapper;
- const setup = (mountComponent = false) => {
- wrapper = mountComponent
- // @ts-ignore
- ? mount(<BrowserRouter><LoginPage {...props} /></BrowserRouter>)
- // @ts-ignore
- : shallow(<BrowserRouter><LoginPage {...props} /></BrowserRouter>);
- return { props, wrapper };
- };
- it("should render the Login Page", () => {
- setup();
- expect(wrapper).toMatchSnapshot();
- expect(wrapper).toHaveLength(1);
- });
- it("should render the Login Page", () => {
- setup(true);
- expect(wrapper).toMatchSnapshot();
- });
- it('should render login button with correct text', () => {
- setup();
- expect(wrapper.find('Button')).toBeTruthy();
- // expect(wrapper.find('Button').text()).toEqual('Login to Get Started');
- });
- // it('should attempt sign-in when login button is clicked', () => {
- // setup(true);
- // jest.spyOn(LoginPage.prototype, 'formIsValid');
- // const loginButtonSpy = jest.spyOn(LoginPage.prototype, 'handleSubmit');
- // wrapper.find('Button').at(0).simulate('click');
- // expect(loginButtonSpy).toHaveBeenCalled();
- // });
- it('should handle form element changes', () => {
- setup();
- const instance = wrapper.dive().instance();
- instance.handleChange(mockChangeEvent('email', user.email));
- instance.handleChange(mockChangeEvent('password', user.password));
- expect(instance.state.email).toEqual(user.email);
- expect(instance.state.password).toEqual(user.password);
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement