# Standard Library
from unittest.mock import Mock

# Django
from django.test import RequestFactory, SimpleTestCase

from incursions.auth_hooks import IncursionsMenuItem, register_cogs, register_menu


class TestAuthHooks(SimpleTestCase):
    def setUp(self) -> None:
        self.factory = RequestFactory()

    def test_register_cogs_returns_incursions_cog(self) -> None:
        self.assertEqual(register_cogs(), ["incursions.cogs.incursions"])

    def test_register_menu_returns_menu_item(self) -> None:
        self.assertIsInstance(register_menu(), IncursionsMenuItem)

    def test_menu_item_renders_empty_without_permission(self) -> None:
        request = self.factory.get("/")
        request.user = Mock(has_perm=Mock(return_value=False))

        self.assertEqual(IncursionsMenuItem().render(request), "")

    def test_menu_item_renders_markup_with_permission(self) -> None:
        request = self.factory.get("/")
        request.user = Mock(has_perm=Mock(return_value=True))

        rendered = IncursionsMenuItem().render(request)

        self.assertIn("Incursion Waitlist", rendered)
        self.assertIn("/incursions/waitlist/", rendered)
        self.assertIn("Incursion Waitlist", rendered)
        self.assertIn("/incursions/waitlist/", rendered)
