client/src/components/__tests__/NotesList.test.js
author ymh <ymh.work@gmail.com>
Fri, 30 Nov 2018 10:53:15 +0100
changeset 183 f8f3af9e5c83
parent 168 ea92f4fe783d
permissions -rw-r--r--
Change the settings to avoid using Session authentication for rest framework as it raise exceptions in case client and backend are on the same domain On the filter, adapt to take into account new version of django_filters
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 } from 'enzyme';
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
import NotesList from '../NotesList';
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 => {
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
  const props = Object.assign({
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
     7
      notes: [{
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
     8
          _id: 'note1',
3
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
          text: 'test text 1'
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
        },
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
        {
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
    12
          _id: 'note2',
3
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
          text: 'test text 2'
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
        },
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
        {
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
    16
          _id: 'note3',
3
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
          text: 'test text 3'
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
    18
        }]
3
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
  }, propOverrides);
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
  const wrapper = shallow(<NotesList {...props} />);
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
  return {
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    props,
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
    wrapper,
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
  }
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
};
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
describe('Notes container Component', () => {
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
  test('render', () => {
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
    const { wrapper } = setup();
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
    expect(wrapper.exists()).toBe(true)
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
  });
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
  test('test note nb', () => {
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
    const { wrapper } = setup();
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
    37
    expect(wrapper.find('Note').getElements()).toHaveLength(3);
3
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
  test('test node key', () => {
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
    const { wrapper } = setup();
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
    wrapper.find('li').forEach((node, i) => {
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
      expect(node.key()).toBe('note'+(i+1));
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
    });
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
  });
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
  test('test node note', () => {
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
    const { wrapper } = setup();
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
    wrapper.find('Note').forEach((node, i) => {
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
      const {note} = node.props();
168
ea92f4fe783d - move SlateEditor and dependencies to its own folder
ymh <ymh.work@gmail.com>
parents: 3
diff changeset
    51
      expect(note._id).toBe('note'+(i+1));
3
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
      expect(note.text).toBe('test text '+(i+1));
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
    });
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
  });
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
});