import { fromJS } from "immutable";
import { makeSelectTemplatesResponse } from "../selectors";
import { selectArchiveFilter, selectSelectedTemplateIds } from "../selectors";

describe("Template selectors", () => {
  const mockState = fromJS({
    templates: [],
  });

  describe("makeSelectTemplatesResponse selector", () => {
    it("should return the correct substate", () => {
      const selected = makeSelectTemplatesResponse().resultFunc(
        mockState.get("templates")
      );
      expect(selected).toEqual(mockState.getIn(["templates", "templates"]));
    });
  });
});

describe("selectArchiveFilter selector", () => {
  it("should return archiveFilter from state", () => {
    const state = fromJS({
      templates: { archiveFilter: 'archived' },
    });
    const result = selectArchiveFilter().resultFunc(state.get('templates').toJS());
    expect(result).toBe('archived');
  });

  it("should default to 'active' when archiveFilter is not set", () => {
    const result = selectArchiveFilter().resultFunc({});
    expect(result).toBe('active');
  });
});

describe("selectSelectedTemplateIds selector", () => {
  it("should return selectedTemplateIds from state", () => {
    const ids = ['id1', 'id2'];
    const state = fromJS({
      templates: { selectedTemplateIds: ids },
    });
    const result = selectSelectedTemplateIds().resultFunc(state.get('templates').toJS());
    expect(result).toEqual(ids);
  });

  it("should default to [] when selectedTemplateIds is not set", () => {
    const result = selectSelectedTemplateIds().resultFunc({});
    expect(result).toEqual([]);
  });
});
