Commit b596d927 authored by csillag's avatar csillag

Improve visual diff code

 - Simplify a check for an error condition
 - Add a test case to avoid regressing the same error
parent 584ff6a9
......@@ -133,8 +133,7 @@ AnnotationController = [
# hasDiff is set to true is there are any targets with a difference
# shouldShowDiff is set to true if there are some meaningful differences
# - that is, more than just uppercase / lowercase
diffFromTargets = (targets) ->
return {hasDiff: false, shouldShowDiff: false} unless targets?
diffFromTargets = (targets = []) ->
hasDiff = targets.some (t) ->
t.diffHTML?
shouldShowDiff = hasDiff and targets.some (t) ->
......
......@@ -127,6 +127,17 @@ describe 'h.directives.annotation', ->
controller.render()
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', ->
it 'sets `showDiff` to undefined and `hasDiff` to false', ->
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