import { isMenuVisible } from "../navigationHandler";

describe("NavigationHandler", () => {
  describe("isMenuVisible", () => {
    it("returns false when the route is a player route", () => {
      const menuVisible = isMenuVisible("/playable/some_vod_item", {}, [
        {
          identifier: "quick-brick-bottom-tabs",
          category: "menu",
          name: "Bottom Tabs",
        },
      ]);

      expect(menuVisible).toBe(false);
    });

    describe("when screen is a hook", () => {
      it("returns true if the `showNavBar` flag is set to true", () => {
        const menuVisible = isMenuVisible(
          "",
          {
            hookPlugin: {
              module: {
                showNavBar: true,
              },
            },
            navigations: [
              {
                navigation_type: "quick-brick-bottom-tabs",
                identifier: "quick-brick-bottom-tabs",
                category: "menu",
                name: "Bottom Tabs",
              },
            ],
          },
          [
            {
              identifier: "quick-brick-bottom-tabs",
              category: "menu",
              name: "Bottom Tabs",
            },
          ]
        );

        expect(menuVisible).toBe(true);
      });

      it("returns true if presentFullScreen flag is set to false", () => {
        const menuVisible = isMenuVisible(
          "",
          {
            hookPlugin: {
              module: {
                presentFullScreen: false,
              },
            },
            navigations: [
              {
                navigation_type: "quick-brick-bottom-tabs",
                identifier: "quick-brick-bottom-tabs",
                category: "menu",
                name: "Bottom Tabs",
              },
            ],
          },
          [
            {
              identifier: "quick-brick-bottom-tabs",
              category: "menu",
              name: "Bottom Tabs",
            },
          ]
        );

        expect(menuVisible).toBe(true);
      });

      it("returns false if presentFullScreen flag is set to true", () => {
        const menuVisible = isMenuVisible(
          "",
          {
            hookPlugin: {
              module: {
                presentFullScreen: true,
              },
            },
            navigations: [
              {
                navigation_type: "quick-brick-bottom-tabs",
                identifier: "quick-brick-bottom-tabs",
                category: "menu",
                name: "Bottom Tabs",
              },
            ],
          },
          [
            {
              identifier: "quick-brick-bottom-tabs",
              category: "menu",
              name: "Bottom Tabs",
            },
          ]
        );

        expect(menuVisible).toBe(false);
      });
    });

    it("returns false if the screen's general settings allow screen presentation", () => {
      const menuVisible = isMenuVisible(
        "",
        {
          general: {
            allow_screen_plugin_presentation: true,
          },
          navigations: [
            {
              navigation_type: "quick-brick-bottom-tabs",
              identifier: "quick-brick-bottom-tabs",
              category: "menu",
              name: "Bottom Tabs",
            },
          ],
        },
        [
          {
            identifier: "quick-brick-bottom-tabs",
            category: "menu",
            name: "Bottom Tabs",
          },
        ]
      );

      expect(menuVisible).toBe(false);
    });

    it("returns false otherwise", () => {
      const menuVisible = isMenuVisible(
        "any",
        {
          navigations: [
            {
              navigation_type: "quick-brick-bottom-tabs",
              identifier: "quick-brick-bottom-tabs",
              category: "menu",
              name: "Bottom Tabs",
            },
          ],
        },
        [
          {
            identifier: "quick-brick-bottom-tabs",
            category: "menu",
            name: "Bottom Tabs",
          },
        ]
      );

      expect(menuVisible).toBe(true);
    });

    it("returns false otherwise", () => {
      const menuVisible = isMenuVisible("", {}, [
        {
          identifier: "quick-brick-bottom-tabs",
          category: "menu",
          name: "Bottom Tabs",
        },
      ]);

      expect(menuVisible).toBe(false);
    });
  });
});
