client/src/components/__tests__/NoteInput.test.js
author ymh <ymh.work@gmail.com>
Tue, 23 May 2017 13:15:34 +0200
changeset 3 3b5d37d84cfe
child 8 6f572b6b6be3
permissions -rw-r--r--
Some code rename and reorg + basic tests
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
import React from 'react';
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
import { shallow, mount } from 'enzyme';
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
import NoteInput from '../NoteInput';
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
const setup = (propOverrides, doMount=false) => {
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
  const props = Object.assign({
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
      addNote: jest.fn()
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
  }, propOverrides);
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
  const renderFn = doMount?mount:shallow; 
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
  const wrapper = renderFn(<NoteInput {...props} />);
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
  return {
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
    props,
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
    wrapper,
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
  }
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
};
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
describe('Notes container Component', () => {
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
  test('render', () => {
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
    const { wrapper } = setup();
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    expect(wrapper.exists()).toBe(true)
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
  });
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
  test('click button', () => {
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
      const { props, wrapper } = setup({}, true);
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
      wrapper.find('button').simulate('click');
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
      expect(props.addNote.mock.calls.length).toBe(1);
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
  });
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
  test('note value on clickbutton', () => {
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
      const { props, wrapper } = setup({}, true);
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
      wrapper.find('textarea').simulate('change', {target: {value: 'note text'}});
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
      wrapper.find('button').simulate('click');
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
      expect(props.addNote.mock.calls.length).toBe(1);
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
      expect(props.addNote.mock.calls[0]).toEqual(['note text']);
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
  });
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
});
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40