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" 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