2023-10-18 14:26:10 -07:00
# frozen_string_literal: true
2022-01-10 13:15:50 -08:00
require " rails_helper "
2023-10-18 14:26:10 -07:00
describe BootstrapHelper , type : :helper do
2022-07-19 08:18:27 -07:00
include ActiveSupport :: Testing :: TimeHelpers
2023-10-18 14:26:10 -07:00
describe " # nav_entry " do
it " should return a HTML navigation item which links to a given address " do
2022-01-10 13:15:50 -08:00
allow ( self ) . to receive ( :current_page? ) . and_return ( false )
2023-10-18 14:26:10 -07:00
expect ( nav_entry ( " Example " , " /example " ) ) . to (
eq ( '<li class="nav-item "><a class="nav-link" href="/example">Example</a></li>' ) ,
2022-01-10 13:15:50 -08:00
)
end
2023-10-18 14:26:10 -07:00
it " should return with an active attribute if the link matches the current URL " do
2022-01-10 13:15:50 -08:00
allow ( self ) . to receive ( :current_page? ) . and_return ( true )
2023-10-18 14:26:10 -07:00
expect ( nav_entry ( " Example " , " /example " ) ) . to (
eq ( '<li class="nav-item active "><a class="nav-link" href="/example">Example</a></li>' ) ,
2022-01-10 13:15:50 -08:00
)
end
2023-10-18 14:26:10 -07:00
it " should include an icon if given " do
2022-01-10 13:15:50 -08:00
allow ( self ) . to receive ( :current_page? ) . and_return ( false )
2023-10-18 14:26:10 -07:00
expect ( nav_entry ( " Example " , " /example " , icon : " beaker " ) ) . to (
eq ( '<li class="nav-item "><a class="nav-link" href="/example"><i class="fa fa-beaker"></i> Example</a></li>' ) ,
2022-01-10 13:15:50 -08:00
)
end
2023-10-18 14:26:10 -07:00
it " should only include an icon if wanted " do
2022-01-10 13:15:50 -08:00
allow ( self ) . to receive ( :current_page? ) . and_return ( false )
2023-10-18 14:26:10 -07:00
expect ( nav_entry ( " Example " , " /example " , icon : " beaker " , icon_only : true ) ) . to (
eq ( '<li class="nav-item "><a class="nav-link" href="/example"><i class="fa fa-beaker" title="Example"></i></a></li>' ) ,
2022-01-10 13:15:50 -08:00
)
end
2023-10-18 14:26:10 -07:00
it " should include a badge if given " do
2022-01-10 13:15:50 -08:00
allow ( self ) . to receive ( :current_page? ) . and_return ( false )
2023-10-18 14:26:10 -07:00
expect ( nav_entry ( " Example " , " /example " , badge : 3 ) ) . to (
eq ( '<li class="nav-item "><a class="nav-link" href="/example">Example <span class="badge">3</span></a></li>' ) ,
2022-01-10 13:15:50 -08:00
)
2023-10-18 14:26:10 -07:00
expect ( nav_entry ( " Example " , " /example " , badge : 3 , badge_color : " primary " , badge_pill : true ) ) . to (
eq ( '<li class="nav-item "><a class="nav-link" href="/example">Example <span class="badge badge-primary badge-pill">3</span></a></li>' ) ,
2022-01-10 13:15:50 -08:00
)
end
2023-08-16 12:19:05 -07:00
2023-08-18 10:43:59 -07:00
it " should put an ID on the entry an id if given " do
2023-08-16 12:19:05 -07:00
allow ( self ) . to receive ( :current_page? ) . and_return ( false )
2023-08-18 10:43:59 -07:00
expect ( nav_entry ( " Example " , " /example " , id : " testing " ) ) . to (
eq ( " <li class= \" nav-item \" id= \" testing \" ><a class= \" nav-link \" href= \" /example \" >Example</a></li> " ) ,
2023-08-16 12:19:05 -07:00
)
end
2022-01-10 13:15:50 -08:00
end
describe " # list_group_item " do
2023-10-18 14:26:10 -07:00
it " should return a HTML navigation item which links to a given address " do
2022-01-10 13:15:50 -08:00
allow ( self ) . to receive ( :current_page? ) . and_return ( false )
2023-10-18 14:26:10 -07:00
expect ( list_group_item ( " Example " , " /example " ) ) . to (
eq ( '<a href="/example" class="list-group-item list-group-item-action ">Example</a>' ) ,
2022-01-10 13:15:50 -08:00
)
end
2023-10-18 14:26:10 -07:00
it " should return with an active attribute if the link matches the current URL " do
2022-01-10 13:15:50 -08:00
allow ( self ) . to receive ( :current_page? ) . and_return ( true )
2023-10-18 14:26:10 -07:00
expect ( list_group_item ( " Example " , " /example " ) ) . to (
eq ( '<a href="/example" class="list-group-item list-group-item-action active ">Example</a>' ) ,
2022-01-10 13:15:50 -08:00
)
end
2023-10-18 14:26:10 -07:00
it " should include a badge if given " do
2022-01-10 13:15:50 -08:00
allow ( self ) . to receive ( :current_page? ) . and_return ( false )
2023-10-18 14:26:10 -07:00
expect ( list_group_item ( " Example " , " /example " , badge : 3 ) ) . to (
eq ( '<a href="/example" class="list-group-item list-group-item-action ">Example <span class="badge">3</span></a>' ) ,
2022-01-10 13:15:50 -08:00
)
end
end
describe " # bootstrap_color " do
2023-10-18 14:26:10 -07:00
it " should map error and alert to danger " do
2022-01-10 13:15:50 -08:00
expect ( bootstrap_color ( " error " ) ) . to eq ( " danger " )
expect ( bootstrap_color ( " alert " ) ) . to eq ( " danger " )
end
2023-10-18 14:26:10 -07:00
it " should map notice to info " do
2022-01-10 13:15:50 -08:00
expect ( bootstrap_color ( " notice " ) ) . to eq ( " info " )
end
2023-10-18 14:26:10 -07:00
it " should return any uncovered value " do
2022-01-10 13:15:50 -08:00
expect ( bootstrap_color ( " success " ) ) . to eq ( " success " )
end
end
describe " # tooltip " do
2023-10-18 14:26:10 -07:00
it " should return the proper markup " do
2023-01-04 08:35:17 -08:00
expect ( tooltip ( " Example Text " , " This is in a tooltip " ) ) . to eq ( " <span title= \" This is in a tooltip \" data-bs-toggle= \" tooltip \" data-bs-placement= \" bottom \" >Example Text</span> " )
2022-01-10 13:15:50 -08:00
end
end
describe " # time_tooltip " do
2023-10-18 14:26:10 -07:00
it " should return a tooltip with proper time values " do
2022-07-19 08:18:27 -07:00
travel_to ( Time . utc ( 1984 ) ) do
2022-01-10 13:15:50 -08:00
@user = FactoryBot . create ( :user )
2022-07-19 08:18:27 -07:00
travel 10 . minutes
2022-01-10 13:15:50 -08:00
2024-03-02 13:39:30 -08:00
expect ( time_tooltip ( @user ) ) . to eq ( " <span title= \" January 01, 1984 00:00 \" data-bs-toggle= \" tooltip \" data-bs-placement= \" bottom \" >10m</span> " )
2022-01-10 13:15:50 -08:00
end
end
end
2022-07-19 08:18:27 -07:00
end