hardlounge/test/models/msg.js
Reto 8fcd079204
Properly track user modes for context menu (#4267)
* properly track user modes for context menu

The RPL_ISUPPORT response contains a PREFIX element, which not only tracks the
prefix chars ("@", "+" etc) but also their corresponding mode chars (+O, +v)
This commit changes the context menu to not rely on a hardcoded list but rather
user the one given in the prefix response by the server.

Co-authored-by: Max Leiter <maxwell.leiter@gmail.com>
2021-07-21 00:30:07 -07:00

61 lines
1.4 KiB
JavaScript

"use strict";
const expect = require("chai").expect;
const Msg = require("../../src/models/msg");
const User = require("../../src/models/user");
describe("Msg", function () {
["from", "target"].forEach((prop) => {
it(`should keep a copy of the original user in the \`${prop}\` property`, function () {
const prefixLookup = {modeToSymbol: {a: "&", o: "@"}};
const user = new User(
{
modes: ["o"],
nick: "foo",
},
prefixLookup
);
const msg = new Msg({[prop]: user});
// Mutating the user
user.setModes(["a"], prefixLookup);
user.nick = "bar";
// Message's `.from`/etc. should still refer to the original user
expect(msg[prop]).to.deep.equal({mode: "@", nick: "foo"});
});
});
describe("#findPreview(link)", function () {
const msg = new Msg({
previews: [
{
body: "",
head: "Example Domain",
link: "https://example.org/",
thumb: "",
type: "link",
shown: true,
},
{
body: "",
head: "The Lounge",
link: "https://thelounge.chat/",
thumb: "",
type: "link",
shown: true,
},
],
});
it("should find a preview given an existing link", function () {
expect(msg.findPreview("https://thelounge.chat/").head).to.equal("The Lounge");
});
it("should not find a preview that does not exist", function () {
expect(msg.findPreview("https://github.com/thelounge/thelounge")).to.be.undefined;
});
});
});