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/multi-select-test.js
Joffrey JAFFEUX a939609d32
FIX: fixes few regressions in select-kit (#17453)
- following c3fd91670e `paste` has been typoed into `pase`
- adds two tests for pasting in `multi-select` and `email-group-user-chooser`
- selectKitOptions would not be following the right overriding order
- `category-selector` was using `selectKitOptions` directly which shouldn't be the case as it's not using computed values
- apparently since a recent ember upgrade, paste event is not providing `originalEvent` anymore and `clipboardData` should be retrieved directly on the event
2022-07-12 21:38:17 +02:00

122 lines
2.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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";
import { paste, query } from "discourse/tests/helpers/qunit-helpers";
const DEFAULT_CONTENT = [
{ id: 1, name: "foo" },
{ id: 2, name: "bar" },
{ id: 3, name: "baz" },
];
const setDefaultState = (ctx, options) => {
const properties = Object.assign(
{
content: DEFAULT_CONTENT,
value: null,
},
options || {}
);
ctx.setProperties(properties);
};
module("Integration | Component | select-kit/multi-select", function (hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(function () {
this.set("subject", selectKit());
});
test("content", async function (assert) {
setDefaultState(this);
await render(hbs`
<MultiSelect
@value={{this.value}}
@content={{this.content}}
/>
`);
await this.subject.expand();
const content = this.subject.displayedContent();
assert.strictEqual(content.length, 3, "it shows rows");
assert.strictEqual(
content[0].name,
this.content.firstObject.name,
"it has the correct name"
);
assert.strictEqual(
content[0].id,
this.content.firstObject.id.toString(),
"it has the correct value"
);
assert.strictEqual(
this.subject.header().value(),
null,
"it doesn't set a value from the content"
);
});
test("maximum=1", async function (assert) {
setDefaultState(this);
await render(hbs`
<MultiSelect
@value={{this.value}}
@content={{this.content}}
@options={{hash maximum=1}}
/>
`);
await this.subject.expand();
await this.subject.selectRowByValue(1);
assert.notOk(this.subject.isExpanded(), "it closes the dropdown");
await this.subject.expand();
await this.subject.deselectItemByValue(1);
assert.ok(
this.subject.isExpanded(),
"it doesnt close the dropdown when no selection has been made"
);
});
test("maximum=2", async function (assert) {
setDefaultState(this);
await render(hbs`
<MultiSelect
@value={{this.value}}
@content={{this.content}}
@options={{hash maximum=2}}
/>
`);
await this.subject.expand();
await this.subject.selectRowByValue(1);
assert.ok(this.subject.isExpanded(), "it doesnt close the dropdown");
});
test("pasting", async function (assert) {
setDefaultState(this);
await render(hbs`
<MultiSelect
@value={{this.value}}
@content={{this.content}}
@options={{hash maximum=2}}
/>
`);
await this.subject.expand();
await paste(query(".filter-input"), "foo|bar");
assert.equal(this.subject.header().value(), "1,2");
});
});