import { getPluginIdentifier } from "..";

describe("getPluginIdentifier", () => {
  const prefix = "tv_buttons";

  it("get first plugin identifier", () => {
    const configuration = {
      tv_buttons_button_1_other: "value",
      tv_buttons_button_1_assign_action:
        "tv_buttons_button_1_assign_action_value",
      tv_buttons_button_2_assign_action:
        "tv_buttons_button_2_assign_action_value",
    };

    const index = 0;

    const result = getPluginIdentifier(configuration, prefix, index);

    expect(result).toEqual(configuration.tv_buttons_button_1_assign_action);
  });

  it("get second plugin identifier", () => {
    const configuration = {
      tv_buttons_button_1_other: "value_1",
      tv_buttons_button_1_assign_action:
        "tv_buttons_button_1_assign_action_value",
      tv_buttons_button_2_other: "value_2",
      tv_buttons_button_2_assign_action:
        "tv_buttons_button_2_assign_action_value",
    };

    const index = 1;

    const result = getPluginIdentifier(configuration, prefix, index);

    expect(result).toEqual(configuration.tv_buttons_button_2_assign_action);
  });

  it("get undefined if no assign_actions at all", () => {
    const configuration = {};

    const index = 0;

    const result = getPluginIdentifier(configuration, prefix, index);

    expect(result).toBeUndefined();
  });
});

describe("getPluginIdentifier - when configuration has same values for different keys", () => {
  const prefix = "tv_buttons";

  const configuration = {
    tv_buttons_button_1_assign_action: "navigation_action",
    tv_buttons_button_2_assign_action: "navigation_action",
  };

  it("get first plugin identifier", () => {
    const index = 0;

    const result = getPluginIdentifier(configuration, prefix, index);

    expect(result).toEqual(configuration.tv_buttons_button_1_assign_action);
  });

  it("get second plugin identifier", () => {
    const index = 1;

    const result = getPluginIdentifier(configuration, prefix, index);

    expect(result).toEqual(configuration.tv_buttons_button_2_assign_action);
  });
});
