FIX: ensures onSelect/onDeselect are called

This commit is contained in:
Joffrey JAFFEUX 2018-09-17 10:36:14 +02:00 committed by GitHub
parent 7a0232249a
commit 52eed73294
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 0 deletions

View File

@ -210,6 +210,10 @@ export default SelectKitComponent.extend({
}, },
select(computedContentItem) { select(computedContentItem) {
if (this.get("hasSelection")) {
this.deselect(this.get("selection.value"));
}
if ( if (
!computedContentItem || !computedContentItem ||
computedContentItem.__sk_row_type === "noneRow" computedContentItem.__sk_row_type === "noneRow"

View File

@ -835,3 +835,55 @@ componentTest("without forceEscape", {
); );
} }
}); });
componentTest("onSelect", {
template:
"<div class='test-external-action'></div>{{single-select content=content onSelect=(action externalAction)}}",
beforeEach() {
this.set("externalAction", actual => {
find(".test-external-action").text(actual);
});
this.set("content", ["red", "blue"]);
},
async test(assert) {
await this.get("subject").expand();
await this.get("subject").selectRowByValue("red");
assert.equal(
find(".test-external-action")
.text()
.trim(),
"red"
);
}
});
componentTest("onDeselect", {
template:
"<div class='test-external-action'></div>{{single-select content=content onDeselect=(action externalAction)}}",
beforeEach() {
this.set("externalAction", actual => {
find(".test-external-action").text(actual);
});
this.set("content", ["red", "blue"]);
},
async test(assert) {
await this.get("subject").expand();
await this.get("subject").selectRowByValue("red");
await this.get("subject").expand();
await this.get("subject").selectRowByValue("blue");
assert.equal(
find(".test-external-action")
.text()
.trim(),
"red"
);
}
});