require 'spec_helper' describe LadyJosephine::SirTrevorHelper, type: :helper do include LadyJosephine::SirTrevorHelper describe '#render_sir_trevor' do it 'returns an empty string if no data is present' do expect(render_sir_trevor("{}")).to eq "" end it 'renders a text' do expect( render_sir_trevor("{\"server_uuid\":\"6cb3e116-fce1-4ae9-8e7f-d8007aec7542\",\"data\":[{\"type\":\"text\",\"data\":{\"note\":\"no\",\"uuid\":\"da0fb3fc-3c9b-42c5-a354-8fb21a29258a\",\"text\":\"This is Text\"}}]}") ).to eql "

This is Text

\n" end it 'does not render notes as default' do expect( render_sir_trevor("{\"server_uuid\":\"6cb3e116-fce1-4ae9-8e7f-d8007aec7542\",\"data\":[{\"type\":\"text\",\"data\":{\"note\":\"yes\",\"uuid\":\"da0fb3fc-3c9b-42c5-a354-8fb21a29258a\",\"text\":\"This is Text\"}}]}") ).to eql "" end it 'renders notes if I say so' do expect( render_sir_trevor("{\"server_uuid\":\"6cb3e116-fce1-4ae9-8e7f-d8007aec7542\",\"data\":[{\"type\":\"text\",\"data\":{\"note\":\"yes\",\"uuid\":\"da0fb3fc-3c9b-42c5-a354-8fb21a29258a\",\"text\":\"This is Text\"}}]}", false) ).to eql "

This is Text

\n" end context 'images' do let(:article) { Article.create(content_data: "{\"one\":\"two\"}") } let!(:image) do image = LadyJosephine::Image.from_params( "model-name" => "Article", "article-uuid" => article.lady_josephine_server_uuid, "column-name" => "image", "block-uuid" => "uuid-image", attachment: { file: File.new('spec/dummy/app/assets/images/depressed-cat.jpg') } ) image.save image end it 'renders a nice image' do expect( render_sir_trevor("{\"server_uuid\":\"6cb3e116-fce1-4ae9-8e7f-d8007aec7542\",\"data\":[{\"type\":\"extended_image\",\"data\":{\"uuid\":\"uuid-image\",\"note\":\"no\",\"style\":\"fullwidth\",\"file\":{\"url\":\"http://example.com/file_1.jpg\",\"large\":{\"url\":\"http://example.com/file_1_large.jpg\"},\"medium\":{\"url\":\"http://example.com/file_1_medium.jpg\"},\"small\":{\"url\":\"http://example.com/file_1_small.jpg\"}}}}]}") ).to eql "
\n" + "
\n" + "
\n" + "
\n" end end end describe '#component_attributes_for' do it 'should not render any class if the block is a note' do block = { "note" => "yes" } expect(component_attributes_for(block, ["one", {"two" => [ "three", "four"]}])).to eq({}) end it 'generates nice class names for a block' do block = { "note" => "no", "uuid" => "block-uuid", "references_count" => 2 } expect(component_attributes_for(block, ["one", {"two" => [ "three", "four"]}])).to eq({ "data-article_component"=>"block-uuid", "notes_count"=>2, "ng-class"=>"{'is-active': active}", "class"=>["one", "three--four"] }) end end describe "#sir_trevor_markdown" do it "renders html from a markdown text" do input = "**this** might be *important* for [bitcrowd](http://bitcrowd.net)" output = "this might be important for bitcrowd" expect(helper.sir_trevor_markdown(input)).to eq output end it "renders no list elements for ." do input = "123. test" expect(helper.sir_trevor_markdown(input)) .to eq(input) end it "renders dots correctly" do input = ". . . ddd .." expect(helper.sir_trevor_markdown(input)).to eq input end it "renders no list elements for an ordered list" do input = "1. test\n2. test2\n3. test3" output = "1. test
\n\n2. test2
\n\n3. test3" expect(helper.sir_trevor_markdown(input)).to eq output end end describe '#sir_trevor_video' do context 'youtube' do it 'generates a fullscreen youtube block if no note' do block = { "source" => "youtube", "note" => "no", "remote_id" => "remote-id" } expect(sir_trevor_video(block)).to eq "
" end it 'generates a embedded youtube block if note' do block = { "source" => "youtube", "note" => "yes", "remote_id" => "remote-id" } expect(sir_trevor_video(block)).to eq "
" end end it 'generates a vimeo block' do block = { "source" => "vimeo", "note" => "yes", "remote_id" => "remote-id" } expect(sir_trevor_video(block)).to eq "
" end it 'returns an empty string for an unknown provider' do block = { "source" => "unknown" } expect(sir_trevor_video(block)).to eq "" end end describe '#image_with_srcset_tag' do it 'creates a nice tag with srcset' do expect(image_with_srcset_tag("one, two", "sizes", {one: "true"})).to eql "" end end describe '#image_display_width' do it 'calculates the width based on the default height' do expect(image_display_width({"w2000" => {"ratio" => 1.5}})).to eql 930 end it 'calculates the width based on a given height' do expect(image_display_width({"w2000" => {"ratio" => 1.5}}, 200)).to eql 300 end end end