From 09edde8ef70ca65be8dfa9c8cd99031d43eff925 Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Fri, 14 Feb 2020 10:19:58 +0200 Subject: [PATCH] DEV: Add test (#8961) Follow-up to 67c9940d72faafa2fec7e327018249ef5a005f15. --- .../javascripts/lib/link-mentions-test.js.es6 | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 test/javascripts/lib/link-mentions-test.js.es6 diff --git a/test/javascripts/lib/link-mentions-test.js.es6 b/test/javascripts/lib/link-mentions-test.js.es6 new file mode 100644 index 0000000000..ae5a83c5cf --- /dev/null +++ b/test/javascripts/lib/link-mentions-test.js.es6 @@ -0,0 +1,61 @@ +import { + fetchUnseenMentions, + linkSeenMentions +} from "discourse/lib/link-mentions"; +import { Promise } from "rsvp"; + +QUnit.module("lib:link-mentions"); + +QUnit.test("linkSeenMentions replaces users and groups", async assert => { + /* global server */ + server.get("/u/is_local_username", () => [ + 200, + { "Content-Type": "application/json" }, + { + valid: ["valid_user"], + valid_groups: ["valid_group"], + mentionable_groups: [ + { + name: "mentionable_group", + user_count: 1 + } + ], + cannot_see: [], + max_users_notified_per_group_mention: 100 + } + ]); + + await fetchUnseenMentions([ + "valid_user", + "mentionable_group", + "valid_group", + "invalid" + ]); + + let $root = $(` +
+ @invalid + @valid_user + @valid_group + @mentionable_group +
+ `); + + await linkSeenMentions($root); + + // Ember.Test.registerWaiter is not available here, so we are implementing + // our own + await new Promise(resolve => { + const interval = setInterval(() => { + if ($("a", $root).length > 0) { + clearInterval(interval); + resolve(); + } + }, 500); + }); + + assert.equal($("a", $root)[0].text, "@valid_user"); + assert.equal($("a", $root)[1].text, "@mentionable_group"); + assert.equal($("span.mention", $root)[0].innerHTML, "@invalid"); + assert.equal($("span.mention", $root)[1].innerHTML, "@valid_group"); +});