import { fromJS } from "immutable";
import makeSelectCreativesContainer, {
  selectCreativesContainerDomain,
  isLoading,
  loyaltyTagProps,
} from "../selectors";

describe("makeSelectCreativesContainer", () => {
  it("returns the expected object with default values when substate is empty", () => {
    // Arrange
    const state = fromJS({ creativesContainer: {} });
    const expected = {};
    const selector = makeSelectCreativesContainer();

    // Act
    const result = selector(state);
    // Assert
    expect(result).toEqual(expected);
  });

  it("returns the expected object when substate has data", () => {
    // Arrange
    const state = fromJS({ 
      creativesContainer: { 
        containerLoader: true,
        loyaltyTagProps: { id: 1, name: "test" }
      } 
    });
    const expected = { 
      containerLoader: true,
      loyaltyTagProps: { id: 1, name: "test" }
    };
    const selector = makeSelectCreativesContainer();

    // Act
    const result = selector(state);
    // Assert
    expect(result).toEqual(expected);
  });
});

describe("selectCreativesContainerDomain", () => {
  it("returns the creativesContainer domain from state", () => {
    // Arrange
    const state = fromJS({ creativesContainer: { test: "value" } });
    const selector = selectCreativesContainerDomain();

    // Act
    const result = selector(state);
    // Assert
    expect(result).toEqual(state.get("creativesContainer"));
  });
});

describe("isLoading", () => {
  it("returns the containerLoader value when substate has data", () => {
    // Arrange
    const state = fromJS({ 
      creativesContainer: { 
        containerLoader: true,
        loyaltyTagProps: { id: 1 }
      } 
    });
    const selector = isLoading();

    // Act
    const result = selector(state);
    // Assert
    expect(result).toBe(true);
  });

  it("returns undefined when substate is empty", () => {
    // Arrange
    const state = fromJS({ creativesContainer: {} });
    const selector = isLoading();

    // Act
    const result = selector(state);
    // Assert
    expect(result).toBeUndefined();
  });
});

describe("loyaltyTagProps", () => {
  it("returns the loyaltyTagProps value when substate has data", () => {
    // Arrange
    const state = fromJS({ 
      creativesContainer: { 
        containerLoader: false,
        loyaltyTagProps: { id: 1, name: "test" }
      } 
    });
    const expected = { id: 1, name: "test" };
    const selector = loyaltyTagProps();

    // Act
    const result = selector(state);
    // Assert
    expect(result).toEqual(expected);
  });

  it("returns undefined when substate is empty", () => {
    // Arrange
    const state = fromJS({ creativesContainer: {} });
    const selector = loyaltyTagProps();

    // Act
    const result = selector(state);
    // Assert
    expect(result).toBeUndefined();
  });
});