Where possible, move test functionality into Test.coffee. #829
This commit is contained in:
parent
e58eefc5e6
commit
5d0d957389
3
Makefile
3
Makefile
@ -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 := \
|
||||
|
||||
@ -1,16 +1,17 @@
|
||||
<% 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']
|
||||
|
||||
a = $.el 'a',
|
||||
textContent: 'Test HTML building'
|
||||
$.on a, 'click', @cb.testOne
|
||||
Menu.menu.addEntry
|
||||
el: a
|
||||
open: (post) ->
|
||||
a.dataset.fullID = post.fullID
|
||||
true
|
||||
if Conf['Menu']
|
||||
a = $.el 'a',
|
||||
textContent: 'Test HTML building'
|
||||
$.on a, 'click', @cb.testOne
|
||||
Menu.menu.addEntry
|
||||
el: a
|
||||
open: (post) ->
|
||||
a.dataset.fullID = post.fullID
|
||||
true
|
||||
|
||||
a2 = $.el 'a',
|
||||
textContent: 'Test HTML building'
|
||||
@ -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()
|
||||
<% } %>
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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]
|
||||
<% } %>
|
||||
|
||||
@ -25,9 +25,6 @@ SW.tinyboard =
|
||||
'Banner'
|
||||
'Flash Features'
|
||||
'Reply Pruning'
|
||||
<% if (readJSON('/.tests_enabled')) { %>
|
||||
'Build Test'
|
||||
<% } %>
|
||||
]
|
||||
|
||||
detect: ->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user