require 'spec_helper' require 'discourse_diff' describe DiscourseDiff do describe "inline_html" do it "does not lead to XSS" do a = "start" b = "end" prev = "
#{CGI::escapeHTML(a)}
" cur = "
#{CGI::escapeHTML(b)}
" diff = DiscourseDiff.new(prev,cur) diff.inline_html.should_not =~ /<\/?test>/ diff.side_by_side_html.should_not =~ /<\/?test>/ end it "returns an empty div when no content is diffed" do DiscourseDiff.new("", "").inline_html.should == "
" end it "returns the diffed content when there is no difference" do before = after = "

this is a paragraph

" DiscourseDiff.new(before, after).inline_html.should == "

this is a paragraph

" end it "adds tags around added text" do before = "

this is a paragraph

" after = "

this is a great paragraph

" DiscourseDiff.new(before, after).inline_html.should == "

this is a great paragraph

" end it "adds tags around removed text" do before = "

this is a great paragraph

" after = "

this is a paragraph

" DiscourseDiff.new(before, after).inline_html.should == "

this is a great paragraph

" end it "adds .diff-ins class when a paragraph is added" do before = "

this is the first paragraph

" after = "

this is the first paragraph

this is the second paragraph

" DiscourseDiff.new(before, after).inline_html.should == "

this is the first paragraph

this is the second paragraph

" end it "adds .diff-del class when a paragraph is removed" do before = "

this is the first paragraph

this is the second paragraph

" after = "

this is the second paragraph

" DiscourseDiff.new(before, after).inline_html.should == "

this is the first paragraph

this is the second paragraph

" end end describe "side_by_side_html" do it "returns two empty divs when no content is diffed" do DiscourseDiff.new("", "").side_by_side_html.should == "
" end it "returns the diffed content on both sides when there is no difference" do before = after = "

this is a paragraph

" DiscourseDiff.new(before, after).side_by_side_html.should == "

this is a paragraph

this is a paragraph

" end it "adds tags around added text on the right div" do before = "

this is a paragraph

" after = "

this is a great paragraph

" DiscourseDiff.new(before, after).side_by_side_html.should == "

this is a paragraph

this is a great paragraph

" end it "adds tags around removed text on the left div" do before = "

this is a great paragraph

" after = "

this is a paragraph

" DiscourseDiff.new(before, after).side_by_side_html.should == "

this is a great paragraph

this is a paragraph

" end it "adds .diff-ins class when a paragraph is added" do before = "

this is the first paragraph

" after = "

this is the first paragraph

this is the second paragraph

" DiscourseDiff.new(before, after).side_by_side_html.should == "

this is the first paragraph

this is the first paragraph

this is the second paragraph

" end it "adds .diff-del class when a paragraph is removed" do before = "

this is the first paragraph

this is the second paragraph

" after = "

this is the second paragraph

" DiscourseDiff.new(before, after).side_by_side_html.should == "

this is the first paragraph

this is the second paragraph

this is the second paragraph

" end end describe "side_by_side_markdown" do it "returns an empty table when no content is diffed" do DiscourseDiff.new("", "").side_by_side_markdown.should == "
" end it "properly escape html tags" do before = "" after = "\"" DiscourseDiff.new(before, after).side_by_side_markdown.should == "
<img src="//domain.com/image.png>"
" end it "returns the diffed content on both columns when there is no difference" do before = after = "this is a paragraph" DiscourseDiff.new(before, after).side_by_side_markdown.should == "
this is a paragraphthis is a paragraph
" end it "adds tags around added text on the second column" do before = "this is a paragraph" after = "this is a great paragraph" DiscourseDiff.new(before, after).side_by_side_markdown.should == "
this is a paragraphthis is a great paragraph
" end it "adds tags around removed text on the first column" do before = "this is a great paragraph" after = "this is a paragraph" DiscourseDiff.new(before, after).side_by_side_markdown.should == "
this is a great paragraphthis is a paragraph
" end it "adds .diff-ins class when a paragraph is added" do before = "this is the first paragraph" after = "this is the first paragraph\nthis is the second paragraph" DiscourseDiff.new(before, after).side_by_side_markdown.should == "
this is the first paragraphthis is the first paragraph\nthis is the second paragraph
" end it "adds .diff-del class when a paragraph is removed" do before = "this is the first paragraph\nthis is the second paragraph" after = "this is the second paragraph" DiscourseDiff.new(before, after).side_by_side_markdown.should == "
this is the first paragraph\n
this is the second paragraphthis is the second paragraph
" end end end