diff --git a/pattern_library/urls.py b/pattern_library/urls.py index 1d2fdcbb..a9b1e0ed 100644 --- a/pattern_library/urls.py +++ b/pattern_library/urls.py @@ -7,14 +7,14 @@ # UI re_path(r"^$", views.IndexView.as_view(), name="index"), re_path( - r"^pattern/(?P[\w./-\\]+%s)$" + r"^pattern/(?P[\w./\-\\]+%s)$" % (get_pattern_template_suffix()), views.IndexView.as_view(), name="display_pattern", ), # iframe rendering re_path( - r"^render-pattern/(?P[\w./-\\]+%s)$" + r"^render-pattern/(?P[\w./\-\\]+%s)$" % (get_pattern_template_suffix()), views.RenderPatternView.as_view(), name="render_pattern", diff --git a/tests/templates/patterns/molecules/test-molecule/test-molecule.html b/tests/templates/patterns/molecules/test-molecule/test-molecule.html new file mode 100644 index 00000000..8e39b114 --- /dev/null +++ b/tests/templates/patterns/molecules/test-molecule/test-molecule.html @@ -0,0 +1 @@ +template-with-dash diff --git a/tests/tests/test_views.py b/tests/tests/test_views.py index e8f9d00b..0db616c1 100644 --- a/tests/tests/test_views.py +++ b/tests/tests/test_views.py @@ -59,6 +59,30 @@ def test_pretty_names_from_filename(self): self.assertEqual(display_link.text.strip(), "test_molecule_no_context.html") self.assertEqual(render_link.text.strip(), pattern_path) + def test_pretty_names_from_filename_containing_dashes(self): + pattern_path = "patterns/molecules/test-molecule/test-molecule.html" + test_molecule_display_url = reverse( + "pattern_library:display_pattern", + kwargs={"pattern_template_name": pattern_path}, + ) + test_molecule_render_url = reverse( + "pattern_library:render_pattern", + kwargs={"pattern_template_name": pattern_path}, + ) + + response = self.client.get(test_molecule_display_url) + self.assertEqual(response.status_code, 200) + + soup = BeautifulSoup(response.content, features="html.parser") + + display_link = soup.select_one( + f'.list__item>a[href="{test_molecule_display_url}"]' + ) + render_link = soup.select_one(f'a[href="{test_molecule_render_url}"]') + + self.assertEqual(display_link.text.strip(), "test-molecule.html") + self.assertEqual(render_link.text.strip(), pattern_path) + def test_includes(self): pattern_path = "patterns/atoms/test_includes/test_includes.html" display_url = reverse( @@ -92,6 +116,7 @@ def test_fragments(self): for template_name in [ "patterns/atoms/test_atom/test_atom.html", "patterns/molecules/test_molecule/test_molecule.html", + "patterns/molecules/test-molecule/test-molecule.html", ]: with self.subTest(template_name=template_name): self.assertContains(