import * as selector from './breadcrumb.selectors';
import * as action from './breadcrumb.actions';
import { breadcrumbReducer } from './breadcrumb.reducer';

import { BreadcrumbState, INIT } from './breadcrumb.state';

describe('Breadcrumb Selectors', () => {
  let state: BreadcrumbState;

  beforeEach(() => {
    state = breadcrumbReducer(INIT, action.addBreadcrumb({ breadcrumb: { id: 1, key: 'unit-test-1', path: '', name: 'Unit Test 1' } }));
    state = breadcrumbReducer(
      state,
      action.addBreadcrumb({ breadcrumb: { id: 2, key: 'unit-test-1', path: '', name: 'Unit Test 1', tags: ['details'] } })
    );
    state = breadcrumbReducer(state, action.addBreadcrumb({ breadcrumb: { id: 3, key: 'unit-test-2', path: '', name: 'Unit Test 1' } }));
    state = breadcrumbReducer(state, action.addBreadcrumb({ breadcrumb: { id: 4, key: 'unit-test-3', path: '', name: 'Unit Test 1' } }));
    state = breadcrumbReducer(
      state,
      action.addBreadcrumb({ breadcrumb: { id: 5, key: 'unit-test-3', path: '', name: 'Unit Test 1', tags: ['details'] } })
    );
  });

  describe('selectBreadcrumbsByKey', () => {
    it('should return all breadcrumbs with the key unit-test-1', () => {
      const fixture = selector.selectBreadcrumbsByKey.projector(Object.values(state.entities), 'unit-test-1');
      expect(fixture.length).toBe(2);
      expect(fixture[0].key).toBe('unit-test-1');
      expect(fixture[1].key).toBe('unit-test-1');
    });
  });

  describe('selectBreadcrumbsByKeyAndTag', () => {
    it('should return all breadcrumbs with the key unit-test-3 and tag details', () => {
      const fixture = selector.selectBreadcrumbsByKeyAndTag.projector(Object.values(state.entities), {
        key: 'unit-test-3',
        tag: 'details',
      });
      expect(fixture.length).toBe(1);
      expect(fixture[0].key).toBe('unit-test-3');
      expect(fixture[0].tags).toContain('details');
    });
  });
});
