Skip to content

Commit

Permalink
Add full form tests for file fields
Browse files Browse the repository at this point in the history
  • Loading branch information
bcvandendool committed May 31, 2021
1 parent 0941425 commit c551516
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
{% if not widget.data.is_initial %}
{% include 'bootstrap5/layout/help_text_and_errors.html' %}
{% endif %}
{% if widget.data.is_initial %}
</div>
{% if widget.data.is_initial %}
<div class="input-group mb-0">
{% include 'bootstrap5/layout/help_text_and_errors.html' %}
</div>
Expand Down
26 changes: 26 additions & 0 deletions tests/results/test_clearable_file_field.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<form method="post" enctype="multipart/form-data">
<div id="div_id_clearable_file" class="mb-3">
<label for="id_clearable_file" class="form-label">Clearable file</label>
<div class=" mb-2">
<div class="input-group mb-2">
<span class="input-group-text">Currently</span>
<div class="form-control d-flex h-auto">
<span class="text-break" style="flex-grow:1;min-width:0">
<a href="something"></a>
</span>
<span class="align-self-center ml-2">
<span class="form-check">
<input type="checkbox" name="clearable_file-clear" id="clearable_file-clear_id" class="form-check-input" >
<label class="form-check-label mb-0" for="clearable_file-clear_id">Clear</label>
</span>
</span>
</div>
</div>
<div class="input-group mb-0 ">
<input type="file" name="clearable_file" class="form-control" id="id_clearable_file">
</div>
<div class="input-group mb-0">
</div>
</div>
</div>
</form>
13 changes: 13 additions & 0 deletions tests/results/test_file_field.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<form method="post" enctype="multipart/form-data">
<div id="div_id_file_field" class="mb-3">
<label for="id_file_field" class="form-label requiredField">
File field
<span class="asteriskField">*</span>
</label>
<div class=" mb-2">
<div class="input-group mb-0 ">
<input type="file" name="file_field" class="form-control" id="id_file_field" required>
</div>
</div>
</div>
</form>
15 changes: 4 additions & 11 deletions tests/test_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,19 +570,12 @@ def test_file_field():
form = FileForm()
form.helper = FormHelper()
form.helper.layout = Layout("clearable_file")
html = render_crispy_form(form)
assert (
'input type="checkbox" name="clearable_file-clear" id="clearable_file-clear_id'
in html
)
assert '<input type="file" name="clearable_file" class="form-control"' in html

assert parse_form(form) == parse_expected("test_clearable_file_field.html")

form.helper.layout = Layout("file_field")
html = render_crispy_form(form)
assert (
'<input type="file" name="file_field" class="'
'form-control" id="id_file_field" required>' in html
)

assert parse_form(form) == parse_expected("test_file_field.html")


def test_row():
Expand Down

0 comments on commit c551516

Please sign in to comment.