From 49dc6ffd8f042f117a72bf290a054258c4a60c85 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Thu, 21 Nov 2019 11:11:06 +0200 Subject: [PATCH] Fix client tests --- client/components/App.vue | 18 ++++++++++++++ client/components/Message.vue | 2 +- client/js/helpers/parse.js | 24 ++++++------------- test/client/js/authTest.js | 6 ++--- test/client/js/constantsTest.js | 2 +- test/client/js/helpers/friendlysizeTest.js | 2 +- .../ircmessageparser/anyIntersection.js | 3 ++- .../js/helpers/ircmessageparser/fill.js | 2 +- .../helpers/ircmessageparser/findChannels.js | 3 ++- .../js/helpers/ircmessageparser/findEmoji.js | 2 +- .../js/helpers/ircmessageparser/findNames.js | 2 +- .../js/helpers/ircmessageparser/merge.js | 2 +- .../js/helpers/ircmessageparser/parseStyle.js | 2 +- test/client/js/helpers/localetimeTest.js | 2 +- .../client/js/helpers/roundBadgeNumberTest.js | 2 +- 15 files changed, 42 insertions(+), 32 deletions(-) diff --git a/client/components/App.vue b/client/components/App.vue index 9c62fdf6..b788a86e 100644 --- a/client/components/App.vue +++ b/client/components/App.vue @@ -15,6 +15,7 @@ import throttle from "lodash/throttle"; import constants from "../js/constants"; import storage from "../js/localStorage"; +import {generateUserContextMenu} from "../js/helpers/contextMenu"; import Sidebar from "./Sidebar.vue"; import ImageViewer from "./ImageViewer.vue"; @@ -92,6 +93,23 @@ export default { // TODO: maybe move this method to the store or some other more accessible place this.$refs.contextMenu.open(event, items); }, + openContextMenuForMentionedNick(event, network, nick) { + // TODO: Find a better way to do this + + const channel = this.$store.state.activeChannel.channel; + let user = channel.users.find((u) => u.nick === nick); + + if (!user) { + user = { + nick: nick, + mode: "", + }; + } + + const items = generateUserContextMenu(this.$root, channel, network, user); + + this.openContextMenu(event, items); + }, }, }; diff --git a/client/components/Message.vue b/client/components/Message.vue index 3afefaa3..28bfedda 100644 --- a/client/components/Message.vue +++ b/client/components/Message.vue @@ -106,7 +106,7 @@ export default { isAction() { return typeof MessageTypes["message-" + this.message.type] !== "undefined"; }, - openUserContextMenu($event, user) { + openUserContextMenu(event, user) { const items = generateUserContextMenu(this.$root, this.channel, this.network, user); this.$root.$refs.app.openContextMenu(event, items); }, diff --git a/client/js/helpers/parse.js b/client/js/helpers/parse.js index a61897f1..f50f0181 100644 --- a/client/js/helpers/parse.js +++ b/client/js/helpers/parse.js @@ -11,8 +11,6 @@ import emojiMap from "./fullnamemap.json"; import LinkPreviewToggle from "../../components/LinkPreviewToggle.vue"; import LinkPreviewFileSize from "../../components/LinkPreviewFileSize.vue"; import InlineChannel from "../../components/InlineChannel.vue"; -import store from "../store"; -import {generateUserContextMenu} from "./contextMenu"; const emojiModifiersRegex = /[\u{1f3fb}-\u{1f3ff}]/gu; @@ -182,6 +180,11 @@ function parse(createElement, text, message = undefined, network = undefined, $r fragments ); } else if (textPart.nick) { + // TODO: This really does not belong here, find a better way + const openContextMenu = (event) => { + $root.$refs.app.openContextMenuForMentionedNick(event, network, textPart.nick); + }; + return createElement( "span", { @@ -192,21 +195,8 @@ function parse(createElement, text, message = undefined, network = undefined, $r "data-name": textPart.nick, }, on: { - contextmenu($event) { - $event.preventDefault(); - const channel = store.state.activeChannel.channel; - let user = channel.users.find((u) => u.nick === textPart.nick); - - if (!user) { - user = { - nick: textPart.nick, - mode: "", - }; - } - - const items = generateUserContextMenu($root, channel, network, user); - $root.$refs.app.openContextMenu($event, items); - }, + contextmenu: openContextMenu, + click: openContextMenu, }, }, fragments diff --git a/test/client/js/authTest.js b/test/client/js/authTest.js index b551d954..b4fa4fc2 100644 --- a/test/client/js/authTest.js +++ b/test/client/js/authTest.js @@ -2,9 +2,9 @@ const expect = require("chai").expect; const stub = require("sinon").stub; -const Auth = require("../../../client/js/auth"); -const localStorage = require("../../../client/js/localStorage"); -const location = require("../../../client/js/location"); +const Auth = require("../../../client/js/auth").default; +const localStorage = require("../../../client/js/localStorage").default; +const location = require("../../../client/js/location").default; describe("Auth", function() { describe(".signout", function() { diff --git a/test/client/js/constantsTest.js b/test/client/js/constantsTest.js index e9035f00..166a42f0 100644 --- a/test/client/js/constantsTest.js +++ b/test/client/js/constantsTest.js @@ -1,7 +1,7 @@ "use strict"; const expect = require("chai").expect; -const constants = require("../../../client/js/constants"); +const constants = require("../../../client/js/constants").default; describe("client-side constants", function() { describe(".colorCodeMap", function() { diff --git a/test/client/js/helpers/friendlysizeTest.js b/test/client/js/helpers/friendlysizeTest.js index 5678e192..709299a5 100644 --- a/test/client/js/helpers/friendlysizeTest.js +++ b/test/client/js/helpers/friendlysizeTest.js @@ -1,7 +1,7 @@ "use strict"; const expect = require("chai").expect; -const friendlysize = require("../../../../client/js/helpers/friendlysize"); +const friendlysize = require("../../../../client/js/helpers/friendlysize").default; describe("friendlysize helper", function() { it("should render big values in human-readable version", function() { diff --git a/test/client/js/helpers/ircmessageparser/anyIntersection.js b/test/client/js/helpers/ircmessageparser/anyIntersection.js index 2b44843d..84ae6b62 100644 --- a/test/client/js/helpers/ircmessageparser/anyIntersection.js +++ b/test/client/js/helpers/ircmessageparser/anyIntersection.js @@ -1,7 +1,8 @@ "use strict"; const expect = require("chai").expect; -const anyIntersection = require("../../../../../client/js/helpers/ircmessageparser/anyIntersection"); +const anyIntersection = require("../../../../../client/js/helpers/ircmessageparser/anyIntersection") + .default; describe("anyIntersection", () => { it("should not intersect on edges", () => { diff --git a/test/client/js/helpers/ircmessageparser/fill.js b/test/client/js/helpers/ircmessageparser/fill.js index b2fc69ab..82ffcf4a 100644 --- a/test/client/js/helpers/ircmessageparser/fill.js +++ b/test/client/js/helpers/ircmessageparser/fill.js @@ -1,7 +1,7 @@ "use strict"; const expect = require("chai").expect; -const fill = require("../../../../../client/js/helpers/ircmessageparser/fill"); +const fill = require("../../../../../client/js/helpers/ircmessageparser/fill").default; describe("fill", () => { const text = "01234567890123456789"; diff --git a/test/client/js/helpers/ircmessageparser/findChannels.js b/test/client/js/helpers/ircmessageparser/findChannels.js index 284db5dd..7e653fd6 100644 --- a/test/client/js/helpers/ircmessageparser/findChannels.js +++ b/test/client/js/helpers/ircmessageparser/findChannels.js @@ -1,7 +1,8 @@ "use strict"; const expect = require("chai").expect; -const findChannels = require("../../../../../client/js/helpers/ircmessageparser/findChannels"); +const findChannels = require("../../../../../client/js/helpers/ircmessageparser/findChannels") + .default; describe("findChannels", () => { it("should find single letter channel", () => { diff --git a/test/client/js/helpers/ircmessageparser/findEmoji.js b/test/client/js/helpers/ircmessageparser/findEmoji.js index d2d5665e..95d5370f 100644 --- a/test/client/js/helpers/ircmessageparser/findEmoji.js +++ b/test/client/js/helpers/ircmessageparser/findEmoji.js @@ -1,7 +1,7 @@ "use strict"; const expect = require("chai").expect; -const findEmoji = require("../../../../../client/js/helpers/ircmessageparser/findEmoji"); +const findEmoji = require("../../../../../client/js/helpers/ircmessageparser/findEmoji").default; describe("findEmoji", () => { it("should find default emoji presentation character", () => { diff --git a/test/client/js/helpers/ircmessageparser/findNames.js b/test/client/js/helpers/ircmessageparser/findNames.js index b826ed32..7ce52655 100644 --- a/test/client/js/helpers/ircmessageparser/findNames.js +++ b/test/client/js/helpers/ircmessageparser/findNames.js @@ -1,7 +1,7 @@ "use strict"; const expect = require("chai").expect; -const findNames = require("../../../../../client/js/helpers/ircmessageparser/findNames"); +const findNames = require("../../../../../client/js/helpers/ircmessageparser/findNames").default; describe("findNames", () => { it("should find nicks in text", () => { diff --git a/test/client/js/helpers/ircmessageparser/merge.js b/test/client/js/helpers/ircmessageparser/merge.js index c7d635c7..18ac32bc 100644 --- a/test/client/js/helpers/ircmessageparser/merge.js +++ b/test/client/js/helpers/ircmessageparser/merge.js @@ -1,7 +1,7 @@ "use strict"; const expect = require("chai").expect; -const merge = require("../../../../../client/js/helpers/ircmessageparser/merge"); +const merge = require("../../../../../client/js/helpers/ircmessageparser/merge").default; describe("merge", () => { it("should split style information", () => { diff --git a/test/client/js/helpers/ircmessageparser/parseStyle.js b/test/client/js/helpers/ircmessageparser/parseStyle.js index 5607b4c1..fed71455 100644 --- a/test/client/js/helpers/ircmessageparser/parseStyle.js +++ b/test/client/js/helpers/ircmessageparser/parseStyle.js @@ -1,7 +1,7 @@ "use strict"; const expect = require("chai").expect; -const parseStyle = require("../../../../../client/js/helpers/ircmessageparser/parseStyle"); +const parseStyle = require("../../../../../client/js/helpers/ircmessageparser/parseStyle").default; describe("parseStyle", () => { it("should skip control codes", () => { diff --git a/test/client/js/helpers/localetimeTest.js b/test/client/js/helpers/localetimeTest.js index 8c9ea0d0..589da875 100644 --- a/test/client/js/helpers/localetimeTest.js +++ b/test/client/js/helpers/localetimeTest.js @@ -1,7 +1,7 @@ "use strict"; const expect = require("chai").expect; -const localetime = require("../../../../client/js/helpers/localetime"); +const localetime = require("../../../../client/js/helpers/localetime").default; describe("localetime helper", () => { it("should render a human-readable date", () => { diff --git a/test/client/js/helpers/roundBadgeNumberTest.js b/test/client/js/helpers/roundBadgeNumberTest.js index 7579e856..282e05de 100644 --- a/test/client/js/helpers/roundBadgeNumberTest.js +++ b/test/client/js/helpers/roundBadgeNumberTest.js @@ -1,7 +1,7 @@ "use strict"; const expect = require("chai").expect; -const roundBadgeNumber = require("../../../../client/js/helpers/roundBadgeNumber"); +const roundBadgeNumber = require("../../../../client/js/helpers/roundBadgeNumber").default; describe("roundBadgeNumber helper", function() { it("should return any number under 1000 as a string", function() {