|
1 | 1 | from django import forms |
2 | 2 | from django.db import models |
3 | 3 | from django.template import Context, Template |
4 | | -from django.test import SimpleTestCase |
| 4 | +from django.test import RequestFactory, SimpleTestCase |
5 | 5 |
|
6 | 6 | from django_smartbase_admin.admin.site import sb_admin_site |
7 | 7 | from django_smartbase_admin.monkeypatch.admin_readonly_field_monkeypatch import ( |
@@ -85,6 +85,42 @@ class ExampleForm(forms.Form): |
85 | 85 | self.assertIn("Enabled", html) |
86 | 86 | self.assertNotIn("sbadmin_hide_label", html) |
87 | 87 |
|
| 88 | + def test_inline_table_field_renders_hidden_initial(self): |
| 89 | + class ExampleForm(forms.Form): |
| 90 | + field = forms.CharField( |
| 91 | + initial=lambda: "initial value", |
| 92 | + show_hidden_initial=True, |
| 93 | + ) |
| 94 | + |
| 95 | + html = self.render_inline_table_field(ExampleForm()) |
| 96 | + |
| 97 | + self.assertIn('name="field"', html) |
| 98 | + self.assertIn('type="hidden"', html) |
| 99 | + self.assertIn('name="initial-field"', html) |
| 100 | + |
| 101 | + def test_form_field_renders_hidden_initial(self): |
| 102 | + class ExampleForm(forms.Form): |
| 103 | + field = forms.CharField( |
| 104 | + initial=lambda: "initial value", |
| 105 | + show_hidden_initial=True, |
| 106 | + ) |
| 107 | + |
| 108 | + template = Template( |
| 109 | + "{% load sb_admin_tags %}{% sb_admin_render_form_field form.field %}" |
| 110 | + ) |
| 111 | + html = template.render( |
| 112 | + Context( |
| 113 | + { |
| 114 | + "form": ExampleForm(), |
| 115 | + "request": RequestFactory().get("/"), |
| 116 | + } |
| 117 | + ) |
| 118 | + ) |
| 119 | + |
| 120 | + self.assertIn('name="field"', html) |
| 121 | + self.assertIn('type="hidden"', html) |
| 122 | + self.assertIn('name="initial-field"', html) |
| 123 | + |
88 | 124 | def test_inline_table_readonly_field_hides_own_label(self): |
89 | 125 | form = InlineReadonlyDemoForm( |
90 | 126 | instance=InlineReadonlyDemoModel(name="Saved name") |
|
0 commit comments