aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/helper/sidebar_helper_test.rb
blob: 89b0fb327bee920bb50340a1b85580cd4f80fb15 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# This file is part of hmnoweb, a RefineryCMS based Webapp for heavymetal.no
# Copyright (C) 2018  Harald Eilertsen <haraldei@anduin.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License version 3
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

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