discourse/test/javascripts/components/categpry-selector-test.js.es6
Joffrey JAFFEUX 39f3dbd945
Introduces select-kit
* renames `select-box-kit` into `select-kit`
* introduces `single-select` and `multi-select` as base components
* introduces {{search-advanced-category-chooser}} as a better component for selecting category in advanced search
* improves events handling in select-kit
* recreates color selection inputs using {{multi-select}} and a custom {{selected-color}} component
* replaces category-selector by a component using select-kit and based on multi-select
* improves positioning of wrapper
* removes the need for offscreen, and instead use `select-kit-header` as a base focus point for all select-kit based components
* introduces a formal plugin api for select-kit based components
* introduces a formal pattern for loading and updating select-kit based components:

```
computeValue()
computeContent()
mutateValue()
```
2017-11-21 11:53:09 +01:00

68 lines
1.8 KiB
JavaScript

import componentTest from 'helpers/component-test';
import Category from "discourse/models/category";
moduleForComponent('category-selector', {integration: true});
componentTest('default', {
template: '{{category-selector categories=categories}}',
beforeEach() {
this.set('categories', [ Category.findById(2) ]);
},
test(assert) {
andThen(() => {
assert.propEqual(selectKit().header.name(), 'feature');
assert.ok(!exists(".select-kit .select-kit-row[data-value='2']"), "selected categories are not in the list");
});
}
});
componentTest('with blacklist', {
template: '{{category-selector categories=categories blacklist=blacklist}}',
beforeEach() {
this.set('categories', [ Category.findById(2) ]);
this.set('blacklist', [ Category.findById(8) ]);
},
test(assert) {
expandSelectKit();
andThen(() => {
assert.ok(exists(".select-kit .select-kit-row[data-value='6']"), "not blacklisted categories are in the list");
assert.ok(!exists(".select-kit .select-kit-row[data-value='8']"), "blacklisted categories are not in the list");
});
}
});
componentTest('interactions', {
template: '{{category-selector categories=categories}}',
beforeEach() {
this.set('categories', [
Category.findById(2),
Category.findById(6)
]);
},
test(assert) {
expandSelectKit();
selectKitSelectRow(8);
andThen(() => {
assert.propEqual(selectKit().header.name(), 'feature,support,hosting', 'it adds the selected category');
assert.equal(this.get('categories').length, 3);
});
selectKit().keyboard.backspace();
selectKit().keyboard.backspace();
andThen(() => {
assert.propEqual(selectKit().header.name(), 'feature,support', 'it removes the last selected category');
assert.equal(this.get('categories').length, 2);
});
}
});