Commit b6ae16c1 authored by gergely-ujvari's avatar gergely-ujvari

Merge pull request #1725 from hypothesis/improve-show-diff

Improve visual diff code
parents 3983f7dd b596d927
...@@ -133,8 +133,7 @@ AnnotationController = [ ...@@ -133,8 +133,7 @@ AnnotationController = [
# hasDiff is set to true is there are any targets with a difference # hasDiff is set to true is there are any targets with a difference
# shouldShowDiff is set to true if there are some meaningful differences # shouldShowDiff is set to true if there are some meaningful differences
# - that is, more than just uppercase / lowercase # - that is, more than just uppercase / lowercase
diffFromTargets = (targets) -> diffFromTargets = (targets = []) ->
return {hasDiff: false, shouldShowDiff: false} unless targets?
hasDiff = targets.some (t) -> hasDiff = targets.some (t) ->
t.diffHTML? t.diffHTML?
shouldShowDiff = hasDiff and targets.some (t) -> shouldShowDiff = hasDiff and targets.some (t) ->
......
...@@ -127,6 +127,17 @@ describe 'h.directives.annotation', -> ...@@ -127,6 +127,17 @@ describe 'h.directives.annotation', ->
controller.render() controller.render()
assert.isNull(controller.document) assert.isNull(controller.document)
describe 'when there are no targets', ->
beforeEach ->
annotation.target = []
controller.render()
targets = controller.annotation.target
it 'sets `hasDiff` to false and `showDiff` to undefined', ->
controller.render()
assert.isFalse(controller.hasDiff)
assert.isUndefined(controller.showDiff)
describe 'when a single target has text identical to what was in the selectors', -> describe 'when a single target has text identical to what was in the selectors', ->
it 'sets `showDiff` to undefined and `hasDiff` to false', -> it 'sets `showDiff` to undefined and `hasDiff` to false', ->
controller.render() controller.render()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment