7c203a9220
* Create PopoverSelect component and styling * Create CatalogToolbar component and Styling * ui: Adds `selectable-key-values` helper (#7472) Preferably we want all copy/text to live in the template. Whilst you can achieve what we've done here with a combination of different helpers, as we will be using this approach in various places it's probably best to make a helper. We also hit an ember bug related to using the `let` helper and trying to access `thingThatWasLet.firstObject` (which can also be worked around using `object-at`). Moving everything to a helper 'sorted' everything. Probably worthwhile noting that if the sort option themselves become dynamic, I'm not sure if the helper here would actually react as you would expect (I'm aware that ember helpers on react on the root arguments, not necesarily sub properties of those arguments). If we get to that point this helper could take the same approach as what I believe ember-composable-helpers does to get around this, or move them to the view controller. If we do ever moved this to the view controller, we can still use the exported function from the new helper here to keep using the same functionality and tests we have here. * Create tests for sorting services with CatalogToolbar * Add rule to print 'ember/no-global-jquery' as a warning Co-authored-by: John Cowen <johncowen@users.noreply.github.com>
35 lines
1.7 KiB
JavaScript
35 lines
1.7 KiB
JavaScript
import { selectableKeyValues } from 'consul-ui/helpers/selectable-key-values';
|
|
import { module, test } from 'qunit';
|
|
|
|
module('Unit | Helper | selectable-key-values', function() {
|
|
test('it turns arrays into key values and selects the first item by default', function(assert) {
|
|
const actual = selectableKeyValues([['key-1', 'value-1'], ['key-2', 'value-2']]);
|
|
assert.equal(actual.items.length, 2);
|
|
assert.deepEqual(actual.selected, { key: 'key-1', value: 'value-1' });
|
|
});
|
|
test('it turns arrays into key values and selects the defined key', function(assert) {
|
|
const actual = selectableKeyValues([['key-1', 'value-1'], ['key-2', 'value-2']], {
|
|
selected: 'key-2',
|
|
});
|
|
assert.equal(actual.items.length, 2);
|
|
assert.deepEqual(actual.selected, { key: 'key-2', value: 'value-2' });
|
|
});
|
|
test('it turns arrays into key values and selects the defined index', function(assert) {
|
|
const actual = selectableKeyValues([['key-1', 'value-1'], ['key-2', 'value-2']], {
|
|
selected: 1,
|
|
});
|
|
assert.equal(actual.items.length, 2);
|
|
assert.deepEqual(actual.selected, { key: 'key-2', value: 'value-2' });
|
|
});
|
|
test('it turns arrays with only one element into key values and selects the defined index', function(assert) {
|
|
const actual = selectableKeyValues([['Value 1'], ['Value 2']], { selected: 1 });
|
|
assert.equal(actual.items.length, 2);
|
|
assert.deepEqual(actual.selected, { key: 'value-2', value: 'Value 2' });
|
|
});
|
|
test('it turns strings into key values and selects the defined index', function(assert) {
|
|
const actual = selectableKeyValues(['Value 1', 'Value 2'], { selected: 1 });
|
|
assert.equal(actual.items.length, 2);
|
|
assert.deepEqual(actual.selected, { key: 'value-2', value: 'Value 2' });
|
|
});
|
|
});
|