This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/tests/integration/components/user-selector-test.js
David Taylor 6d6d5a200f
DEV: Add withSilencedDeprecationsAsync for async functions (#19057)
Previously we were trying to handle both async and sync use cases in a single function, but it was confusing to read and led to subtle race conditions. This commit separates the async version into a separate function.
2022-11-16 17:55:20 +00:00

68 lines
2.3 KiB
JavaScript

import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { render } from "@ember/test-helpers";
import { query } from "discourse/tests/helpers/qunit-helpers";
import { hbs } from "ember-cli-htmlbars";
import { withSilencedDeprecationsAsync } from "discourse-common/lib/deprecated";
function paste(element, text) {
let e = new Event("paste");
e.clipboardData = { getData: () => text };
element.dispatchEvent(e);
}
module("Integration | Component | user-selector", function (hooks) {
setupRenderingTest(hooks);
test("pasting a list of usernames", async function (assert) {
this.set("usernames", "evil,trout");
await withSilencedDeprecationsAsync(
"discourse.user-selector-component",
async () => {
await render(
hbs`<UserSelector @usernames={{this.usernames}} class="test-selector" />`
);
}
);
let element = query(".test-selector");
assert.strictEqual(this.get("usernames"), "evil,trout");
paste(element, "zip,zap,zoom");
assert.strictEqual(this.get("usernames"), "evil,trout,zip,zap,zoom");
paste(element, "evil,abc,abc,abc");
assert.strictEqual(this.get("usernames"), "evil,trout,zip,zap,zoom,abc");
this.set("usernames", "");
paste(element, "names with spaces");
assert.strictEqual(this.get("usernames"), "names,with,spaces");
this.set("usernames", null);
paste(element, "@eviltrout,@codinghorror sam");
assert.strictEqual(this.get("usernames"), "eviltrout,codinghorror,sam");
this.set("usernames", null);
paste(element, "eviltrout\nsam\ncodinghorror");
assert.strictEqual(this.get("usernames"), "eviltrout,sam,codinghorror");
});
test("excluding usernames", async function (assert) {
this.set("usernames", "mark");
this.set("excludedUsernames", ["jeff", "sam", "robin"]);
await withSilencedDeprecationsAsync(
"discourse.user-selector-component",
async () => {
await render(
hbs`<UserSelector @usernames={{this.usernames}} @excludedUsernames={{this.excludedUsernames}} class="test-selector" />`
);
}
);
let element = query(".test-selector");
paste(element, "roman,penar,jeff,robin");
assert.strictEqual(this.get("usernames"), "mark,roman,penar");
});
});