FEATURE: improves select-box to support category selection on new topic

This commit is contained in:
Joffrey JAFFEUX
2017-08-23 15:08:19 +02:00
committed by GitHub
parent 7c15b27a90
commit 7b4e302677
18 changed files with 439 additions and 173 deletions

View File

@ -33,7 +33,7 @@ componentTest('accepts a value by reference', {
andThen(() => {
assert.equal(
this.$(".select-box-row.is-highlighted .text").html().trim(), "robin",
find(".select-box-row.is-highlighted .text").html().trim(), "robin",
"it highlights the row corresponding to the value"
);
});
@ -79,7 +79,7 @@ componentTest('no default icon', {
template: '{{select-box}}',
test(assert) {
assert.equal(this.$(".select-box-header .icon").length, 0, "it doesn’t have an icon if not specified");
assert.equal(find(".select-box-header .icon").length, 0, "it doesn’t have an icon if not specified");
}
});
@ -87,7 +87,7 @@ componentTest('customisable icon', {
template: '{{select-box icon="shower"}}',
test(assert) {
assert.equal(this.$(".select-box-header .icon").html().trim(), "<i class=\"fa fa-shower d-icon d-icon-shower\"></i>", "it has a the correct icon");
assert.equal(find(".select-box-header .icon").html().trim(), "<i class=\"fa fa-shower d-icon d-icon-shower\"></i>", "it has a the correct icon");
}
});
@ -98,7 +98,7 @@ componentTest('default search icon', {
click(".select-box-header");
andThen(() => {
assert.equal(find(".select-box-filter .filter-icon").html().trim(), "<i class=\"fa fa-search d-icon d-icon-search\"></i>", "it has a the correct icon");
assert.equal(find(".select-box-filter .d-icon-search").length, 1, "it has a the correct icon");
});
}
});
@ -122,7 +122,7 @@ componentTest('custom search icon', {
click(".select-box-header");
andThen(() => {
assert.equal(find(".select-box-filter .filter-icon").html().trim(), "<i class=\"fa fa-shower d-icon d-icon-shower\"></i>", "it has a the correct icon");
assert.equal(find(".select-box-filter .d-icon-shower").length, 1, "it has a the correct icon");
});
}
});
@ -145,13 +145,13 @@ componentTest('select-box is expandable', {
click(".select-box-header");
andThen(() => {
assert.equal(this.$(".select-box").hasClass("is-expanded"), true);
assert.equal(find(".select-box").hasClass("is-expanded"), true);
});
click(".select-box-header");
andThen(() => {
assert.equal(this.$(".select-box").hasClass("is-expanded"), false);
assert.equal(find(".select-box").hasClass("is-expanded"), false);
});
}
});
@ -165,10 +165,10 @@ componentTest('accepts custom id/text keys', {
},
test(assert) {
click(this.$(".select-box-header"));
click(".select-box-header");
andThen(() => {
assert.equal(this.$(".select-box-row.is-highlighted .text").html().trim(), "robin");
assert.equal(find(".select-box-row.is-highlighted .text").html().trim(), "robin");
});
}
});
@ -181,12 +181,12 @@ componentTest('doesn’t render collection content before first expand', {
},
test(assert) {
assert.equal(this.$(".select-box-body .collection").length, 0);
assert.equal(find(".select-box-body .collection").length, 0);
click(this.$(".select-box-header"));
click(".select-box-header");
andThen(() => {
assert.equal(this.$(".select-box-body .collection").length, 1);
assert.equal(find(".select-box-body .collection").length, 1);
});
}
});
@ -199,42 +199,76 @@ componentTest('persists filter state when expandind/collapsing', {
},
test(assert) {
click(this.$(".select-box-header"));
click(".select-box-header");
fillIn('.filter-query', 'rob');
triggerEvent('.filter-query', 'keyup');
andThen(() => {
assert.equal(this.$(".select-box-row").length, 1);
assert.equal(find(".select-box-row").length, 1);
});
click(this.$(".select-box-header"));
click(".select-box-header");
andThen(() => {
assert.equal(this.$().hasClass("is-expanded"), false);
assert.equal(find(".select-box").hasClass("is-expanded"), false);
});
click(this.$(".select-box-header"));
click(".select-box-header");
andThen(() => {
assert.equal(this.$(".select-box-row").length, 1);
assert.equal(find(".select-box-row").length, 1);
});
}
});
componentTest('supports options to limit size', {
template: '{{select-box maxWidth=100 maxCollectionHeight=20 content=content}}',
template: '{{select-box width=50 maxCollectionHeight=20 content=content}}',
beforeEach() {
this.set("content", [{ id: 1, text: "robin" }]);
},
test(assert) {
assert.equal(this.$(".select-box-header").outerWidth(), 100, "it limits the width");
click(this.$(".select-box-header"));
click(".select-box-header");
andThen(() => {
assert.equal(this.$(".select-box-body").height(), 20, "it limits the height");
assert.equal(find(".select-box-body").height(), 20, "it limits the height");
assert.equal(find(".select-box").width(), 50, "it limits the width");
});
}
});
componentTest('supports custom row template', {
template: '{{select-box content=content selectBoxRowTemplate=selectBoxRowTemplate}}',
beforeEach() {
this.set("content", [{ id: 1, text: "robin" }]);
this.set("selectBoxRowTemplate", (rowComponent) => {
return `<b>${rowComponent.get("text")}</b>`;
});
},
test(assert) {
click(".select-box-header");
andThen(() => {
assert.equal(find(".select-box-row").html().trim(), "<b>robin</b>");
});
}
});
componentTest('supports converting select value to integer', {
template: '{{select-box value=2 content=content castInteger=true}}',
beforeEach() {
this.set("content", [{ id: "1", text: "robin"}, {id: "2", text: "régis" }]);
},
test(assert) {
click(".select-box-header");
andThen(() => {
assert.equal(find(".select-box-row.is-highlighted .text").text(), "régis");
});
}
});