require 'spec_helper' describe Nutmeg::TagTreeHelper do before(:each) do @tree_from_yaml = Nutmeg::TreeFromYaml.new({file: [Dir.pwd, "/spec/files/tree.yml"].join}) data = File.open([Dir.pwd, "/spec/files/tree.json"].join) @tree_from_json = Nutmeg::TreeFromJson.new(data) end describe "#print_html" do it "outputs html" do expect(Nutmeg::TagTreeHelper.new(@tree_from_yaml.tree).print_html([1]).class).to eq(String) expect(Nutmeg::TagTreeHelper.new(@tree_from_yaml.tree).print_html(["north", "men", "collections", "summer_2015"])).to eq("") end it "outputs html for subtree" do subtree = @tree_from_yaml.tree.subtree("north") expect(Nutmeg::TagTreeHelper.new(subtree).print_html(["men", "collections", "summer_2015"])).to eq("") end it "outputs html for subtree (greedy)" do subtree = @tree_from_yaml.tree.subtree("north") expect(Nutmeg::TagTreeHelper.new(subtree).print_html(["men", "collections"],true)).to eq("") end context "from json" do it "outputs html for subtree" do subtree = @tree_from_json.tree expect(Nutmeg::TagTreeHelper.new(subtree, {:prepend_path => "/nl/t"}).print_html(["men", "collections"],false)).to eq("") end context "additional leaf content" do it "renders additional content in the leaf" do subtree = @tree_from_json.tree expect(Nutmeg::TagTreeHelper.new(subtree, {:prepend_path => "/nl/t"}).print_html(["north", "men", "footwear"],false, "Extra content")).to eq("") end end context "Wrapping ul element" do it "do not return wrapping ul" do subtree = @tree_from_json.tree expect(Nutmeg::TagTreeHelper.new(subtree, {:prepend_path => "/nl/t"}).print_html(["north", "men", "footwear"],false, "Extra content", true)).to eq("
  • North
  • South
  • ") end end context "Big tree with complex structure" do it "returns the correct html" do data = File.open([Dir.pwd, "/spec/files/big_tree.json"].join) @tree_from_json = Nutmeg::TreeFromJson.new(data) subtree = @tree_from_json.tree.subtree("north") tree_html = Nutmeg::TagTreeHelper.new(subtree).print_html(["north", "about", "milestones", "2014", "the-netherlands"], true) expect(tree_html).to include("About