File: text_spec.rb

package info (click to toggle)
ruby-simple-navigation 4.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 488 kB
  • ctags: 255
  • sloc: ruby: 3,693; makefile: 3
file content (51 lines) | stat: -rw-r--r-- 1,484 bytes parent folder | download
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
module SimpleNavigation
  module Renderer
    describe Text do
      let!(:navigation) { setup_navigation('nav_id', 'nav_class') }

      let(:item) { nil }
      let(:options) {{ level: :all }}
      let(:output) { renderer.render(navigation) }
      let(:renderer) { Text.new(options) }

      before { select_an_item(navigation[item]) if item }

      describe '#render' do
        context 'when no item is selected' do
          it 'renders an empty string' do
            expect(output).to eq ''
          end
        end

        context 'when an item is selected' do
          let(:item) { :invoices }

          it "renders the selected item's name" do
            expect(output).to eq 'Invoices'
          end
        end

        context 'when a sub navigation item is selected' do
          before do
            allow(navigation[:invoices]).to receive_messages(selected?: true)

            allow(navigation[:invoices].sub_navigation[:unpaid]).to \
              receive_messages(selected?: true, selected_by_condition?: true)
          end

          it 'separates the items with a space' do
            expect(output).to eq 'Invoices Unpaid'
          end

          context "and the :join_with option is set" do
            let(:options) {{ level: :all, join_with: ' | ' }}

            it 'separates the items with the specified separator' do
              expect(output).to eq 'Invoices | Unpaid'
            end
          end
        end
      end
    end
  end
end