import { fromJS, Map } from 'immutable';
import { makeSelectRcs, makeSelectAccount } from '../selectors';

describe('RCS selectors', () => {
  it('makeSelectRcs returns JS object from immutable substate', () => {
    const rcsSubstate = fromJS({ foo: 'bar', nested: { a: 1 } });
    const state = Map({ rcs: rcsSubstate });
    const selectRcs = makeSelectRcs();
    const result = selectRcs(state);
    expect(result).toEqual({ foo: 'bar', nested: { a: 1 } });
  });

  it('makeSelectRcs memoizes result when substate reference is stable', () => {
    const rcsSubstate = fromJS({ x: 1 });
    const state = Map({ rcs: rcsSubstate });
    const selectRcs = makeSelectRcs();
    const first = selectRcs(state);
    const second = selectRcs(state);
    // Same input reference should yield cached result (strictly equal)
    expect(second).toBe(first);
  });

  it('makeSelectRcs returns undefined when substate is missing', () => {
    const state = Map({});
    const selectRcs = makeSelectRcs();
    const result = selectRcs(state);
    expect(result).toBeUndefined();
  });

  it('makeSelectAccount returns JS object from templates substate', () => {
    const templatesSubstate = fromJS({ list: [1, 2], meta: { total: 2 } });
    const state = Map({ templates: templatesSubstate });
    const selectAccount = makeSelectAccount();
    const result = selectAccount(state);
    expect(result).toEqual({ list: [1, 2], meta: { total: 2 } });
  });
});


