mirror of
https://github.com/status-im/consul.git
synced 2025-02-22 18:38:19 +00:00
ui: Adds a default
view helper for providing a default value (#4650)
If the first value passed to the helper is an empty string or undefined then return the second value
This commit is contained in:
parent
5ea748005c
commit
0757a08684
10
ui-v2/app/helpers/default.js
Normal file
10
ui-v2/app/helpers/default.js
Normal file
@ -0,0 +1,10 @@
|
||||
import { helper } from '@ember/component/helper';
|
||||
|
||||
export function _default(params, hash) {
|
||||
if (params[0] === '' || typeof params[0] === 'undefined') {
|
||||
return params[1];
|
||||
}
|
||||
return params[0];
|
||||
}
|
||||
|
||||
export default helper(_default);
|
@ -38,7 +38,7 @@
|
||||
href=(href-to 'dc.nodes.show' item.Node.Node)
|
||||
name=item.Node.Node
|
||||
service=item.Service.ID
|
||||
address=(concat item.Service.Address ':' item.Service.Port)
|
||||
address=(concat (default item.Service.Address item.Node.Address) ':' item.Service.Port)
|
||||
checks=item.Checks
|
||||
}}
|
||||
{{/each}}
|
||||
@ -58,7 +58,7 @@
|
||||
data-test-node=item.Node.Node
|
||||
name=item.Node.Node
|
||||
service=item.Service.ID
|
||||
address=(concat item.Service.Address ':' item.Service.Port)
|
||||
address=(concat (default item.Service.Address item.Node.Address) ':' item.Service.Port)
|
||||
checks=item.Checks
|
||||
status=item.Checks.[0].Status
|
||||
}}
|
||||
|
32
ui-v2/tests/integration/helpers/default-test.js
Normal file
32
ui-v2/tests/integration/helpers/default-test.js
Normal file
@ -0,0 +1,32 @@
|
||||
import { moduleForComponent, test } from 'ember-qunit';
|
||||
import hbs from 'htmlbars-inline-precompile';
|
||||
|
||||
moduleForComponent('default', 'helper:default', {
|
||||
integration: true,
|
||||
});
|
||||
|
||||
// Replace this with your real tests.
|
||||
test('it renders', function(assert) {
|
||||
this.set('inputValue', '1234');
|
||||
|
||||
this.render(hbs`{{default inputValue}}`);
|
||||
|
||||
assert.equal(
|
||||
this.$()
|
||||
.text()
|
||||
.trim(),
|
||||
'1234'
|
||||
);
|
||||
});
|
||||
test('it renders the default value', function(assert) {
|
||||
this.set('inputValue', '');
|
||||
|
||||
this.render(hbs`{{default inputValue '1234'}}`);
|
||||
|
||||
assert.equal(
|
||||
this.$()
|
||||
.text()
|
||||
.trim(),
|
||||
'1234'
|
||||
);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user