2017-10-19 15:51:08 -04:00
import componentTest from 'helpers/component-test';
2017-12-22 07:08:12 -05:00
moduleForComponent('category-chooser', {
integration: true,
beforeEach: function() {
this.set('subject', selectKit());
}
});
2017-10-19 15:51:08 -04:00
componentTest('with value', {
template: '{{category-chooser value=2}}',
test(assert) {
andThen(() => {
2017-12-22 07:08:12 -05:00
assert.equal(this.get('subject').header().value(), 2);
assert.equal(this.get('subject').header().title(), 'feature');
2017-10-19 15:51:08 -04:00
});
}
});
componentTest('with excludeCategoryId', {
template: '{{category-chooser excludeCategoryId=2}}',
test(assert) {
2017-12-22 07:08:12 -05:00
this.get('subject').expand();
2017-10-19 15:51:08 -04:00
2017-12-22 07:08:12 -05:00
andThen(() => assert.notOk(this.get('subject').rowByValue(2).exists()));
2017-10-19 15:51:08 -04:00
}
});
componentTest('with scopedCategoryId', {
template: '{{category-chooser scopedCategoryId=2}}',
test(assert) {
2017-12-22 07:08:12 -05:00
this.get('subject').expand();
2017-10-19 15:51:08 -04:00
andThen(() => {
2018-03-27 08:11:05 -04:00
assert.equal(this.get('subject').rowByIndex(0).title(), 'Discussion about features or potential features of Discourse: how they work, why they work, etc.');
2017-12-22 07:08:12 -05:00
assert.equal(this.get('subject').rowByIndex(0).value(), 2);
2018-03-27 08:11:05 -04:00
assert.equal(this.get('subject').rowByIndex(1).title(), 'My idea here is to have mini specs for features we would like built but have no bandwidth to build');
2017-12-22 07:08:12 -05:00
assert.equal(this.get('subject').rowByIndex(1).value(), 26);
assert.equal(this.get('subject').rows().length, 2);
2017-10-19 15:51:08 -04:00
});
}
});
componentTest('with allowUncategorized=null', {
template: '{{category-chooser allowUncategorized=null}}',
beforeEach() {
this.siteSettings.allow_uncategorized_topics = false;
},
test(assert) {
andThen(() => {
2017-12-22 07:08:12 -05:00
assert.equal(this.get('subject').header().value(), null);
2018-05-23 15:07:39 -04:00
assert.equal(this.get('subject').header().title(), "Select a category");
2017-10-19 15:51:08 -04:00
});
}
});
componentTest('with allowUncategorized=null rootNone=true', {
template: '{{category-chooser allowUncategorized=null rootNone=true}}',
beforeEach() {
this.siteSettings.allow_uncategorized_topics = false;
},
test(assert) {
andThen(() => {
2017-12-22 07:08:12 -05:00
assert.equal(this.get('subject').header().value(), null);
2018-05-23 15:07:39 -04:00
assert.equal(this.get('subject').header().title(), 'Select a category');
2017-10-19 15:51:08 -04:00
});
}
});
componentTest('with disallowed uncategorized, rootNone and rootNoneLabel', {
template: '{{category-chooser allowUncategorized=null rootNone=true rootNoneLabel="test.root"}}',
beforeEach() {
2017-12-22 07:08:12 -05:00
I18n.translations[I18n.locale].js.test = { root: 'root none label' };
2017-10-19 15:51:08 -04:00
this.siteSettings.allow_uncategorized_topics = false;
},
test(assert) {
andThen(() => {
2017-12-22 07:08:12 -05:00
assert.equal(this.get('subject').header().value(), null);
2018-05-23 15:07:39 -04:00
assert.equal(this.get('subject').header().title(), 'Select a category');
2017-10-19 15:51:08 -04:00
});
}
});
componentTest('with allowed uncategorized', {
template: '{{category-chooser allowUncategorized=true}}',
beforeEach() {
this.siteSettings.allow_uncategorized_topics = true;
},
test(assert) {
andThen(() => {
2017-12-22 07:08:12 -05:00
assert.equal(this.get('subject').header().value(), null);
assert.equal(this.get('subject').header().title(), 'uncategorized');
2017-10-19 15:51:08 -04:00
});
}
});
componentTest('with allowed uncategorized and rootNone', {
template: '{{category-chooser allowUncategorized=true rootNone=true}}',
beforeEach() {
this.siteSettings.allow_uncategorized_topics = true;
},
test(assert) {
andThen(() => {
2017-12-22 07:08:12 -05:00
assert.equal(this.get('subject').header().value(), null);
assert.equal(this.get('subject').header().title(), '(no category)');
2017-10-19 15:51:08 -04:00
});
}
});
componentTest('with allowed uncategorized rootNone and rootNoneLabel', {
template: '{{category-chooser allowUncategorized=true rootNone=true rootNoneLabel="test.root"}}',
beforeEach() {
2017-12-22 07:08:12 -05:00
I18n.translations[I18n.locale].js.test = { root: 'root none label' };
2017-10-19 15:51:08 -04:00
this.siteSettings.allow_uncategorized_topics = true;
},
test(assert) {
andThen(() => {
2017-12-22 07:08:12 -05:00
assert.equal(this.get('subject').header().value(), null);
assert.equal(this.get('subject').header().title(), 'root none label');
2017-10-19 15:51:08 -04:00
});
}
});