BuildTest: close menu, ignore whitespace diffs, better first diff finding
This commit is contained in:
parent
deedfba851
commit
a914a29380
@ -1,7 +1,7 @@
|
|||||||
<% if (tests_enabled) { %>
|
<% if (tests_enabled) { %>
|
||||||
BuildTest =
|
BuildTest =
|
||||||
init: ->
|
init: ->
|
||||||
return if !Conf['Menu']
|
return if !Conf['Menu'] or g.VIEW is 'catalog'
|
||||||
|
|
||||||
a = $.el 'a',
|
a = $.el 'a',
|
||||||
textContent: 'Test HTML building'
|
textContent: 'Test HTML building'
|
||||||
@ -18,38 +18,44 @@ BuildTest =
|
|||||||
Header.menu.addEntry
|
Header.menu.addEntry
|
||||||
el: a2
|
el: a2
|
||||||
|
|
||||||
|
firstDiff: (x, y) ->
|
||||||
|
x2 = x.cloneNode false
|
||||||
|
y2 = y.cloneNode false
|
||||||
|
if !x2.isEqualNode y2
|
||||||
|
return [x2, y2]
|
||||||
|
i = 0
|
||||||
|
while (x2 = x.childNodes[i]) and (y2 = y.childNodes[i++])
|
||||||
|
if !x2.isEqualNode y2
|
||||||
|
return BuildTest.firstDiff x2, y2
|
||||||
|
return [x2, y2]
|
||||||
|
|
||||||
runTest: (post) ->
|
runTest: (post) ->
|
||||||
$.cache "//a.4cdn.org/#{post.board.ID}/thread/#{post.thread.ID}.json", ->
|
$.cache "//a.4cdn.org/#{post.board.ID}/thread/#{post.thread.ID}.json", ->
|
||||||
for postData in @response.posts
|
for postData in @response.posts
|
||||||
if postData.no is post.ID
|
if postData.no is post.ID
|
||||||
root = Build.postFromObject postData, post.board.ID
|
root = Build.postFromObject postData, post.board.ID
|
||||||
post2 = new Post root, post.thread, post.board
|
post2 = new Post root, post.thread, post.board
|
||||||
if post.normalizedOriginal.isEqualNode post2.normalizedOriginal
|
x = post.normalizedOriginal
|
||||||
|
y = post2.normalizedOriginal
|
||||||
|
if x.isEqualNode y
|
||||||
c.log "#{post.fullID} correct"
|
c.log "#{post.fullID} correct"
|
||||||
else
|
else
|
||||||
c.log "#{post.fullID} differs"
|
c.log "#{post.fullID} differs"
|
||||||
html = post.normalizedOriginal.innerHTML
|
[x2, y2] = BuildTest.firstDiff x, y
|
||||||
html2 = post2.normalizedOriginal.innerHTML
|
c.log x2
|
||||||
if html is html2
|
c.log y2
|
||||||
c.log post.normalizedOriginal.outerHTML
|
c.log x.outerHTML
|
||||||
c.log post2.normalizedOriginal.outerHTML
|
c.log y.outerHTML
|
||||||
else
|
|
||||||
i = 0
|
|
||||||
while i < html.length and i < html2.length
|
|
||||||
break unless html[i] is html2[i]
|
|
||||||
i++
|
|
||||||
c.log html[i..i+80]
|
|
||||||
c.log html2[i..i+80]
|
|
||||||
c.log html
|
|
||||||
c.log html2
|
|
||||||
post2.isFetchedQuote = true
|
post2.isFetchedQuote = true
|
||||||
Main.callbackNodes Post, [post2]
|
Main.callbackNodes Post, [post2]
|
||||||
|
|
||||||
testOne: ->
|
testOne: ->
|
||||||
BuildTest.runTest g.posts[@dataset.fullID]
|
BuildTest.runTest g.posts[@dataset.fullID]
|
||||||
|
Menu.menu.close()
|
||||||
|
|
||||||
testAll: ->
|
testAll: ->
|
||||||
g.posts.forEach (post) ->
|
g.posts.forEach (post) ->
|
||||||
unless post.isClone or post.isFetchedQuote or $ '.abbr', post.nodes.comment
|
unless post.isClone or post.isFetchedQuote or $ '.abbr', post.nodes.comment
|
||||||
BuildTest.runTest post
|
BuildTest.runTest post
|
||||||
|
Header.menu.close()
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|||||||
@ -15,6 +15,10 @@ class Post
|
|||||||
el.removeAttribute 'rel'
|
el.removeAttribute 'rel'
|
||||||
for el in $$ 'img[src]', root2
|
for el in $$ 'img[src]', root2
|
||||||
el.src = el.src.replace /^(\w+:\/\/)[0-2](\.t\.4cdn\.org\/)/, '$10$2'
|
el.src = el.src.replace /^(\w+:\/\/)[0-2](\.t\.4cdn\.org\/)/, '$10$2'
|
||||||
|
textNodes = $.X './/text()', root2
|
||||||
|
i = 0
|
||||||
|
while node = textNodes.snapshotItem i++
|
||||||
|
node.data = node.data.replace /\s+/g, ' '
|
||||||
@normalizedOriginal = root2
|
@normalizedOriginal = root2
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user