Skip to content
Permalink
Browse files

Alert banner component takes an optional block

  • Loading branch information...
alisdair committed Jun 20, 2015
1 parent 4fc33ba commit 14367960bc7c88318ec5e2d5ea2c2afc3c5be7ea
@@ -13,10 +13,13 @@ export default Ember.Controller.extend({
}
}),

fancy: false,

actions: {
createAlert() {
let alert = Alert.create({
text: this.get('alertText'),
fancy: this.get('fancy'),
closeAction: this.get('closeAction')
});
this.get('alerts').pushObject(alert);
@@ -38,3 +38,6 @@ button.close

.form-group
margin: $spacing / 2 0

.text-danger
color: #d00
@@ -3,4 +3,8 @@
<span aria-hidden="true">×</span>
</button>
{{/if}}
{{text}}
{{#if hasBlock}}
{{yield text}}
{{else}}
{{text}}
{{/if}}
@@ -1,6 +1,14 @@
<div class="alert-banner-container">
{{#each alerts as |alert|}}
{{alert-banner alert=alert closeAction=alert.closeAction}}
{{#if alert.fancy}}
{{#alert-banner alert=alert closeAction=alert.closeAction as |text|}}
<h3 class="text-danger">Something Went Wrong</h3>

<p>{{text}}</p>
{{/alert-banner}}
{{else}}
{{alert-banner alert=alert closeAction=alert.closeAction}}
{{/if}}
{{/each}}
</div>

@@ -13,6 +21,7 @@

<div class="form-group">
<label>{{input type='checkbox' checked=dismissible}} Dismissible</label>
<label>{{input type='checkbox' checked=fancy}} Fancy</label>
</div>

<div class="form-group">
@@ -47,3 +47,27 @@ test('close button and closeAction', function(assert) {
});
$button.click();
});

test('with optional block for rendering text', function(assert) {
assert.expect(3);

var alert = Alert.create({ text: 'The server is on fire!' });
this.set('alert', alert);

this.render(hbs`
{{#alert-banner alert=alert as |text|}}
<h3 class="text-danger">Something Went Wrong</h3>
<p>{{text}}</p>
{{/alert-banner}}
`);

var $alert = this.$('.alert-banner');
assert.equal($alert.length, 1, 'renders alert');

var $h3 = $alert.find('h3.text-danger');
assert.equal($h3.text().trim(), 'Something Went Wrong', 'renders heading');

var $p = $alert.find('p');
assert.equal($p.text().trim(), 'The server is on fire!', 'renders text');
});

0 comments on commit 1436796

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.