import { sendQuickBrickEvent, getAppData, getLegacyInitialProps } from "../";
import { bridgeLogger } from "../../logger";

jest.mock("../../logger", () => ({
  bridgeLogger: {
    warning: jest.fn(),
  },
}));

const payload = {};

describe("when QuickBrickCommunication Module is undefined", () => {
  beforeAll(() => {
    require("react-native").NativeModules.QuickBrickCommunicationModule =
      undefined;
  });

  describe("sendQuickBrickEvent", () => {
    it("throws an error", () => {
      const eventName = "event";
      expect(() => sendQuickBrickEvent(eventName, payload)).toThrow();
    });
  });

  describe("getAppData", () => {
    it("returns the default values", () => {
      expect(getAppData()).toMatchSnapshot();
    });
  });

  describe("getLegacyInitialProps", () => {
    beforeEach(() => {
      bridgeLogger.warning.mockClear();
    });

    it("returns an empty object", () => {
      expect(getLegacyInitialProps()).toEqual({});
    });

    it("warns in the console that the module is missing", () => {
      getLegacyInitialProps();

      expect(bridgeLogger.warning).toHaveBeenCalledWith(
        "QuickBrickCommunicationModule not found"
      );
    });
  });
});
