From 5d0d957389c14a05eed8fe760ba4d713a8ccb57b Mon Sep 17 00:00:00 2001 From: ccd0 Date: Fri, 26 Jul 2019 15:15:59 -0700 Subject: [PATCH] Where possible, move test functionality into Test.coffee. #829 --- Makefile | 3 -- src/General/Test.coffee | 50 +++++++++++++++++++++++++------ src/Miscellaneous/Keybinds.coffee | 5 ---- src/Monitoring/Unread.coffee | 21 ------------- src/main/Main.coffee | 7 +++-- src/site/SW.tinyboard.coffee | 3 -- 6 files changed, 45 insertions(+), 44 deletions(-) diff --git a/Makefile b/Makefile index a4974e1bde..01f95ce95b 100644 --- a/Makefile +++ b/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 := \ diff --git a/src/General/Test.coffee b/src/General/Test.coffee index acffd01463..135f302db6 100644 --- a/src/General/Test.coffee +++ b/src/General/Test.coffee @@ -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() <% } %> diff --git a/src/Miscellaneous/Keybinds.coffee b/src/Miscellaneous/Keybinds.coffee index f89cc9d945..b51e123043 100644 --- a/src/Miscellaneous/Keybinds.coffee +++ b/src/Miscellaneous/Keybinds.coffee @@ -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() diff --git a/src/Monitoring/Unread.coffee b/src/Monitoring/Unread.coffee index b0f352a1c3..7c6dae86eb 100644 --- a/src/Monitoring/Unread.coffee +++ b/src/Monitoring/Unread.coffee @@ -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 diff --git a/src/main/Main.coffee b/src/main/Main.coffee index d1f0d26828..5759627311 100644 --- a/src/main/Main.coffee +++ b/src/main/Main.coffee @@ -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] +<% } %> diff --git a/src/site/SW.tinyboard.coffee b/src/site/SW.tinyboard.coffee index b30327cc93..7b47634131 100644 --- a/src/site/SW.tinyboard.coffee +++ b/src/site/SW.tinyboard.coffee @@ -25,9 +25,6 @@ SW.tinyboard = 'Banner' 'Flash Features' 'Reply Pruning' - <% if (readJSON('/.tests_enabled')) { %> - 'Build Test' - <% } %> ] detect: ->