mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Show a correct diff when editing consecutive paragraphs (#8177)
This commit is contained in:
committed by
Régis Hanol
parent
694a5bf229
commit
7d2f5240d9
@@ -76,6 +76,13 @@ describe DiscourseDiff do
|
||||
expect(DiscourseDiff.new(before, after).side_by_side_html).to eq("<div class=\"revision-content\"><p>this is a paragraph</p></div><div class=\"revision-content\"><p>this is a <ins>great </ins>paragraph</p></div>")
|
||||
end
|
||||
|
||||
it "adds <ins> and <del> tags on consecutive paragraphs", :focus do
|
||||
before = "<p>this is one paragraph</p><p>here is yet another</p>"
|
||||
after = "<p>this is one great paragraph</p><p>here is another</p>"
|
||||
got = DiscourseDiff.new(before, after).side_by_side_html
|
||||
expect(got).to eq("<div class=\"revision-content\"><p>this is one paragraph</p><p>here is <del>yet </del>another</p></div><div class=\"revision-content\"><p>this is one <ins>great </ins>paragraph</p><p>here is another</p></div>")
|
||||
end
|
||||
|
||||
it "adds <del> tags around removed text on the left div" do
|
||||
before = "<p>this is a great paragraph</p>"
|
||||
after = "<p>this is a paragraph</p>"
|
||||
|
||||
@@ -39,4 +39,38 @@ describe ONPDiff do
|
||||
|
||||
end
|
||||
|
||||
describe "paragraph_diff" do
|
||||
|
||||
it "returns an empty array when there is no content to diff" do
|
||||
expect(ONPDiff.new("", "").paragraph_diff).to eq([])
|
||||
end
|
||||
|
||||
it "returns an array with the operation code for each element" do
|
||||
expect(ONPDiff.new("abc", "acd").paragraph_diff).to eq([["a", :common], ["b", :delete], ["c", :common], ["d", :add]])
|
||||
end
|
||||
|
||||
it "pairs as many elements as possible", :focus do
|
||||
expect(ONPDiff.new("abcd", "abef").paragraph_diff).to eq([
|
||||
["a", :common], ["b", :common],
|
||||
["e", :add], ["c", :delete],
|
||||
["f", :add], ["d", :delete]
|
||||
])
|
||||
|
||||
expect(ONPDiff.new("abcde", "abfg").paragraph_diff).to eq([
|
||||
["a", :common], ["b", :common],
|
||||
["c", :delete],
|
||||
["d", :delete], ["f", :add],
|
||||
["e", :delete], ["g", :add]
|
||||
])
|
||||
|
||||
expect(ONPDiff.new("abcd", "abefg").paragraph_diff).to eq([
|
||||
["a", :common], ["b", :common],
|
||||
["e", :add],
|
||||
["f", :add], ["c", :delete],
|
||||
["g", :add], ["d", :delete]
|
||||
])
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user