# encoding: utf-8 #Credit for this goes to https://github.com/julescopeland/Rails-Bootstrap-Navbar require 'spec_helper' require 'action_view' require 'active_support' require_relative '../../../app/helpers/railsstrap/navbar_helper' include ActionView::Helpers include ActionView::Context include Railsstrap::NavbarHelper describe Railsstrap::NavbarHelper, :type => :helper do before do allow(self).to receive(:uri_state) { :inactive } allow(self).to receive(:root_url) { '/' } end describe "nav_bar" do it "should return a basic railsstrap navbar" do expect(nav_bar.gsub(/\s/, '').downcase) .to eql(BASIC_NAVBAR.gsub(/\s/, '').downcase) end it "should set the fixed position to top" do expect(nav_bar(:fixed => :top).gsub(/\s/, '').downcase) .to eql(FIXED_TOP_NAVBAR.gsub(/\s/, '').downcase) end it "should set the static position to top" do expect(nav_bar(:static => :top).gsub(/\s/, '').downcase) .to eql(STATIC_TOP_NAVBAR.gsub(/\s/, '').downcase) end it "should set the fixed position to bottom" do expect(nav_bar(:fixed => :bottom).gsub(/\s/, '').downcase) .to eql(FIXED_BOTTOM_NAVBAR.gsub(/\s/, '').downcase) end it "should set the style to inverse" do expect(nav_bar(:inverse => true).gsub(/\s/, '').downcase) .to eql(INVERSE_NAVBAR.gsub(/\s/, '').downcase) end it "should add the brand name and link it to the home page" do expect(nav_bar(:brand => "Ninety Ten").gsub(/\s/, '').downcase) .to eql(NAVBAR_WITH_BRAND.gsub(/\s/, '').downcase) end it "should be able to set the brand link url" do expect(nav_bar(:brand => "Ninety Ten", :brand_link => "http://www.ninetyten.com").gsub(/\s/, '').downcase) .to eql(NAVBAR_WITH_BRAND_AND_LINK.gsub(/\s/, '').downcase) end it "should be able to set the brand link url without a turbolink" do expect(nav_bar(:brand => "Ninety Ten", :brand_link => "http://www.ninetyten.com", :no_turbolink => true).gsub(/\s/, '').downcase) .to eql(NAVBAR_WITH_BRAND_AND_LINK_TBLINK.gsub(/\s/, '').downcase) end it "should add the buttons etc for a responsive layout with no block passed" do expect(nav_bar(:responsive => true).gsub(/\s/, '').downcase).to eql(RESPONSIVE_NAVBAR.gsub(/\s/, '').downcase) end it "should add the buttons etc for a responsive layout with block passed" do ele = nav_bar(:responsive => true) do '
Passing a block
'.html_safe end expect(ele.gsub(/\s/, '').downcase).to eql(RESPONSIVE_NAVBAR_WITH_BLOCK.gsub(/\s/, '').downcase) end it "should render contained items" do ele = nav_bar do menu_group do menu_item("Home", "/") + menu_item("Products", "/products") end end expect(ele.gsub(/\s/, '').downcase).to eql(PLAIN_NAVBAR_WITH_ITEM.gsub(/\s/, '').downcase) end it "should still render the brand name even with other options turned on" do ele = nav_bar(:brand => "Something") do menu_group do menu_item "Home", "/" end end expect(ele.gsub(/\s/, '').downcase).to eql(BRANDED_NAVBAR_WITH_ITEM.gsub(/\s/, '').downcase) end end describe "menu_group" do it "should return a ul with the class 'nav'" do ele = menu_group do menu_item("Home", "/") + menu_item("Products", "/products") end expect(ele).to eql ' ' end it "should return a ul with class .navbar-left when passed the {:pull => :left} option" do ele = menu_group(:pull => :left) do menu_item("Home", "/") end expect(ele).to eql(' ') end end describe "menu_item" do it "should return a link within an li tag" do allow(self).to receive(:current_page?) { false } expect(menu_item("Home", "/")).to eql('I am being pulled right
") end it "should be able to cope with arbitrary options being passed to the p tag" do expect(menu_text("I am classy!", :class => "classy", :id => "classy_text")).to match("I am classy!
") end it "should be able to cope with a block too" do ele = menu_text("I have been rendered programmatically!") expect(ele).to have_tag(:p, with: {class: "navbar-text"}) expect(ele).to match "I have been rendered programmatically!" end end describe "rendering forms ok" do it "should not escape anything unexpectedly" do expect( nav_bar do form_tag "/", :method => 'get' do |f| f.text_field :search, "stub" end end ).to have_tag(:form) end end describe "default navbar" do it "renders a navbar" do expect(nav_bar { 'foo' }).to have_tag(:nav, with: { class: 'navbar navbar-default', role: 'navigation' }, text: /foo/) end end end # HTML output BASIC_NAVBAR = <<-HTML HTML FIXED_TOP_NAVBAR = <<-HTML HTML STATIC_TOP_NAVBAR = <<-HTML HTML FIXED_BOTTOM_NAVBAR = <<-HTML HTML INVERSE_NAVBAR = <<-HTML HTML NAVBAR_WITH_BRAND = <<-HTML HTML NAVBAR_WITH_BRAND_AND_LINK = <<-HTML HTML NAVBAR_WITH_BRAND_AND_LINK_TBLINK = <<-HTML HTML RESPONSIVE_NAVBAR = <<-HTML HTML RESPONSIVE_NAVBAR_WITH_BLOCK = <<-HTML HTML PLAIN_NAVBAR_WITH_ITEM = <<-HTML HTML BRANDED_NAVBAR_WITH_ITEM = <<-HTML HTML DROPDOWN_MENU = <<-HTML