"""This module holds the tests template tags of the ``translation`` app."""

from django.test import TestCase

from mtp.apps.common.tests.test_cases import MTPTemplateTestCaseMixin


class GetFlagTestCase(MTPTemplateTestCaseMixin, TestCase):
    """Test the `get_country_flag` tag."""

    def test_get_country_flag_without_locale(self):
        """Test case where no locale is provided."""
        rendered = self.render_raw_template('{% load i18n_utils %}'
                                            '{% get_country_flag "fr" as flag_path %}'
                                            '{{flag_path}}')
        self.assertEqual(rendered, '/static/translation/flags/fr.png')

        rendered = self.render_raw_template('{% load i18n_utils %}'
                                            '{% get_country_flag "en" as flag_path %}'
                                            '{{flag_path}}')
        self.assertEqual(rendered, '/static/translation/flags/en.png')

    def test_get_country_flag_with_locale(self):
        """Test case where a locale is provided."""
        rendered = self.render_raw_template('{% load i18n_utils %}'
                                            '{% get_country_flag "fr-BE" as flag_path %}'
                                            '{{flag_path}}')
        self.assertEqual(rendered, '/static/translation/flags/be.png')

        rendered = self.render_raw_template('{% load i18n_utils %}'
                                            '{% get_country_flag "en-IS" as flag_path %}'
                                            '{{flag_path}}')
        self.assertEqual(rendered, '/static/translation/flags/is.png')

        rendered = self.render_raw_template('{% load i18n_utils %}'
                                            '{% get_country_flag "fr-CH" as flag_path %}'
                                            '{{flag_path}}')
        self.assertEqual(rendered, '/static/translation/flags/ch.png')

    def test_get_country_flag_with_no_existing_file(self):
        """Test case where a locale is provided."""
        rendered = self.render_raw_template('{% load i18n_utils %}'
                                            '{% get_country_flag "jf" as flag_path %}'
                                            '{{flag_path}}')
        self.assertEqual(rendered, 'None')
