Skip to content

Commit

Permalink
add test for every template tag to make sure they honour the change a…
Browse files Browse the repository at this point in the history
…rgument, improve the documentation
  • Loading branch information
fredkingham committed Apr 27, 2017
1 parent c182d82 commit 3c7bf53
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
8 changes: 7 additions & 1 deletion doc/docs/reference/form_templatetags.md
Expand Up @@ -15,6 +15,7 @@ Keywords:
[Inference from subrecord fields](#inference-from-subrecord-fields)
* `label` The Label with which to describe this field
* `model` The model which we are editing (This is a string that references an in-scope Angular variable)
* `change` A javascript function that fires if the field has changed
* `disabled` If this exists, we use this as the expression for the ng-disabled directive
* `element_name` If this exists this is an Angular expression that is set to the 'name' attribute of the html element

Expand All @@ -29,6 +30,7 @@ Keywords:
[Inference from subrecord fields](#inference-from-subrecord-fields)
* `label` The Label with which to describe this field
* `model` The model which we are editing (This is a string that references an in-scope Angular variable)
* `change` A javascript function that fires if the field has changed
* `show` A string that contains an Angular expression for the ng-show directive
* `hide` A string that contains an Angular expression for the ng-hide directive
* `required` Label to show when we're required
Expand All @@ -46,7 +48,7 @@ Keywords:
* `date_label` The Label with which to describe the date field (defaults to 'Date')
* `time_label` The Label with which to describe the date field (defaults to 'Time')
* `model` The model which we are editing (This is a string that references an in-scope Angular variable)
* `change` an Angular directive that fires on change
* `change` A javascript function that fires if the field has changed
* `element_name` If this exists this is an Angular expression that is set to the 'name' attribute of the html datetime picker element


Expand All @@ -61,6 +63,7 @@ Keywords:
[Inference from subrecord fields](#inference-from-subrecord-fields)
* `label` The Label with which to describe this field
* `model` The model which we are editing (This is a string that references an in-scope Angular variable)
* `change` A javascript function that fires if the field has changed
* `show` A string that contains an Angular expression for the ng-show directive
* `hide` A string that contains an Angular expression for the ng-hide directive
* `lookuplist` an Angular expression that evaluates to an array containing the lookuplist values
Expand Down Expand Up @@ -89,6 +92,7 @@ Keywords:
* `field` a string of the models api name '.' field from this it calculates the label, model and will infer the lookuplist if required. For example {% radio field="DogOwner.dog" %}
* `label` The Label with which to describe this input
* `model` The model which we are editing (This is a string that references an in-scope Angular variable)
* `change` A javascript function that fires if the field has changed
* `show` A string that contains an Angular expression for the ng-show directive
* `hide` A string that contains an Angular expression for the ng-hide directive
* `lookuplist` an Angular expression that evaluates to an array containing the radio values
Expand All @@ -104,6 +108,7 @@ Keywords:
* `field` a string of the models api name '.' field from this it calculates the label, model and will infer the lookuplist if required. For example {% select field="DogOwner.dog" %}
* `label` The Label with which to describe this input
* `model` The model which we are editing (This is a string that references an in-scope Angular variable)
* `change` A javascript function that fires if the field has changed
* `show` A string that contains an Angular expression for the ng-show directive
* `hide` A string that contains an Angular expression for the ng-hide directive
* `lookuplist` an Angular expression that evaluates to an array containing the radio values
Expand All @@ -121,6 +126,7 @@ Keywords:
* `field` a string of the models api name '.' field from this it calculates the label, model and will infer the lookuplist if required. For example {% textarea field="DogOwner.dog" %}
* `label` The Label with which to describe this input
* `model` The model which we are editing (This is a string that references an in-scope Angular variable)
* `change` A javascript function that fires if the field has changed
* `show` A string that contains an Angular expression for the ng-show directive
* `hide` A string that contains an Angular expression for the ng-hide directive
* `element_name` If this exists this is an Angular expression that is set to the 'name' attribute of the html element
Expand Down
30 changes: 30 additions & 0 deletions opal/tests/test_templatetags_forms.py
Expand Up @@ -109,6 +109,11 @@ def test_element_name(self):
rendered = tpl.render(Context({}))
self.assertIn('name="[[ onions ]]"', rendered)

def test_change(self):
tpl = Template('{% load forms %}{% textarea label="hai" change="doStuff" model="bai" element_name="onions"%}')
rendered = tpl.render(Context({}))
self.assertIn('ng-change="doStuff"', rendered)


class InputTest(TestCase):

Expand Down Expand Up @@ -196,6 +201,11 @@ def test_required_error(self):
rendered = tpl.render(Context({}))
self.assertIn('(form[onions].$dirty || form.$submitted) && form[onions].$error.required', rendered)

def test_change(self):
tpl = Template('{% load forms %}{% input label="hai" change="doStuff" model="bai" element_name="onions"%}')
rendered = tpl.render(Context({}))
self.assertIn('ng-change="doStuff"', rendered)


class CheckboxTestCase(TestCase):

Expand All @@ -215,6 +225,11 @@ def test_set_element_id(self):
rendered = tpl.render(Context({}))
self.assertIn('id="checkbox_[[ onions ]]"', rendered)

def test_change(self):
tpl = Template('{% load forms %}{% checkbox label="hai" change="doStuff" model="bai" element_name="onions"%}')
rendered = tpl.render(Context({}))
self.assertIn('ng-change="doStuff"', rendered)


class DatepickerTestCase(TestCase):

Expand Down Expand Up @@ -254,6 +269,11 @@ def test_show(self):
rendered = tpl.render(Context({}))
self.assertIn('ng-hide="onions"', rendered)

def test_change(self):
tpl = Template('{% load forms %}{% datepicker label="hai" change="doStuff" model="bai" element_name="onions"%}')
rendered = tpl.render(Context({}))
self.assertIn('ng-change="doStuff"', rendered)


class DateTimePickerTestCase(TestCase):
def test_generic(self):
Expand Down Expand Up @@ -321,6 +341,11 @@ def test_element_name_required(self):
rendered = tpl.render(Context({}))
self.assertIn('form.$submitted && form[onions].$error.required"', rendered)

def test_change(self):
tpl = Template('{% load forms %}{% radio label="hai" change="doStuff" model="bai" element_name="onions"%}')
rendered = tpl.render(Context({}))
self.assertIn('ng-change="doStuff"', rendered)


class SelectTestCase(TestCase):

Expand Down Expand Up @@ -370,6 +395,11 @@ def test_element_name_required(self):
rendered = tpl.render(Context({}))
self.assertIn('"form.$submitted && form[onions].$error.required"', rendered)

def test_change(self):
tpl = Template('{% load forms %}{% select label="hai" change="doStuff" model="bai" element_name="onions"%}')
rendered = tpl.render(Context({}))
self.assertIn('ng-change="doStuff"', rendered)


class StaticTestCase(TestCase):

Expand Down

0 comments on commit 3c7bf53

Please sign in to comment.