Where possible, move test functionality into Test.coffee. #829

This commit is contained in:
ccd0 2019-07-26 15:15:59 -07:00
parent e58eefc5e6
commit 5d0d957389
6 changed files with 45 additions and 44 deletions

View File

@ -45,11 +45,8 @@ sources := $(foreach d,$(source_directories),$(call sort_directory,$(d)))
uses_tests_enabled := \
src/classes/Post.coffee \
src/site/SW.tinyboard.coffee \
src/General/Test.coffee \
src/Linkification/Linkify.coffee \
src/Miscellaneous/Keybinds.coffee \
src/Monitoring/Unread.coffee \
src/main/Main.coffee
imports_src/globals/globals.js := \

View File

@ -1,8 +1,9 @@
<% if (readJSON('/.tests_enabled')) { %>
Test =
init: ->
return if !Conf['Menu'] or g.VIEW not in ['index', 'thread']
return unless g.SITE.software is 'yotsuba' and g.VIEW in ['index', 'thread']
if Conf['Menu']
a = $.el 'a',
textContent: 'Test HTML building'
$.on a, 'click', @cb.testOne
@ -18,6 +19,15 @@ Test =
Header.menu.addEntry
el: a2
if Unread.posts
testOrderLink = $.el 'a',
textContent: 'Test Post Order'
$.on testOrderLink, 'click', @cb.testOrder
Header.menu.addEntry
el: testOrderLink
$.on d, 'keydown', @cb.keydown
assert: (condition) ->
unless condition()
new Notice 'warning', "Assertion failed: #{condition}", 30
@ -137,4 +147,26 @@ Test =
testAll: ->
Test.testAll()
Header.menu.close()
testOrder: ->
list1 = (x.ID for x in Unread.order.order())
list2 = (+x.id.match(/\d*$/)[0] for x in $$ (if g.SITE.isOPContainerThread then "#{g.SITE.selectors.thread}, " else '') + g.SITE.selectors.postContainer)
pass = do ->
return false unless list1.length is list2.length
for i in [0...list1.length] by 1
return false if list1[i] isnt list2[i]
true
if pass
new Notice 'success', "Orders same (#{list1.length} posts)", 5
else
new Notice 'warning', 'Orders differ.', 30
c.log list1
c.log list2
keydown: (e) ->
return unless Keybinds.keyCode(e) is 'v'
return if e.target.nodeName in ['INPUT', 'TEXTAREA']
Test.testAll()
e.preventDefault()
e.stopPropagation()
<% } %>

View File

@ -218,11 +218,6 @@ Keybinds =
when Conf['Next Post Quoting You']
return unless threadRoot and QuoteYou.db
QuoteYou.cb.seek 'following'
<% if (readJSON('/.tests_enabled')) { %>
when 'v'
return unless threadRoot
Test.testAll()
<% } %>
else
return
e.preventDefault()

View File

@ -29,27 +29,6 @@ Unread =
name: 'Unread'
cb: @addPost
<% if (readJSON('/.tests_enabled')) { %>
testLink = $.el 'a',
textContent: 'Test Post Order'
$.on testLink, 'click', ->
list1 = (x.ID for x in Unread.order.order())
list2 = (+x.id.match(/\d*$/)[0] for x in $$ (if g.SITE.isOPContainerThread then "#{g.SITE.selectors.thread}, " else '') + g.SITE.selectors.postContainer)
pass = do ->
return false unless list1.length is list2.length
for i in [0...list1.length] by 1
return false if list1[i] isnt list2[i]
true
if pass
new Notice 'success', "Orders same (#{list1.length} posts)", 5
else
new Notice 'warning', 'Orders differ.', 30
c.log list1
c.log list2
Header.menu.addEntry
el: testLink
<% } %>
node: ->
Unread.thread = @
Unread.title = d.title

View File

@ -671,7 +671,8 @@ Main =
['Flash Features', Flash]
['Reply Pruning', ReplyPruning]
['Mod Contact Links', ModContact]
<% if (readJSON('/.tests_enabled')) { %>
['Build Test', Test]
<% } %>
]
<% if (readJSON('/.tests_enabled')) { %>
Main.features.push ['Build Test', Test]
<% } %>

View File

@ -25,9 +25,6 @@ SW.tinyboard =
'Banner'
'Flash Features'
'Reply Pruning'
<% if (readJSON('/.tests_enabled')) { %>
'Build Test'
<% } %>
]
detect: ->