SHARE
TWEET

Untitled

a guest Aug 22nd, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2. import { AccountDetailForm } from '../../../src/pages/User/AccountDetailForm';
  3. import ReduxAccountDetailForm from '../../../src/pages/User/AccountDetailForm';
  4. import { Provider } from 'react-redux';
  5. import { combineReducers, createStore } from 'redux';
  6. import { reducer as formReducer } from 'redux-form';
  7. import { ShallowWrapper } from 'enzyme';
  8. import { shallowToJson } from 'enzyme-to-json';
  9. import { mount, shallow } from '../../setup/test-setup';
  10.  
  11. const mockfn = jest.fn();
  12.  
  13. describe('<AccountDetailForm />', () => {
  14.     let wrapper: any;
  15.     let store: any;
  16.  
  17.     const props: any = {
  18.         handleSubmit: mockfn,
  19.     };
  20.  
  21.     beforeEach(() => {
  22.         wrapper = shallow(<AccountDetailForm {...props} />);
  23.     });
  24.  
  25.     it('should match the snapshot', () => {
  26.         expect(shallowToJson(wrapper)).toMatchSnapshot();
  27.     });
  28.  
  29.     describe('defines account detail form fields', () => {
  30.         it('renders account number field', () => {
  31.             const userAccountNumberField = wrapper.find('[name="useraccountNumber"]');
  32.  
  33.             expect(userAccountNumberField.prop('type')).toBe('text');
  34.             expect(userAccountNumberField.prop('label')).toBe('Account Number *');
  35.             expect(userAccountNumberField.prop('placeHolder')).toBe('Enter Account Number');
  36.         });
  37.  
  38.         it('renders bank name field', () => {
  39.             const bankNameField = wrapper.find('[name="userBankName"]');
  40.  
  41.             expect(bankNameField.prop('type')).toBe('text');
  42.             expect(bankNameField.prop('label')).toBe('Bank Name *');
  43.             expect(bankNameField.prop('placeHolder')).toBe('Enter Bank Name');
  44.         });
  45.  
  46.         it('renders bank address field', () => {
  47.             const bankAddressField = wrapper.find('[name="userbankAddress"]');
  48.  
  49.             expect(bankAddressField.prop('type')).toBe('textarea');
  50.             expect(bankAddressField.prop('label')).toBe('Bank Address *');
  51.             expect(bankAddressField.prop('placeHolder')).toBe('Enter Bank Address');
  52.         });
  53.  
  54.         it('renders previous button', () => {
  55.             const previousButton = wrapper
  56.                 .find('Button')
  57.                 .at(0)
  58.                 .dive();
  59.  
  60.             expect(previousButton.text()).toEqual('<FaChevronLeft />  Previous');
  61.         });
  62.  
  63.         it('renders save button', () => {
  64.             const button = wrapper.find('Button').at(1).dive();
  65.             const saveButton = button.find('span').text();
  66.  
  67.             expect(button.prop('type')).toBe('submit');
  68.             expect(saveButton).toEqual('Save');
  69.         });
  70.     });
  71.  
  72.     describe('form validation', () => {
  73.         beforeEach(() => {
  74.             store = createStore(combineReducers({ form: formReducer }));
  75.             wrapper = mount(
  76.                 <Provider store={store}>
  77.                     <ReduxAccountDetailForm {...props} />
  78.                 </Provider>,
  79.             );
  80.         });
  81.  
  82.         describe('input#account number', () => {
  83.             let accountNumberField: ShallowWrapper;
  84.  
  85.             beforeEach(() => {
  86.                 accountNumberField = wrapper.find('input[name="useraccountNumber"]').first();
  87.             });
  88.  
  89.             it('shows error when account number is set to blank', () => {
  90.                 accountNumberField.simulate('blur');
  91.                 const errorBlock = wrapper.find('.text-danger');
  92.  
  93.                 expect(errorBlock).toHaveLength(1);
  94.                 expect(errorBlock.text()).toBe('Account number required');
  95.             });
  96.         });
  97.  
  98.         describe('input#bank name', () => {
  99.             let bankNameField: ShallowWrapper;
  100.  
  101.             beforeEach(() => {
  102.                 bankNameField = wrapper.find('input[name="userBankName"]').first();
  103.             });
  104.  
  105.             it('shows error when bank name is set to blank', () => {
  106.                 bankNameField.simulate('blur');
  107.                 const errorBlock = wrapper.find('.text-danger');
  108.  
  109.                 expect(errorBlock).toHaveLength(1);
  110.                 expect(errorBlock.text()).toBe('Bank name required');
  111.             });
  112.         });
  113.  
  114.         describe('input#bank address', () => {
  115.             let addressField: ShallowWrapper;
  116.  
  117.             beforeEach(() => {
  118.                 addressField = wrapper.find('textarea[name="userbankAddress"]').first();
  119.             });
  120.  
  121.             it('shows error when bank address is set to blank', () => {
  122.                 addressField.simulate('blur');
  123.                 const errorBlock = wrapper.find('.text-danger');
  124.  
  125.                 expect(errorBlock).toHaveLength(1);
  126.                 expect(errorBlock.text()).toBe('Bank address required');
  127.             });
  128.         });
  129.  
  130.     });
  131. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top