Esempio n. 1
0
def test_checkbox_with_inline_layout(web_fixture, choices_fixture):
    """PrimitiveCheckboxInputs can be rendered inlined with each other by using the ChoicesLayout with the inline=True setting."""
    fixture = choices_fixture

    inlined_container = Div(web_fixture.view).use_layout(ChoicesLayout(inline=True))
    inlined_container.layout.add_choice(PrimitiveCheckboxInput(fixture.form, fixture.boolean_field))

    assert 'custom-control-inline' in inlined_container.children[0].get_attribute('class').split(' ')
Esempio n. 2
0
def choices_layout(fixture):
    """A ChoicesLayout can be used to add a PrimitiveCheckboxInput inlined or stacked."""
    stacked_container = Div(fixture.view).use_layout(ChoicesLayout())
    stacked_container.layout.add_choice(
        PrimitiveCheckboxInput(fixture.form, fixture.field))

    tester = WidgetTester(stacked_container)
    vassert(fixture.input_is_wrapped_in_label(tester))
    vassert(fixture.main_element(tester).tag == 'div')
    vassert(fixture.main_element(tester).attrib['class'] == 'checkbox')

    inlined_container = Div(fixture.view).use_layout(
        ChoicesLayout(inline=True))
    inlined_container.layout.add_choice(
        PrimitiveCheckboxInput(fixture.form, fixture.field))

    tester = WidgetTester(inlined_container)
    vassert(fixture.input_is_wrapped_in_label(tester))
    vassert(fixture.main_element(tester).tag == 'label')
    vassert(fixture.main_element(tester).attrib['class'] == 'checkbox-inline')
Esempio n. 3
0
def test_choices_layout_applied_to_checkbox(web_fixture, choices_fixture):
    """A ChoicesLayout lays out PrimitiveCheckboxInputs inside a Label containing the Field label, such that they will be stacked."""
    fixture = choices_fixture

    stacked_container = Div(web_fixture.view).use_layout(ChoicesLayout())
    stacked_container.layout.add_choice(PrimitiveCheckboxInput(fixture.form, fixture.boolean_field))

    stacked_container_classes = stacked_container.children[0].get_attribute('class').split(' ')
    assert 'custom-control' in stacked_container_classes
    assert 'custom-checkbox' in stacked_container_classes

    [checkbox_input, label] = stacked_container.children[0].children
    [description_widget] = label.children
    assert label.tag_name == 'label'

    assert checkbox_input.html_representation.input_type == 'checkbox'
    assert description_widget.value == 'field'
Esempio n. 4
0
def test_choice_disabled_state(web_fixture, disabled_scenarios):
    """Visible cues are inserted to indicate that inputs are disabled. """
    fixture = disabled_scenarios

    form = Form(web_fixture.view, 'test')
    field = fixture.field
    field.bind('field', fixture)

    container = Div(web_fixture.view).use_layout(ChoicesLayout())
    container.layout.add_choice(PrimitiveCheckboxInput(form, field))

    [checkbox_container] = container.children
    [checkbox_input, label] = checkbox_container.children
    checkbox_container_classes = checkbox_container.get_attribute('class').split(' ')
    if fixture.expects_disabled_class:
        assert 'disabled' in checkbox_container_classes
        assert checkbox_input.html_representation.get_attribute('disabled') == 'disabled'
    else:
        assert 'disabled' not in checkbox_container_classes
        with expected(KeyError):
            checkbox_input.html_representation.get_attribute('disabled')
Esempio n. 5
0
 def make_checkbox_widget(view, row):
     return PrimitiveCheckboxInput(form,
                                   row.fields.selected_by_user,
                                   name_discriminator=str(
                                       row.address.id))
Esempio n. 6
0
 def make_checkbox_widget(view, row):
     return PrimitiveCheckboxInput(form, row.fields.selected_by_user)