-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
navbuilder/templates/navbuilder/inclusion_tags/breadcrumbs.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% load navbuilder_tags %} | ||
{% for crumb in navbuilder_breadcrumbs %} | ||
<a class="Crumb" href="{{ crumb.link.get_absolute_url }}" title="{{ crumb.link.title|default:crumb.title }}" target="{{ crumb.target|default:"" }}" data-slug="{{ crumb.link.slug|default:crumb.slug }}">{{ crumb.link.title|default:crumb.title }}</a> | ||
{% if not forloop.last %} > {% endif %} | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from django.core.urlresolvers import reverse | ||
from django.test import TestCase | ||
from django.test.client import Client | ||
|
||
from navbuilder import models | ||
from navbuilder.tests.test_base import load_fixtures, load_crumb_fixtures | ||
|
||
from django.template import Context, Template | ||
|
||
crumb_template_1 = Template( | ||
"{% load navbuilder_tags %}" | ||
"{% navbuilder_breadcrumbs 'menu-1' %}" | ||
) | ||
|
||
crumb_template_2 = Template( | ||
"{% load navbuilder_tags %}" | ||
"{% navbuilder_breadcrumbs 'menu-2' %}" | ||
) | ||
|
||
crumb_template_3 = Template( | ||
"{% load navbuilder_tags %}" | ||
"{% navbuilder_breadcrumbs 'menu-3' %}" | ||
) | ||
|
||
|
||
class BreadcrumbsTestCase(TestCase): | ||
def setUp(self): | ||
self.client = Client() | ||
load_fixtures(self) | ||
load_crumb_fixtures(self) | ||
# Reorganise the items | ||
self.menuitem.link = None | ||
self.sub_menuitem_2.link = self.link | ||
|
||
|
||
def test_single_level(self): | ||
# The link object maps to a single level in menu 2 | ||
out = crumb_template_2.render(Context({"object": self.link})) | ||
self.assertHTMLEqual(out, """ | ||
<a class="Crumb" href="/link/1/" title="Link 1" | ||
target="" data-slug="link-1"> | ||
Link 1 | ||
</a> | ||
""" | ||
) | ||
|
||
def test_multilevel(self): | ||
# The link object maps to the submenu in menu 1 | ||
out = crumb_template_1.render(Context({"object": self.link})) | ||
self.assertHTMLEqual(out, """ | ||
<a class="Crumb" href="/link/1/" | ||
title="Link 1" target="" data-slug="link-1"> | ||
Link 1 | ||
</a> | ||
> | ||
<a class="Crumb" data-slug="link-1" href="/link/1/" | ||
target="blank" title="Link 1"> | ||
Link 1 | ||
</a> | ||
""" | ||
) | ||
|
||
def test_menu_slug_not_found(self): | ||
# If we cannot identify the menu it comes from, take the first one. | ||
out = crumb_template_3.render(Context({"object": self.link})) | ||
self.assertIn("Link 1", out) | ||
|
||
def test_no_matching_menuitem(self): | ||
# If the object does not show up in any menu, render nothing | ||
self.menuitem_2.link = None | ||
out = crumb_template_3.render(Context({"object": self.link_2})) | ||
self.assertHTMLEqual("", out) | ||
|
||
def tearDown(self): | ||
pass |