discourse/test/javascripts/lib/link-mentions-test.js.es6
Mark VanLandingham 176aa0ac7d
DEV: Import pretender instead of global server var (#8996)
* DEV: Remove server global test variable

* Delete yarn-error.log

* prettier and some eslint fixes

* add global server variable back for plugins

* rename imported server to pretender

* prettier

* support plugin server. usage

* Export pretender as named

* Prettier

* change default pretender export

* fix bad import

* Use pretender() and original default export

* export new Pretender as default

* fix accidental change

* WIP testing

* add pretend handlers in correct location

* move more stuff into the correct pretender

* Consolidated more pretenders

* comment out another bad test

* fix user acceptance tests

* commented out bad test

* fixed another composer server stub

* fix more tests

* fixed tag test pretender

* Fix admin email test

* removed another draft handler

* add back test

* fix and uncomment another test

* remove test that is not useful

* remove commented out lines

* reapply handlers between every test

* no need to re-stub requests now :)

* cleanup from review

* more cleanup
2020-03-02 14:24:31 -05:00

62 lines
1.5 KiB
JavaScript

import {
fetchUnseenMentions,
linkSeenMentions
} from "discourse/lib/link-mentions";
import { Promise } from "rsvp";
import pretender from "helpers/create-pretender";
QUnit.module("lib:link-mentions");
QUnit.test("linkSeenMentions replaces users and groups", async assert => {
pretender.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 = $(`
<div>
<span class="mention">@invalid</span>
<span class="mention">@valid_user</span>
<span class="mention">@valid_group</span>
<span class="mention">@mentionable_group</span>
</div>
`);
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, "@valid_group");
assert.equal($("a.notify", $root).text(), "@mentionable_group");
assert.equal($("span.mention", $root)[0].innerHTML, "@invalid");
});