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/select-kit/user-chooser-test.js
Bianca Nenciu 8f9933d1dd
DEV: Add default results option to user-chooser (#19521)
defaultSearchResults search option can be used to show a list of results
by default, before any search ran, when the filter is empty.
2022-12-21 14:47:47 +02:00

46 lines
1.4 KiB
JavaScript

import { module, test } from "qunit";
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
import { render } from "@ember/test-helpers";
import { hbs } from "ember-cli-htmlbars";
import selectKit from "discourse/tests/helpers/select-kit-helper";
module("Integration | Component | select-kit/user-chooser", function (hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(function () {
this.set("subject", selectKit());
});
test("displays usernames", async function (assert) {
this.set("value", ["bob", "martin"]);
await render(hbs`<UserChooser @value={{this.value}} />`);
assert.strictEqual(this.subject.header().name(), "bob,martin");
});
test("can remove a username", async function (assert) {
this.set("value", ["bob", "martin"]);
await render(hbs`<UserChooser @value={{this.value}} />`);
await this.subject.expand();
await this.subject.deselectItemByValue("bob");
assert.strictEqual(this.subject.header().name(), "martin");
});
test("can display default search results", async function (assert) {
this.set("options", {
customSearchOptions: {
defaultSearchResults: [{ username: "foo" }, { username: "bar" }],
},
});
await render(hbs`<UserChooser @options={{this.options}} />`);
await this.subject.expand();
assert.strictEqual(this.subject.rowByIndex(0).value(), "foo");
assert.strictEqual(this.subject.rowByIndex(1).value(), "bar");
});
});