mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 08:23:39 +08:00
0431942f3d
This new iteration of select-kit focuses on following best principales and disallowing mutations inside select-kit components. A best effort has been made to avoid breaking changes, however if you content was a flat array, eg: ["foo", "bar"] You will need to set valueProperty=null and nameProperty=null on the component. Also almost every component should have an `onChange` handler now to decide what to do with the updated data. **select-kit will not mutate your data by itself anymore**
103 lines
2.0 KiB
JavaScript
103 lines
2.0 KiB
JavaScript
import selectKit from "helpers/select-kit-helper";
|
|
import componentTest from "helpers/component-test";
|
|
|
|
moduleForComponent("select-kit/combo-box", {
|
|
integration: true,
|
|
beforeEach() {
|
|
this.set("subject", selectKit());
|
|
}
|
|
});
|
|
|
|
const DEFAULT_CONTENT = [
|
|
{ id: 1, name: "foo" },
|
|
{ id: 2, name: "bar" },
|
|
{ id: 3, name: "baz" }
|
|
];
|
|
|
|
const DEFAULT_VALUE = 1;
|
|
|
|
const setDefaultState = (ctx, options) => {
|
|
const properties = Object.assign(
|
|
{
|
|
content: DEFAULT_CONTENT,
|
|
value: DEFAULT_VALUE
|
|
},
|
|
options || {}
|
|
);
|
|
ctx.setProperties(properties);
|
|
};
|
|
|
|
componentTest("options.clearable", {
|
|
template: `
|
|
{{combo-box
|
|
value=value
|
|
content=content
|
|
onChange=onChange
|
|
options=(hash clearable=clearable)
|
|
}}
|
|
`,
|
|
|
|
beforeEach() {
|
|
setDefaultState(this, {
|
|
clearable: true,
|
|
onChange: value => {
|
|
this.set("value", value);
|
|
}
|
|
});
|
|
},
|
|
|
|
async test(assert) {
|
|
const $header = this.subject.header();
|
|
|
|
assert.ok(
|
|
exists($header.el().find(".btn-clear")),
|
|
"it shows the clear button"
|
|
);
|
|
assert.equal($header.value(), DEFAULT_VALUE);
|
|
|
|
await click($header.el().find(".btn-clear"));
|
|
|
|
assert.notOk(
|
|
exists($header.el().find(".btn-clear")),
|
|
"it hides the clear button"
|
|
);
|
|
assert.equal($header.value(), null);
|
|
}
|
|
});
|
|
|
|
componentTest("options.{caretUpIcon,caretDownIcon}", {
|
|
template: `
|
|
{{combo-box
|
|
value=value
|
|
content=content
|
|
options=(hash
|
|
caretUpIcon=caretUpIcon
|
|
caretDownIcon=caretDownIcon
|
|
)
|
|
}}
|
|
`,
|
|
|
|
beforeEach() {
|
|
setDefaultState(this, {
|
|
caretUpIcon: "pencil-alt",
|
|
caretDownIcon: "trash-alt"
|
|
});
|
|
},
|
|
|
|
async test(assert) {
|
|
const $header = this.subject.header().el();
|
|
|
|
assert.ok(
|
|
exists($header.find(`.d-icon-${this.caretDownIcon}`)),
|
|
"it uses the icon provided"
|
|
);
|
|
|
|
await this.subject.expand();
|
|
|
|
assert.ok(
|
|
exists($header.find(`.d-icon-${this.caretUpIcon}`)),
|
|
"it uses the icon provided"
|
|
);
|
|
}
|
|
});
|