huridocs/uwazi

View on GitHub
app/react/ConnectionsList/components/specs/ConnectionsList.spec.js

Summary

Maintainability
A
0 mins
Test Coverage
import { fromJS as Immutable } from 'immutable';
import RelationshipsGraph from 'app/Relationships/components/RelationshipsGraphEdit';
import { mapStateToProps } from '../ConnectionsList';

describe('ConnectionsList', () => {
  describe('mapStateToProps', () => {
    let state;
    let props;

    beforeEach(() => {
      state = {
        relationships: {
          list: {
            sharedId: 'id1',
            searchResults: Immutable({
              rows: [
                { sharedId: 'id2', connections: ['a', 'b'] },
                { sharedId: 'id1', connections: ['c'] },
                { sharedId: 'id2', connections: ['d'] },
              ],
            }),
            sort: 'sort',
          },
        },
      };

      props = mapStateToProps(state);
    });

    it('should pass the documents and search from the state', () => {
      expect(props.documents).toEqual(state.relationships.list.searchResults);
      expect(props.search).toBe('sort');
    });

    it('should define the filters and sortButtonsStateProperty props', () => {
      expect(props.filters.toJS()).toEqual({ documentTypes: [] });
      expect(props.sortButtonsStateProperty).toBe('relationships/list.sort');
    });

    it('should pass action graph view elements', () => {
      expect(props.GraphView).toBe(RelationshipsGraph);
    });

    it('should calculate the number of connections', () => {
      expect(props.connections.totalRows).toBe(3);
    });

    it('should pass the view type', () => {
      expect(props.view).toBe('graph');
    });
  });
});