select-box refactoring

- more flexibility (allows custom title)
- less re-render
- more robustness
This commit is contained in:
Joffrey JAFFEUX
2017-08-29 12:25:54 +02:00
committed by GitHub
parent 3d6c79de6d
commit 861dbe3b51
6 changed files with 116 additions and 119 deletions

View File

@ -239,12 +239,12 @@ componentTest('supports options to limit size', {
});
componentTest('supports custom row template', {
template: '{{select-box content=content selectBoxRowTemplate=selectBoxRowTemplate}}',
template: '{{select-box content=content templateForRow=templateForRow}}',
beforeEach() {
this.set("content", [{ id: 1, text: "robin" }]);
this.set("selectBoxRowTemplate", (rowComponent) => {
return `<b>${rowComponent.get("text")}</b>`;
this.set("templateForRow", (rowComponent) => {
return `<b>${rowComponent.get("content.text")}</b>`;
});
},
@ -258,9 +258,10 @@ componentTest('supports custom row template', {
});
componentTest('supports converting select value to integer', {
template: '{{select-box value=2 content=content castInteger=true}}',
template: '{{select-box value=value content=content castInteger=true}}',
beforeEach() {
this.set("value", 2);
this.set("content", [{ id: "1", text: "robin"}, {id: "2", text: "régis" }]);
},
@ -270,6 +271,15 @@ componentTest('supports converting select value to integer', {
andThen(() => {
assert.equal(find(".select-box-row.is-highlighted .text").text(), "régis");
});
andThen(() => {
this.set("value", 3);
this.set("content", [{ id: "3", text: "jeff" }]);
});
andThen(() => {
assert.equal(find(".select-box-row.is-highlighted .text").text(), "jeff", "it works with dynamic content");
});
}
});
@ -335,3 +345,20 @@ componentTest('clearable selection', {
});
}
});
componentTest('supports custom row title', {
template: '{{select-box content=content titleForRow=titleForRow}}',
beforeEach() {
this.set("content", [{ id: 1, text: "robin" }]);
this.set("titleForRow", () => "sam" );
},
test(assert) {
click(".select-box-header");
andThen(() => {
assert.equal(find(".select-box-row:first").attr("title"), "sam");
});
}
});