Skip to content

Commit b318279

Browse files
committed
Tests for custom input templates
1 parent e9bb8e7 commit b318279

File tree

9 files changed

+77
-6
lines changed

9 files changed

+77
-6
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<h5>This is a customized date-picker</h5>
2+
<div class="input-group date my-custom-class">
3+
{% include "bootstrap_datepicker_plus/input.html" %}
4+
<div class="input-group-addon input-group-append">
5+
<div class="input-group-text"><i class="glyphicon glyphicon-calendar"></i></div>
6+
</div>
7+
</div>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<h5>This is a customized time-picker</h5>
2+
<div class="input-group date my-custom-class">
3+
{% include "bootstrap_datepicker_plus/input.html" %}
4+
<div class="input-group-addon input-group-append">
5+
<div class="input-group-text"><i class="glyphicon glyphicon-time"></i></div>
6+
</div>
7+
</div>

demo_project/demo_project/settings.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@
140140
# ]
141141

142142
# Default settings
143-
BOOTSTRAP3 = {
144-
'include_jquery': True,
145-
}
143+
# BOOTSTRAP3 = {
144+
# 'include_jquery': True,
145+
# }
146146

147-
BOOTSTRAP4 = {
148-
'include_jquery': True,
149-
}
147+
# BOOTSTRAP4 = {
148+
# 'include_jquery': True,
149+
# }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<h5>This is a customized date-picker</h5>
2+
<div class="input-group date my-custom-class">
3+
<input type="text" name="input_name" value="2018-04-12"/>
4+
<div class="input-group-addon input-group-append">
5+
<div class="input-group-text"><i class="glyphicon glyphicon-calendar"></i></div>
6+
</div>
7+
</div>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<h5>This is a customized date-picker</h5>
2+
<div class="input-group date my-custom-class">
3+
<input type="text" name="input_name" value="2018-04-12" class="form-control" dp_config="{&quot;id&quot;: &quot;dp_17&quot;, &quot;picker_type&quot;: &quot;DATE&quot;, &quot;linked_to&quot;: null, &quot;options&quot;: {&quot;showClose&quot;: true, &quot;showClear&quot;: true, &quot;showTodayButton&quot;: true, &quot;format&quot;: &quot;MM/DD/YYYY&quot;}}"/>
4+
<div class="input-group-addon input-group-append">
5+
<div class="input-group-text"><i class="glyphicon glyphicon-calendar"></i></div>
6+
</div>
7+
</div>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<h5>This is a customized time-picker</h5>
2+
<div class="input-group date my-custom-class">
3+
<input type="text" name="input_name" value="12:30" class="form-control" dp_config="{&quot;id&quot;: &quot;dp_17&quot;, &quot;picker_type&quot;: &quot;TIME&quot;, &quot;linked_to&quot;: null, &quot;options&quot;: {&quot;showClose&quot;: true, &quot;showClear&quot;: true, &quot;showTodayButton&quot;: true, &quot;format&quot;: &quot;HH:mm&quot;}}"/>
4+
<div class="input-group-addon input-group-append">
5+
<div class="input-group-text"><i class="glyphicon glyphicon-time"></i></div>
6+
</div>
7+
</div>

tests/test_compatibility_patch.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
from bootstrap_datepicker_plus._helpers import get_base_input
55

66

7+
class CustomCompatibleDatePickerInput(get_base_input(True)):
8+
template_name = 'demo_app/custom_input/date-picker.html'
9+
10+
711
class TestCompatibilityPatch(SimpleTestCase):
812

913
def setUp(self):
@@ -26,3 +30,9 @@ def test_compatible_input_snapshot(self):
2630
html = self.dp_input.render('input_name', '2018-04-12', {})
2731
snapshot = open('tests/snapshots/compatible-input.html').read()
2832
self.assertEqual(html, snapshot)
33+
34+
def test_compatible_custom_input_snapshot(self):
35+
dp_input = CustomCompatibleDatePickerInput()
36+
html = dp_input.render('input_name', '2018-04-12', {})
37+
snapshot = open('tests/snapshots/compatible-input-custom.html').read()
38+
self.assertEqual(html, snapshot)

tests/test_context_render.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
import re
66

77

8+
class CustomDatePickerInput(DatePickerInput):
9+
template_name = 'demo_app/custom_input/date-picker.html'
10+
11+
12+
class CustomTimePickerInput(TimePickerInput):
13+
template_name = 'demo_app/custom_input/time-picker.html'
14+
15+
816
class TestContextRender(SimpleTestCase):
917

1018
def test_get_context(self):
@@ -30,3 +38,20 @@ def test_time_input_snapshot(self):
3038
html = re.sub('dp_\\d+', '', html)
3139
snapshot = re.sub('dp_\\d+', '', snapshot)
3240
self.assertEqual(html, snapshot)
41+
42+
def test_custom_date_input_snapshot(self):
43+
dp_input = CustomDatePickerInput()
44+
html = dp_input.render('input_name', '2018-04-12', {})
45+
snapshot = open('tests/snapshots/date-input-custom.html').read()
46+
html = re.sub('dp_\\d+', '', html)
47+
snapshot = re.sub('dp_\\d+', '', snapshot)
48+
self.assertEqual(html, snapshot)
49+
50+
def test_custom_time_input_snapshot(self):
51+
dp_input = CustomTimePickerInput()
52+
html = dp_input.render('input_name', '12:30', {})
53+
snapshot = open('tests/snapshots/time-input-custom.html').read()
54+
html = re.sub('dp_\\d+', '', html)
55+
snapshot = re.sub('dp_\\d+', '', snapshot)
56+
self.assertEqual(html, snapshot)
57+

tests/test_settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
SECRET_KEY = 'fake-key'
77

88
INSTALLED_APPS = [
9+
"demo_project.demo_app",
910
"bootstrap_datepicker_plus"
1011
]
1112

0 commit comments

Comments
 (0)