Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
nonprofittechy committed Dec 5, 2023
1 parent c6d25c4 commit 6d694e9
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions docassemble/ALToolbox/test_misc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import re
import unittest
from unittest.mock import patch
from .misc import button_array, ButtonDict

class TestButtonArray(unittest.TestCase):

def normalize_whitespace(self, s):
return re.sub(r'\s+', ' ', s)

def test_button_array_generates_correct_html(self):
buttons = [
ButtonDict(name="Button 1", image="image1", url="url1"),
ButtonDict(name="Button 2", image="image2", url="url2"),
]
expected_html = self.normalize_whitespace(
'<div class="da-button-set da-field-buttons ">'
'<a class="btn btn-da btn-light btn-da btn-da-custom " href="url1">'
'<i class="fa fa-image1"></i> Button 1'
'</a>'
'<a class="btn btn-da btn-light btn-da btn-da-custom " href="url2">'
'<i class="fa fa-image2"></i> Button 2'
'</a>'
'</div>'
)
self.assertEqual(self.normalize_whitespace(button_array(buttons)), expected_html)

@patch('.misc.user_has_privilege', return_value=False)
def test_button_array_filters_by_privilege(self, mock_privilege):
buttons = [
ButtonDict(name="Button 1", image="image1", url="url1", privilege="admin"),
ButtonDict(name="Button 2", image="image2", url="url2"),
]
expected_html = self.normalize_whitespace(
'<div class="da-button-set da-field-buttons ">'
'<a class="btn btn-da btn-light btn-da btn-da-custom " href="url2">'
'<i class="fa fa-image2"></i> Button 2'
'</a>'
'</div>'
)
self.assertEqual(self.normalize_whitespace(button_array(buttons)), expected_html)

if __name__ == '__main__':
unittest.main()

0 comments on commit 6d694e9

Please sign in to comment.