# Copyright (c) 2020, JINGROW and Contributors
# License: MIT. See LICENSE

import jingrow
from jingrow.tests.utils import JingrowTestCase
from jingrow.website.pagetype.website_settings.website_settings import get_website_settings


class TestWebsiteSettings(JingrowTestCase):
	def test_child_items_in_top_bar(self):
		ws = jingrow.get_pg("Website Settings")
		ws.append(
			"top_bar_items",
			{"label": "Parent Item"},
		)
		ws.append(
			"top_bar_items",
			{"parent_label": "Parent Item", "label": "Child Item"},
		)
		ws.save()

		context = get_website_settings()

		for item in context.top_bar_items:
			if item.label == "Parent Item":
				self.assertEqual(item.child_items[0].label, "Child Item")
				break
		else:
			self.fail("Child items not found")

	def test_redirect_setups(self):
		ws = jingrow.get_pg("Website Settings")

		ws.append("route_redirects", {"source": "/engineering/(*.)", "target": "/development/(*.)"})
		self.assertRaises(jingrow.ValidationError, ws.validate)
