aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2013-12-25 17:44:04 +0100
committerHarald Eilertsen <haraldei@anduin.net>2013-12-25 17:44:04 +0100
commit65566d1134c544933d7bea1f7bfa1f50bd9f531f (patch)
treec6e7877649a243fed4253b994c0eb925e1c7c3cc /test
parent83397f964d06c5aff991ccb81bf2bbe69b397a90 (diff)
downloadhmnoweb-65566d1134c544933d7bea1f7bfa1f50bd9f531f.tar.gz
hmnoweb-65566d1134c544933d7bea1f7bfa1f50bd9f531f.tar.bz2
hmnoweb-65566d1134c544933d7bea1f7bfa1f50bd9f531f.zip
Add tests for sidebar helper.
Also fixes DOM id of sidebar modules with spaces in their title.
Diffstat (limited to 'test')
-rw-r--r--test/unit/helper/sidebar_helper_test.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/unit/helper/sidebar_helper_test.rb b/test/unit/helper/sidebar_helper_test.rb
new file mode 100644
index 0000000..10ae63f
--- /dev/null
+++ b/test/unit/helper/sidebar_helper_test.rb
@@ -0,0 +1,50 @@
+require File.dirname(__FILE__) + '/../../test_helper'
+require 'action_view/test_case'
+
+class SidebarHelperTest < ActionView::TestCase
+ def setup
+ setup_with_controller
+ end
+
+ test "should not render anything if no modules" do
+ result = render_sidebar_modules []
+ assert_select ".sidebar_module", :count => 0
+ end
+
+ test "should only render modules with matching position" do
+ modules = [
+ SidebarModule.new("Module 1", "Module 1 body", 1),
+ SidebarModule.new("Module 2", "Module 2 body", 2)
+ ]
+
+ result = render_sidebar_modules(modules, :position => 2)
+ assert_select ".sidebar_module", :count => 1
+ assert_select "#sidebar_module_module-1", :count => 0
+ assert_select "#sidebar_module_module-2", :count => 1
+ end
+
+ test "should render all modules if no position given" do
+ modules = [
+ SidebarModule.new("Module 1", "Module 1 body", 1),
+ SidebarModule.new("Module 2", "Module 2 body", 2)
+ ]
+
+ result = render_sidebar_modules(modules)
+ assert_select ".sidebar_module", :count => 2
+ assert_select "#sidebar_module_module-1", :count => 1
+ assert_select "#sidebar_module_module-2", :count => 1
+ end
+
+ test "should not render modules with empty body" do
+ modules = [
+ SidebarModule.new("Module 1", "", 1),
+ SidebarModule.new("Module 2", "Module 2 body", 1)
+ ]
+
+ result = render_sidebar_modules(modules)
+ assert_select ".sidebar_module", :count => 1
+ assert_select "#sidebar_module_module-1", :count => 0
+ assert_select "#sidebar_module_module-2", :count => 1
+ end
+end
+