mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: implements minimum selection for select-kit
This commit is contained in:
@@ -160,3 +160,44 @@ componentTest('with limitMatches', {
|
||||
andThen(() => assert.equal(this.get('subject').el().find(".select-kit-row").length, 2));
|
||||
}
|
||||
});
|
||||
|
||||
componentTest('with minimum', {
|
||||
template: '{{multi-select content=content minimum=1}}',
|
||||
|
||||
beforeEach() {
|
||||
this.set('content', ['sam', 'jeff', 'neil']);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
this.get('subject').expand();
|
||||
|
||||
andThen(() => assert.equal(this.get('subject').validationMessage(), 'Select at least 1 item(s).'));
|
||||
|
||||
this.get('subject').selectRowByValue('sam');
|
||||
|
||||
andThen(() => {
|
||||
assert.equal(this.get('subject').header().label(), 'sam');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
componentTest('with minimumLabel', {
|
||||
template: '{{multi-select content=content minimum=1 minimumLabel="test.minimum"}}',
|
||||
|
||||
beforeEach() {
|
||||
I18n.translations[I18n.locale].js.test = { minimum: 'min %{count}' };
|
||||
this.set('content', ['sam', 'jeff', 'neil']);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
this.get('subject').expand();
|
||||
|
||||
andThen(() => assert.equal(this.get('subject').validationMessage(), 'min 1'));
|
||||
|
||||
this.get('subject').selectRowByValue('jeff');
|
||||
|
||||
andThen(() => {
|
||||
assert.equal(this.get('subject').header().label(), 'jeff');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -501,3 +501,44 @@ componentTest('with limitMatches', {
|
||||
andThen(() => assert.equal(this.get('subject').el().find(".select-kit-row").length, 2));
|
||||
}
|
||||
});
|
||||
|
||||
componentTest('with minimum', {
|
||||
template: '{{single-select content=content minimum=1 allowAutoSelectFirst=false}}',
|
||||
|
||||
beforeEach() {
|
||||
this.set('content', ['sam', 'jeff', 'neil']);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
this.get('subject').expand();
|
||||
|
||||
andThen(() => assert.equal(this.get('subject').validationMessage(), 'Select at least 1 item(s).'));
|
||||
|
||||
this.get('subject').selectRowByValue('sam');
|
||||
|
||||
andThen(() => {
|
||||
assert.equal(this.get('subject').header().label(), 'sam');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
componentTest('with minimumLabel', {
|
||||
template: '{{single-select content=content minimum=1 minimumLabel="test.minimum" allowAutoSelectFirst=false}}',
|
||||
|
||||
beforeEach() {
|
||||
I18n.translations[I18n.locale].js.test = { minimum: 'min %{count}' };
|
||||
this.set('content', ['sam', 'jeff', 'neil']);
|
||||
},
|
||||
|
||||
test(assert) {
|
||||
this.get('subject').expand();
|
||||
|
||||
andThen(() => assert.equal(this.get('subject').validationMessage(), 'min 1'));
|
||||
|
||||
this.get('subject').selectRowByValue('jeff');
|
||||
|
||||
andThen(() => {
|
||||
assert.equal(this.get('subject').header().label(), 'jeff');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -63,6 +63,7 @@ function selectKit(selector) { // eslint-disable-line no-unused-vars
|
||||
return {
|
||||
value: function() { return header.attr('data-value'); },
|
||||
name: function() { return header.attr('data-name'); },
|
||||
label: function() { return header.text().trim(); },
|
||||
icon: function() { return header.find('.icon'); },
|
||||
title: function() { return header.attr('title'); },
|
||||
el: function() { return header; }
|
||||
@@ -183,6 +184,16 @@ function selectKit(selector) { // eslint-disable-line no-unused-vars
|
||||
return rowHelper(find(selector).find('.select-kit-row.none'));
|
||||
},
|
||||
|
||||
validationMessage: function() {
|
||||
var validationMessage = find(selector).find('.validation-message');
|
||||
|
||||
if (validationMessage.length) {
|
||||
return validationMessage.html().trim();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
selectedRow: function() {
|
||||
return rowHelper(find(selector).find('.select-kit-row.is-selected'));
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user