# -*- coding: utf-8 -*-
"""
Testing inlining translation when no translation is specified.
"""
from pyxform.tests_v1.pyxform_test_case import PyxformTestCase


class InlineTranslationsTest(PyxformTestCase):
    def test_inline_translations(self):
        """
        Dynamic choice (marked with choice filter) should inline the labels instead of using
        itext fields. There should be no itext definition in the model.
        """
        self.assertPyxformXform(
            md="""
               | survey  |                   |          |            |               |
               |         | type              | name     | label      | choice_filter |
               |         | select_one states | state    | State Name | state != ''   |
               | choices |                   |          |            |
               |         | list name         | name     | label      |
               |         | states            | option a | a          |
               |         | states            | option b | b          |
               |         | states            | option c | c          |
               """,
            name="data",
            id_string="some-id",
            model__contains=[
                "<label>a</label>",
                "<label>b</label>",
                "<label>c</label>",
            ],
            model__excludes=[
                '<text id="static_instance-states-0">',
                '<text id="static_instance-states-1">',
                '<text id="static_instance-states-2">',
                "<itextId>static_instance-states-0</itextId>",
                "<itextId>static_instance-states-1</itextId>",
                "<itextId>static_instance-states-2</itextId>",
            ],
            xml__contains=['<label ref="label"/>'],
            xml__excludes=['<label ref="jr:itext(itextId)"/>'],
        )

    def test_multiple_translations(self):
        """
        Dynamic choice with potential translation should generate itext fields.
        """
        self.assertPyxformXform(
            md="""
               | survey  |                   |          |            |               |
               |         | type              | name     | label      | choice_filter |
               |         | select_one states | state    | State Name | state != ''   |
               | choices |                   |          |            |
               |         | list name         | name     | label::English(en)|
               |         | states            | option a | a                 |
               |         | states            | option b | b                 |
               |         | states            | option c | c                 |
               """,
            name="data",
            id_string="some-id",
            model__contains=[
                '<text id="static_instance-states-0">',
                '<text id="static_instance-states-1">',
                '<text id="static_instance-states-2">',
                "<itextId>static_instance-states-0</itextId>",
                "<itextId>static_instance-states-1</itextId>",
                "<itextId>static_instance-states-2</itextId>",
            ],
            model__excludes=[
                "<label>a</label>",
                "<label>b</label>",
                "<label>c</label>",
            ],
            xml__contains=['<label ref="jr:itext(itextId)"/>'],
            xml__excludes=['<label ref="label"/>'],
        )

@@ -3442,24 +3442,1652 @@
 =%22label%22/%3E'%5D,%0A        )%0A
+%0A    def test_select_with_media_and_choice_filter_and_no_translations_generates_media(%0A        self,%0A    ):%0A        %22%22%22%0A        Selects with media and choice filter should generate itext fields.%0A        %22%22%22%0A        xform_md = %22%22%22%0A        %7C survey %7C                    %7C                 %7C                                 %7C                           %7C%0A        %7C        %7C type               %7C name            %7C label                           %7C choice_filter             %7C%0A        %7C        %7C select_one consent %7C consent         %7C Would you like to participate ? %7C                           %7C%0A        %7C        %7C select_one mood    %7C enumerator_mood %7C How are you feeling today ?     %7C selected($%7Bconsent%7D, 'y') %7C%0A        %7C choices %7C%0A        %7C         %7C list_name %7C name %7C label %7C media::image %7C%0A        %7C         %7C mood      %7C h    %7C Happy %7C happy.jpg    %7C%0A        %7C         %7C mood      %7C s    %7C Sad   %7C sad.jpg      %7C%0A        %7C         %7C consent   %7C y    %7C Yes   %7C              %7C%0A        %7C         %7C consent   %7C n    %7C No    %7C              %7C%0A        %22%22%22%0A        self.assertPyxformXform(%0A            name=%22mood_form%22,%0A            id_string=%22mood_form%22,%0A            md=xform_md,%0A            errored=False,%0A            debug=False,%0A            model__contains=%5B%0A                '%3Ctext id=%22static_instance-mood-0%22%3E',%0A                '%3Ctext id=%22static_instance-mood-1%22%3E',%0A                %22%3CitextId%3Estatic_instance-mood-0%3C/itextId%3E%22,%0A                %22%3CitextId%3Estatic_instance-mood-1%3C/itextId%3E%22,%0A            %5D,%0A            xml__contains=%5B'%3Clabel ref=%22jr:itext(itextId)%22/%3E'%5D,%0A            xml__excludes=%5B'%3Clabel ref=%22label%22/%3E'%5D,%0A        )%0A

Test that selects with media and choice filter use itext