"""This module holds forms tests for the ``trainings`` app."""

from mtp.apps.common.tests.test_cases import TestCase
from mtp.apps.common.tests.waffle_test_utils import override_switch

from ..forms import TrainingOptionsForm


class TrainingOptionsFormTestCase(TestCase):
    """Test case that tests the ``WorkshopStepQuestionForm`` form."""

    def create_form(self, form_data):
        """Create a ``TrainingOptionsForm`` instance."""

        return TrainingOptionsForm(
            data=form_data,
        )

    @override_switch('enable_assessments', active=True)
    def test_with_assessment(self):
        """Test ``TrainingOptionsForm`` with assessment."""

        form = self.create_form({
            'activate_show_results': True,
            'activate_activity_quickcreation': True,
            'activate_qrcode_launcher': True,
        })

        # Assessment is enabled, this field should be available
        self.assertIn('activate_show_results', form.fields)

        # The form should be valid
        self.assertTrue(form.is_valid())

        # The form should create/update the wanted object
        options = form.save(commit=False)
        self.assertTrue(options.activate_show_results)

    @override_switch('enable_assessments', active=False)
    def test_without_assessment(self):
        """Test ``TrainingOptionsForm`` without assessment."""

        form = self.create_form({
            'activate_activity_quickcreation': True,
            'activate_qrcode_launcher': True,
        })

        # Assessment is disabled, this field should'nt be available
        self.assertNotIn('activate_show_results', form.fields)

        # The form should be valid
        self.assertTrue(form.is_valid())

        # The form should create/update the wanted object
        options = form.save(commit=False)
        self.assertIsNotNone(options)
