Skip to content

Commit

Permalink
Where possible, move test functionality into Test.coffee. #829
Browse files Browse the repository at this point in the history
  • Loading branch information
ccd0 committed Jul 26, 2019
1 parent e58eefc commit 5d0d957
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 44 deletions.
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 := \
Expand Down
50 changes: 41 additions & 9 deletions src/General/Test.coffee
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
<% 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'
$.on a2, 'click', @cb.testAll
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
Expand Down Expand Up @@ -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()
<% } %>
5 changes: 0 additions & 5 deletions src/Miscellaneous/Keybinds.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
21 changes: 0 additions & 21 deletions src/Monitoring/Unread.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/main/Main.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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]
<% } %>
3 changes: 0 additions & 3 deletions src/site/SW.tinyboard.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ SW.tinyboard =
'Banner'
'Flash Features'
'Reply Pruning'
<% if (readJSON('/.tests_enabled')) { %>
'Build Test'
<% } %>
]

detect: ->
Expand Down

0 comments on commit 5d0d957

Please sign in to comment.