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