Files
grecia/spec/helpers/link_list_helper_spec.rb
Javi Martín d1ab8ac29b Split li tags in link list helper
This way we generate the same HTML as we generate everywhere where we
manually generate lists of links. Having a blank space betwwen tags
results in a space being introduced when the elements are displayed
inline (or with `inline-block`).

So in places where we don't want that space between the elements we have
to use a flex layout.
2021-01-27 15:56:58 +01:00

75 lines
2.3 KiB
Ruby

require "rails_helper"
describe LinkListHelper do
describe "#link_list" do
it "returns an empty string with an empty list" do
expect(helper.link_list).to eq ""
end
it "returns nothing with a list of nil elements" do
expect(helper.link_list(nil, nil)).to eq ""
end
it "generates a list of links" do
list = helper.link_list(["Home", "/"], ["Info", "/info"], class: "menu")
expect(list).to eq '<ul class="menu">' +
'<li><a href="/">Home</a></li>' + "\n" +
'<li><a href="/info">Info</a></li></ul>'
expect(list).to be_html_safe
end
it "accepts options for links" do
render helper.link_list(["Home", "/", class: "root"], ["Info", "/info", id: "info"])
expect(page).to have_css "a", count: 2
expect(page).to have_css "a.root", count: 1, exact_text: "Home"
expect(page).to have_css "a#info", count: 1, exact_text: "Info"
end
it "ignores nil entries" do
render helper.link_list(["Home", "/", class: "root"], nil, ["Info", "/info", id: "info"])
expect(page).to have_css "a", count: 2
expect(page).to have_css "a.root", count: 1, exact_text: "Home"
expect(page).to have_css "a#info", count: 1, exact_text: "Info"
end
it "accepts an optional condition to check the active element" do
render helper.link_list(
["Home", "/", false],
["Info", "/info", true],
["Help", "/help"]
)
expect(page).to have_css "li", count: 3
expect(page).to have_css "li[aria-current='true']", count: 1, exact_text: "Info"
end
it "allows passing both the active condition and link options" do
render helper.link_list(
["Home", "/", false, class: "root"],
["Info", "/info", true, id: "info"],
["Help", "/help", rel: "help"]
)
expect(page).to have_css "li", count: 3
expect(page).to have_css "li[aria-current='true']", count: 1, exact_text: "Info"
expect(page).to have_css "a.root", count: 1, exact_text: "Home"
expect(page).to have_css "a#info", count: 1, exact_text: "Info"
expect(page).to have_css "a[rel='help']", count: 1, exact_text: "Help"
end
end
attr_reader :content
def render(content)
@content = content
end
def page
Capybara::Node::Simple.new(content)
end
end