# Copyright (c) 2015, JINGROW and Contributors
# License: MIT. See LICENSE
import jingrow
from jingrow.tests.utils import JingrowTestCase

# test_records = jingrow.get_test_records('Help Article')


class TestHelpArticle(JingrowTestCase):
	@classmethod
	def setUpClass(cls) -> None:
		cls.help_category = jingrow.get_pg(
			{
				"pagetype": "Help Category",
				"category_name": "_Test Help Category",
			}
		).insert()

		cls.help_article = jingrow.get_pg(
			{
				"pagetype": "Help Article",
				"title": "_Test Article",
				"category": cls.help_category.name,
				"content": "_Test Article",
			}
		).insert()

	def test_article_is_helpful(self):
		from jingrow.website.pagetype.help_article.help_article import add_feedback

		self.help_article.load_from_db()
		self.assertEqual(self.help_article.helpful, 0)
		self.assertEqual(self.help_article.not_helpful, 0)

		add_feedback(self.help_article.name, "Yes")
		add_feedback(self.help_article.name, "No")

		self.help_article.load_from_db()
		self.assertEqual(self.help_article.helpful, 1)
		self.assertEqual(self.help_article.not_helpful, 1)

	def test_category_disable(self):
		self.help_article.load_from_db()
		self.help_article.published = 1
		self.help_article.save()

		self.help_category.load_from_db()
		self.help_category.published = 0
		self.help_category.save()

		self.help_article.load_from_db()
		self.assertEqual(self.help_article.published, 0)

	@classmethod
	def tearDownClass(cls) -> None:
		jingrow.delete_pg(cls.help_article.pagetype, cls.help_article.name)
		jingrow.delete_pg(cls.help_category.pagetype, cls.help_category.name)
