From 116a73c8d082ea74f8ba10f30b064f9ff872114d Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Tue, 13 Feb 2018 13:05:33 +0200 Subject: [PATCH] Remove actionTypes and check templates directly --- client/js/constants.js | 21 --------------------- client/js/render.js | 3 +-- test/client/js/constantsTest.js | 18 ++++-------------- 3 files changed, 5 insertions(+), 37 deletions(-) diff --git a/client/js/constants.js b/client/js/constants.js index 754a349b..1ce2f9e5 100644 --- a/client/js/constants.js +++ b/client/js/constants.js @@ -68,26 +68,6 @@ const commands = [ "/whois", ]; -const actionTypes = [ - "away", - "back", - "ban_list", - "invite", - "join", - "mode", - "kick", - "nick", - "part", - "quit", - "topic", - "topic_set_by", - "action", - "whois", - "ctcp", - "chghost", - "channel_list", -]; - const condensedTypes = [ "away", "back", @@ -110,6 +90,5 @@ module.exports = { commands: commands, condensedTypes: condensedTypes, condensedTypesQuery: "." + condensedTypes.join(", ."), - actionTypes: actionTypes, timeFormats: timeFormats, }; diff --git a/client/js/render.js b/client/js/render.js index 1530c52a..bf5d2e36 100644 --- a/client/js/render.js +++ b/client/js/render.js @@ -93,8 +93,7 @@ function buildChatMessage(msg) { msg.highlight = true; } - if (constants.actionTypes.indexOf(type) !== -1) { - msg.template = "actions/" + type; + if (typeof templates.actions[type] !== "undefined") { template = "msg_action"; } else if (type === "unhandled") { template = "msg_unhandled"; diff --git a/test/client/js/constantsTest.js b/test/client/js/constantsTest.js index 5c44253f..f3140a89 100644 --- a/test/client/js/constantsTest.js +++ b/test/client/js/constantsTest.js @@ -30,25 +30,15 @@ describe("client-side constants", function() { }); }); - describe(".actionTypes", function() { - it("should be a non-empty array", function() { - expect(constants.actionTypes).to.be.an("array").that.is.not.empty; - }); - - it("should only contain strings with no whitespaces", function() { - constants.actionTypes.forEach((type) => { - expect(type).to.be.a("string").that.does.not.match(/\s/); - }); - }); - }); - describe(".condensedTypes", function() { it("should be a non-empty array", function() { expect(constants.condensedTypes).to.be.an("array").that.is.not.empty; }); - it("should be a subset of `actionTypes`", function() { - expect(constants.actionTypes).to.include.members(constants.condensedTypes); + it("should only contain ASCII strings", function() { + constants.condensedTypes.forEach((type) => { + expect(type).to.be.a("string").that.does.match(/^\w+$/); + }); }); });