<reponame>jpsca/pforms
import proper_forms.fields as f


def test_text_as_richtext():
    field = f.Text(name="name")
    field.input_values = ["hello"]
    expected = (
        '<input id="TEST" name="name" value="hello" type="hidden">\n'
        '<trix-editor class="trix-content" input="TEST"></trix-editor>'
    )
    assert field.as_richtext(id="TEST") == expected


def test_text_as_richtext_no_value():
    field = f.Text(name="name")
    expected = (
        '<input id="TEST" name="name" value="" type="hidden">\n'
        '<trix-editor class="trix-content" input="TEST"></trix-editor>'
    )
    assert field.as_richtext(id="TEST") == expected


def test_text_as_richtext_with_label():
    field = f.Text(name="name")
    expected = (
        '<label id="label-TEST">Hello World</label>\n'
        '<input id="TEST" name="name" value="" type="hidden">\n'
        '<trix-editor class="trix-content" input="TEST"></trix-editor>'
    )
    assert field.as_richtext(id="TEST", label="Hello World") == expected


def test_text_as_richtext_attributes():
    field = f.Text(name="name")
    expected = (
        '<input id="TEST" name="name" value="" type="hidden">\n'
        '<trix-editor class="trix-content" data-id="2" input="TEST" extra></trix-editor>'
    )

    assert field.as_richtext(id="TEST", data_id=2, extra=True) == expected


def test_text_as_richtext_required():
    field = f.Text(name="name", required=True)
    expected = (
        '<input id="TEST" name="name" value="" type="hidden">\n'
        '<trix-editor class="trix-content" input="TEST" required></trix-editor>'
    )
    assert field.as_richtext(id="TEST") == expected


def test_text_as_richtext_custom_class():
    field = f.Text(name="name")
    expected = (
        '<input id="TEST" name="name" value="" type="hidden">\n'
        '<trix-editor class="foo bar" input="TEST"></trix-editor>'
    )
    assert field.as_richtext(id="TEST", classes="foo bar") == expected


def test_value_index():
    field = f.Text(name="name")
    field.input_values = ["a", "b", "c"]

    expected = (
        '<input id="TEST" name="name" value="a" type="hidden">\n'
        '<trix-editor class="trix-content" input="TEST"></trix-editor>'
    )
    assert field.as_richtext(id="TEST", value_index=0) == expected

    expected = (
        '<input id="TEST" name="name" value="b" type="hidden">\n'
        '<trix-editor class="trix-content" input="TEST"></trix-editor>'
    )
    assert field.as_richtext(id="TEST", value_index=1) == expected

    expected = (
        '<input id="TEST" name="name" value="c" type="hidden">\n'
        '<trix-editor class="trix-content" input="TEST"></trix-editor>'
    )
    assert field.as_richtext(id="TEST", value_index=2) == expected

    expected = (
        '<input id="TEST" name="name" value="" type="hidden">\n'
        '<trix-editor class="trix-content" input="TEST"></trix-editor>'
    )
    assert field.as_richtext(id="TEST", value_index=3) == expected
