Fix client tests

This commit is contained in:
Pavel Djundik 2019-11-21 11:11:06 +02:00
parent 0ac9601a3a
commit 49dc6ffd8f
15 changed files with 42 additions and 32 deletions

View file

@ -15,6 +15,7 @@
import throttle from "lodash/throttle"; import throttle from "lodash/throttle";
import constants from "../js/constants"; import constants from "../js/constants";
import storage from "../js/localStorage"; import storage from "../js/localStorage";
import {generateUserContextMenu} from "../js/helpers/contextMenu";
import Sidebar from "./Sidebar.vue"; import Sidebar from "./Sidebar.vue";
import ImageViewer from "./ImageViewer.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 // TODO: maybe move this method to the store or some other more accessible place
this.$refs.contextMenu.open(event, items); 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);
},
}, },
}; };
</script> </script>

View file

@ -106,7 +106,7 @@ export default {
isAction() { isAction() {
return typeof MessageTypes["message-" + this.message.type] !== "undefined"; return typeof MessageTypes["message-" + this.message.type] !== "undefined";
}, },
openUserContextMenu($event, user) { openUserContextMenu(event, user) {
const items = generateUserContextMenu(this.$root, this.channel, this.network, user); const items = generateUserContextMenu(this.$root, this.channel, this.network, user);
this.$root.$refs.app.openContextMenu(event, items); this.$root.$refs.app.openContextMenu(event, items);
}, },

View file

@ -11,8 +11,6 @@ import emojiMap from "./fullnamemap.json";
import LinkPreviewToggle from "../../components/LinkPreviewToggle.vue"; import LinkPreviewToggle from "../../components/LinkPreviewToggle.vue";
import LinkPreviewFileSize from "../../components/LinkPreviewFileSize.vue"; import LinkPreviewFileSize from "../../components/LinkPreviewFileSize.vue";
import InlineChannel from "../../components/InlineChannel.vue"; import InlineChannel from "../../components/InlineChannel.vue";
import store from "../store";
import {generateUserContextMenu} from "./contextMenu";
const emojiModifiersRegex = /[\u{1f3fb}-\u{1f3ff}]/gu; const emojiModifiersRegex = /[\u{1f3fb}-\u{1f3ff}]/gu;
@ -182,6 +180,11 @@ function parse(createElement, text, message = undefined, network = undefined, $r
fragments fragments
); );
} else if (textPart.nick) { } 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( return createElement(
"span", "span",
{ {
@ -192,21 +195,8 @@ function parse(createElement, text, message = undefined, network = undefined, $r
"data-name": textPart.nick, "data-name": textPart.nick,
}, },
on: { on: {
contextmenu($event) { contextmenu: openContextMenu,
$event.preventDefault(); click: openContextMenu,
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);
},
}, },
}, },
fragments fragments

View file

@ -2,9 +2,9 @@
const expect = require("chai").expect; const expect = require("chai").expect;
const stub = require("sinon").stub; const stub = require("sinon").stub;
const Auth = require("../../../client/js/auth"); const Auth = require("../../../client/js/auth").default;
const localStorage = require("../../../client/js/localStorage"); const localStorage = require("../../../client/js/localStorage").default;
const location = require("../../../client/js/location"); const location = require("../../../client/js/location").default;
describe("Auth", function() { describe("Auth", function() {
describe(".signout", function() { describe(".signout", function() {

View file

@ -1,7 +1,7 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const constants = require("../../../client/js/constants"); const constants = require("../../../client/js/constants").default;
describe("client-side constants", function() { describe("client-side constants", function() {
describe(".colorCodeMap", function() { describe(".colorCodeMap", function() {

View file

@ -1,7 +1,7 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const friendlysize = require("../../../../client/js/helpers/friendlysize"); const friendlysize = require("../../../../client/js/helpers/friendlysize").default;
describe("friendlysize helper", function() { describe("friendlysize helper", function() {
it("should render big values in human-readable version", function() { it("should render big values in human-readable version", function() {

View file

@ -1,7 +1,8 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const anyIntersection = require("../../../../../client/js/helpers/ircmessageparser/anyIntersection"); const anyIntersection = require("../../../../../client/js/helpers/ircmessageparser/anyIntersection")
.default;
describe("anyIntersection", () => { describe("anyIntersection", () => {
it("should not intersect on edges", () => { it("should not intersect on edges", () => {

View file

@ -1,7 +1,7 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const fill = require("../../../../../client/js/helpers/ircmessageparser/fill"); const fill = require("../../../../../client/js/helpers/ircmessageparser/fill").default;
describe("fill", () => { describe("fill", () => {
const text = "01234567890123456789"; const text = "01234567890123456789";

View file

@ -1,7 +1,8 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const findChannels = require("../../../../../client/js/helpers/ircmessageparser/findChannels"); const findChannels = require("../../../../../client/js/helpers/ircmessageparser/findChannels")
.default;
describe("findChannels", () => { describe("findChannels", () => {
it("should find single letter channel", () => { it("should find single letter channel", () => {

View file

@ -1,7 +1,7 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const findEmoji = require("../../../../../client/js/helpers/ircmessageparser/findEmoji"); const findEmoji = require("../../../../../client/js/helpers/ircmessageparser/findEmoji").default;
describe("findEmoji", () => { describe("findEmoji", () => {
it("should find default emoji presentation character", () => { it("should find default emoji presentation character", () => {

View file

@ -1,7 +1,7 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const findNames = require("../../../../../client/js/helpers/ircmessageparser/findNames"); const findNames = require("../../../../../client/js/helpers/ircmessageparser/findNames").default;
describe("findNames", () => { describe("findNames", () => {
it("should find nicks in text", () => { it("should find nicks in text", () => {

View file

@ -1,7 +1,7 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const merge = require("../../../../../client/js/helpers/ircmessageparser/merge"); const merge = require("../../../../../client/js/helpers/ircmessageparser/merge").default;
describe("merge", () => { describe("merge", () => {
it("should split style information", () => { it("should split style information", () => {

View file

@ -1,7 +1,7 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const parseStyle = require("../../../../../client/js/helpers/ircmessageparser/parseStyle"); const parseStyle = require("../../../../../client/js/helpers/ircmessageparser/parseStyle").default;
describe("parseStyle", () => { describe("parseStyle", () => {
it("should skip control codes", () => { it("should skip control codes", () => {

View file

@ -1,7 +1,7 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const localetime = require("../../../../client/js/helpers/localetime"); const localetime = require("../../../../client/js/helpers/localetime").default;
describe("localetime helper", () => { describe("localetime helper", () => {
it("should render a human-readable date", () => { it("should render a human-readable date", () => {

View file

@ -1,7 +1,7 @@
"use strict"; "use strict";
const expect = require("chai").expect; const expect = require("chai").expect;
const roundBadgeNumber = require("../../../../client/js/helpers/roundBadgeNumber"); const roundBadgeNumber = require("../../../../client/js/helpers/roundBadgeNumber").default;
describe("roundBadgeNumber helper", function() { describe("roundBadgeNumber helper", function() {
it("should return any number under 1000 as a string", function() { it("should return any number under 1000 as a string", function() {