client/src/actions/__tests__/notesActions.test.js
author ymh <ymh.work@gmail.com>
Tue, 29 Mar 2022 11:23:56 +0200
changeset 211 244a90638e80
parent 168 ea92f4fe783d
permissions -rw-r--r--
Added tag 0.2.3 for changeset 3de92ddba2de

// cf. http://redux.js.org/docs/recipes/WritingTests.html

import * as actions from '../notesActions'
import * as types from '../../constants/actionTypes'

describe('actions', () => {

  it('should create an action to add a note', () => {
    const text = 'hello world';
    const dateNote = Date.now();
    const data = {
      raw: {
        document: {
          nodes: [
            {
              object: 'block',
              type: 'paragraph',
              nodes: [
                {
                  object: 'text',
                  leaves: [
                    {
                      text: text,
                    },
                  ],
                },
              ],
            },
          ],
        },
      },
      plain: text,
      html: text,
      startedAt: dateNote,
      finishedAt: dateNote + 10000,
      categories: [],
      marginComment: 'empty',
    }
    const session = { _id: 'abcd123' }
    const expectedAction = {
      type: types.ADD_NOTE,
      note: {
        _id: expect.stringMatching(/[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}/),
        session: session._id
      }
    }

    const receivedAction = actions.addNote(session, data);
    expect(receivedAction).toMatchObject(expectedAction);

  })
})