2017-08-13 08:34:50 -04:00
|
|
|
|
import componentTest from 'helpers/component-test';
|
|
|
|
|
|
2017-10-19 15:51:08 -04:00
|
|
|
|
moduleForComponent('select-box-kit', { integration: true });
|
2017-08-13 08:34:50 -04:00
|
|
|
|
|
2017-08-15 18:41:56 -04:00
|
|
|
|
componentTest('updating the content refreshes the list', {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
template: '{{select-box-kit value=1 content=content}}',
|
2017-08-13 08:34:50 -04:00
|
|
|
|
|
|
|
|
|
beforeEach() {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
this.set("content", [{ id: 1, name: "robin" }]);
|
2017-08-13 08:34:50 -04:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
test(assert) {
|
2017-11-09 13:57:53 -05:00
|
|
|
|
expandSelectBoxKit();
|
2017-08-15 20:34:43 -04:00
|
|
|
|
|
2017-08-13 08:34:50 -04:00
|
|
|
|
andThen(() => {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
assert.equal(selectBox().rowByValue(1).name(), "robin");
|
|
|
|
|
this.set("content", [{ id: 1, name: "regis" }]);
|
|
|
|
|
assert.equal(selectBox().rowByValue(1).name(), "regis");
|
2017-08-13 08:34:50 -04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
componentTest('accepts a value by reference', {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
template: '{{select-box-kit value=value content=content}}',
|
2017-08-13 08:34:50 -04:00
|
|
|
|
|
|
|
|
|
beforeEach() {
|
|
|
|
|
this.set("value", 1);
|
2017-10-19 15:51:08 -04:00
|
|
|
|
this.set("content", [{ id: 1, name: "robin" }, { id: 2, name: "regis" }]);
|
2017-08-13 08:34:50 -04:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
test(assert) {
|
2017-11-09 13:57:53 -05:00
|
|
|
|
expandSelectBoxKit();
|
2017-08-15 20:34:43 -04:00
|
|
|
|
|
2017-08-13 08:34:50 -04:00
|
|
|
|
andThen(() => {
|
2017-08-15 20:34:43 -04:00
|
|
|
|
assert.equal(
|
2017-10-19 15:51:08 -04:00
|
|
|
|
selectBox().selectedRow.name(), "robin",
|
2017-08-15 20:34:43 -04:00
|
|
|
|
"it highlights the row corresponding to the value"
|
|
|
|
|
);
|
2017-08-15 18:41:56 -04:00
|
|
|
|
});
|
2017-08-13 08:34:50 -04:00
|
|
|
|
|
2017-11-09 13:57:53 -05:00
|
|
|
|
selectBoxKitSelectRow(1);
|
2017-08-15 20:34:43 -04:00
|
|
|
|
|
2017-08-15 18:41:56 -04:00
|
|
|
|
andThen(() => {
|
2017-08-15 20:34:43 -04:00
|
|
|
|
assert.equal(this.get("value"), 1, "it mutates the value");
|
2017-08-13 08:34:50 -04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
componentTest('no default icon', {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
template: '{{select-box-kit}}',
|
2017-08-13 08:34:50 -04:00
|
|
|
|
|
|
|
|
|
test(assert) {
|
2017-09-14 13:50:32 -04:00
|
|
|
|
assert.equal(selectBox().header.icon().length, 0, "it doesn’t have an icon if not specified");
|
2017-08-13 08:34:50 -04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
componentTest('default search icon', {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
template: '{{select-box-kit filterable=true}}',
|
2017-08-13 08:34:50 -04:00
|
|
|
|
|
|
|
|
|
test(assert) {
|
2017-11-09 13:57:53 -05:00
|
|
|
|
expandSelectBoxKit();
|
2017-08-15 20:34:43 -04:00
|
|
|
|
|
2017-08-13 08:34:50 -04:00
|
|
|
|
andThen(() => {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
assert.ok(exists(selectBox().filter.icon), "it has a the correct icon");
|
2017-08-13 08:34:50 -04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
componentTest('with no search icon', {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
template: '{{select-box-kit filterable=true filterIcon=null}}',
|
2017-08-13 08:34:50 -04:00
|
|
|
|
|
|
|
|
|
test(assert) {
|
2017-11-09 13:57:53 -05:00
|
|
|
|
expandSelectBoxKit();
|
2017-08-15 20:34:43 -04:00
|
|
|
|
|
2017-08-13 08:34:50 -04:00
|
|
|
|
andThen(() => {
|
2017-09-14 13:50:32 -04:00
|
|
|
|
assert.equal(selectBox().filter.icon().length, 0, "it has no icon");
|
2017-08-13 08:34:50 -04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
componentTest('custom search icon', {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
template: '{{select-box-kit filterable=true filterIcon="shower"}}',
|
2017-08-13 08:34:50 -04:00
|
|
|
|
|
|
|
|
|
test(assert) {
|
2017-11-09 13:57:53 -05:00
|
|
|
|
expandSelectBoxKit();
|
2017-08-15 20:34:43 -04:00
|
|
|
|
|
2017-08-13 08:34:50 -04:00
|
|
|
|
andThen(() => {
|
2017-09-14 13:50:32 -04:00
|
|
|
|
assert.ok(selectBox().filter.icon().hasClass("d-icon-shower"), "it has a the correct icon");
|
2017-08-13 08:34:50 -04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
componentTest('select-box is expandable', {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
template: '{{select-box-kit}}',
|
2017-08-13 08:34:50 -04:00
|
|
|
|
test(assert) {
|
2017-11-09 13:57:53 -05:00
|
|
|
|
expandSelectBoxKit();
|
2017-08-15 20:34:43 -04:00
|
|
|
|
|
2017-09-14 13:50:32 -04:00
|
|
|
|
andThen(() => assert.ok(selectBox().isExpanded) );
|
2017-08-13 08:34:50 -04:00
|
|
|
|
|
2017-11-09 13:57:53 -05:00
|
|
|
|
collapseSelectBoxKit();
|
2017-08-15 20:34:43 -04:00
|
|
|
|
|
2017-09-14 13:50:32 -04:00
|
|
|
|
andThen(() => assert.notOk(selectBox().isExpanded) );
|
2017-08-13 08:34:50 -04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2017-10-19 15:51:08 -04:00
|
|
|
|
componentTest('accepts custom value/name keys', {
|
|
|
|
|
template: '{{select-box-kit value=value nameProperty="item" content=content valueAttribute="identifier"}}',
|
2017-08-13 08:34:50 -04:00
|
|
|
|
|
|
|
|
|
beforeEach() {
|
|
|
|
|
this.set("value", 1);
|
2017-10-19 15:51:08 -04:00
|
|
|
|
this.set("content", [{ identifier: 1, item: "robin" }]);
|
2017-08-13 08:34:50 -04:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
test(assert) {
|
2017-11-09 13:57:53 -05:00
|
|
|
|
expandSelectBoxKit();
|
2017-08-15 20:34:43 -04:00
|
|
|
|
|
2017-08-13 08:34:50 -04:00
|
|
|
|
andThen(() => {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
assert.equal(selectBox().selectedRow.name(), "robin");
|
2017-08-13 08:34:50 -04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
componentTest('doesn’t render collection content before first expand', {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
template: '{{select-box-kit value=1 content=content}}',
|
2017-08-13 08:34:50 -04:00
|
|
|
|
|
|
|
|
|
beforeEach() {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
this.set("content", [{ value: 1, name: "robin" }]);
|
2017-08-13 08:34:50 -04:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
test(assert) {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
assert.notOk(exists(find(".select-box-kit-collection")));
|
2017-08-13 08:34:50 -04:00
|
|
|
|
|
2017-11-09 13:57:53 -05:00
|
|
|
|
expandSelectBoxKit();
|
2017-08-15 20:34:43 -04:00
|
|
|
|
|
2017-08-13 08:34:50 -04:00
|
|
|
|
andThen(() => {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
assert.ok(exists(find(".select-box-kit-collection")));
|
2017-08-13 08:34:50 -04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
componentTest('supports options to limit size', {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
template: '{{select-box-kit collectionHeight=20 content=content}}',
|
2017-08-13 08:34:50 -04:00
|
|
|
|
|
|
|
|
|
beforeEach() {
|
2017-11-09 15:33:36 -05:00
|
|
|
|
this.set("content", ["robin", "régis"]);
|
2017-08-13 08:34:50 -04:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
test(assert) {
|
2017-11-09 13:57:53 -05:00
|
|
|
|
expandSelectBoxKit();
|
2017-08-24 10:04:47 -04:00
|
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
const height = find(".select-box-kit-collection").height();
|
|
|
|
|
assert.equal(parseInt(height, 10), 20, "it limits the height");
|
2017-08-24 10:04:47 -04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2017-10-19 15:51:08 -04:00
|
|
|
|
componentTest('dynamic headerText', {
|
|
|
|
|
template: '{{select-box-kit value=1 content=content}}',
|
2017-08-24 10:04:47 -04:00
|
|
|
|
|
|
|
|
|
beforeEach() {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
this.set("content", [{ id: 1, name: "robin" }, { id: 2, name: "regis" }]);
|
2017-08-24 10:04:47 -04:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
test(assert) {
|
2017-11-09 13:57:53 -05:00
|
|
|
|
expandSelectBoxKit();
|
2017-08-15 20:34:43 -04:00
|
|
|
|
|
2017-10-19 15:51:08 -04:00
|
|
|
|
andThen(() => assert.equal(selectBox().header.name(), "robin") );
|
2017-08-29 06:25:54 -04:00
|
|
|
|
|
2017-11-09 13:57:53 -05:00
|
|
|
|
selectBoxKitSelectRow(2);
|
2017-08-29 06:25:54 -04:00
|
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
assert.equal(selectBox().header.name(), "regis", "it changes header text");
|
2017-08-29 06:25:54 -04:00
|
|
|
|
});
|
2017-08-13 08:34:50 -04:00
|
|
|
|
}
|
|
|
|
|
});
|
2017-08-24 12:31:33 -04:00
|
|
|
|
|
2017-10-19 15:51:08 -04:00
|
|
|
|
componentTest('supports custom row template', {
|
|
|
|
|
template: '{{select-box-kit content=content templateForRow=templateForRow}}',
|
2017-08-24 12:31:33 -04:00
|
|
|
|
|
|
|
|
|
beforeEach() {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
this.set("content", [{ id: 1, name: "robin" }]);
|
|
|
|
|
this.set("templateForRow", rowComponent => {
|
|
|
|
|
return `<b>${rowComponent.get("content.name")}</b>`;
|
|
|
|
|
});
|
2017-08-24 12:31:33 -04:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
test(assert) {
|
2017-11-09 13:57:53 -05:00
|
|
|
|
expandSelectBoxKit();
|
2017-09-14 13:50:32 -04:00
|
|
|
|
|
2017-10-19 15:51:08 -04:00
|
|
|
|
andThen(() => assert.equal(selectBox().rowByValue(1).el.html().trim(), "<b>robin</b>") );
|
2017-08-24 12:31:33 -04:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2017-10-19 15:51:08 -04:00
|
|
|
|
componentTest('supports converting select value to integer', {
|
|
|
|
|
template: '{{select-box-kit value=value content=content castInteger=true}}',
|
2017-08-24 12:31:33 -04:00
|
|
|
|
|
|
|
|
|
beforeEach() {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
this.set("value", 2);
|
|
|
|
|
this.set("content", [{ id: "1", name: "robin"}, {id: "2", name: "régis" }]);
|
2017-08-24 12:31:33 -04:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
test(assert) {
|
2017-11-09 13:57:53 -05:00
|
|
|
|
expandSelectBoxKit();
|
2017-09-14 13:50:32 -04:00
|
|
|
|
|
2017-10-19 15:51:08 -04:00
|
|
|
|
andThen(() => assert.equal(selectBox().selectedRow.name(), "régis") );
|
|
|
|
|
|
2017-08-24 12:31:33 -04:00
|
|
|
|
andThen(() => {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
this.set("value", 3);
|
|
|
|
|
this.set("content", [{ id: "3", name: "jeff" }]);
|
2017-08-24 12:31:33 -04:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
assert.equal(selectBox().selectedRow.name(), "jeff", "it works with dynamic content");
|
2017-08-24 12:31:33 -04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2017-08-28 08:34:04 -04:00
|
|
|
|
|
2017-09-10 13:12:03 -04:00
|
|
|
|
componentTest('supports keyboard events', {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
template: '{{select-box-kit content=content filterable=true}}',
|
2017-09-10 13:12:03 -04:00
|
|
|
|
|
|
|
|
|
beforeEach() {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
this.set("content", [{ id: 1, name: "robin" }, { id: 2, name: "regis" }]);
|
2017-09-10 13:12:03 -04:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
test(assert) {
|
2017-11-09 13:57:53 -05:00
|
|
|
|
expandSelectBoxKit();
|
2017-09-14 13:50:32 -04:00
|
|
|
|
|
|
|
|
|
selectBox().keyboard.down();
|
2017-09-10 13:12:03 -04:00
|
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
assert.equal(selectBox().highlightedRow.title(), "regis", "the next row is highlighted");
|
2017-09-10 13:12:03 -04:00
|
|
|
|
});
|
|
|
|
|
|
2017-09-14 13:50:32 -04:00
|
|
|
|
selectBox().keyboard.down();
|
2017-09-10 13:12:03 -04:00
|
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
assert.equal(selectBox().highlightedRow.title(), "robin", "it returns to the first row");
|
2017-09-10 13:12:03 -04:00
|
|
|
|
});
|
|
|
|
|
|
2017-09-14 13:50:32 -04:00
|
|
|
|
selectBox().keyboard.up();
|
2017-09-10 13:12:03 -04:00
|
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
assert.equal(selectBox().highlightedRow.title(), "regis", "it highlights the last row");
|
2017-09-10 13:12:03 -04:00
|
|
|
|
});
|
|
|
|
|
|
2017-09-14 13:50:32 -04:00
|
|
|
|
selectBox().keyboard.enter();
|
2017-09-10 13:12:03 -04:00
|
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-10-19 15:51:08 -04:00
|
|
|
|
assert.equal(selectBox().selectedRow.title(), "regis", "it selects the row when pressing enter");
|
2017-09-14 13:50:32 -04:00
|
|
|
|
assert.notOk(selectBox().isExpanded, "it collapses the select box when selecting a row");
|
2017-09-10 13:12:03 -04:00
|
|
|
|
});
|
|
|
|
|
|
2017-11-09 13:57:53 -05:00
|
|
|
|
expandSelectBoxKit();
|
2017-09-10 13:12:03 -04:00
|
|
|
|
|
2017-09-14 13:50:32 -04:00
|
|
|
|
selectBox().keyboard.escape();
|
2017-09-10 13:12:03 -04:00
|
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-09-14 13:50:32 -04:00
|
|
|
|
assert.notOk(selectBox().isExpanded, "it collapses the select box");
|
2017-09-10 13:12:03 -04:00
|
|
|
|
});
|
2017-09-10 18:38:32 -04:00
|
|
|
|
|
2017-11-09 13:57:53 -05:00
|
|
|
|
expandSelectBoxKit();
|
2017-09-14 13:50:32 -04:00
|
|
|
|
|
2017-11-09 13:57:53 -05:00
|
|
|
|
selectBoxKitFillInFilter("regis");
|
2017-09-10 18:38:32 -04:00
|
|
|
|
|
2017-09-14 13:50:32 -04:00
|
|
|
|
selectBox().keyboard.tab();
|
2017-09-10 18:38:32 -04:00
|
|
|
|
|
|
|
|
|
andThen(() => {
|
2017-09-14 13:50:32 -04:00
|
|
|
|
assert.notOk(selectBox().isExpanded, "it collapses the select box when selecting a row");
|
2017-09-10 18:38:32 -04:00
|
|
|
|
});
|
2017-09-10 13:12:03 -04:00
|
|
|
|
}
|
|
|
|
|
});
|
2017-10-20 16:40:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
componentTest('supports mutating value when no value given', {
|
|
|
|
|
template: '{{select-box-kit value=value content=content}}',
|
|
|
|
|
|
|
|
|
|
beforeEach() {
|
|
|
|
|
this.set("value", "");
|
|
|
|
|
this.set("content", [{ id: "1", name: "robin"}, {id: "2", name: "régis" }]);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
test(assert) {
|
|
|
|
|
andThen(() => {
|
|
|
|
|
assert.equal(this.get("value"), "1");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|