Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Badge component #36

Merged
merged 2 commits into from
Apr 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions addon/components/materialize-badge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Ember from 'ember';
import layout from '../templates/components/materialize-badge';

export default Ember.Component.extend({
layout: layout,
tagName: 'span',
text: null,
classNames: ['badge']
});
1 change: 1 addition & 0 deletions addon/templates/components/materialize-badge.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{text}}{{yield}}
3 changes: 3 additions & 0 deletions app/components/materialize-badge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import materializeBadge from 'ember-cli-materialize/components/materialize-badge';

export default materializeBadge;
1 change: 1 addition & 0 deletions tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var Router = Ember.Router.extend({
});

Router.map(function() {
this.route("badges");
this.route("buttons");
this.route("navbar");
this.route("cards");
Expand Down
49 changes: 49 additions & 0 deletions tests/dummy/app/templates/badges.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<div class="section index-banner">
<div class="container">
<div class="row">
<div class="col s12 m9">
<h1 class="header">Badges</h1>
</div>
</div>
</div>
</div>

<div class='container'>
<div class="section">
<div class="intro">
<h4 class="col s12 header">The component supports one option:</h4>
<ul>
<li>text, default value <span class="default-value badge">null</span></li>
</ul>
</div>
</div>
<div class="section">
<div class="row">
<div class="col s12">
<ul class="collection">
<li class="collection-item">
1. Steal Underpants
{{materialize-badge class='new' text="6"}}
</li>
<li class="collection-item">2. ???
{{#materialize-badge}}9{{/materialize-badge}}
</li>
<li class="collection-item">3. Profit</li>
</ul>
</div>
</div>
<div class="row">
<div class="col s12">

<pre class=" language-markup">
<code class=" col s12 language-markup">
<span>&#123;&#123;</span>materialize-badge class="new" text="6"<span>&#125;&#125;</span>
<span>&#123;&#123;</span>#materialize-badge<span>&#125;&#125;</span>9<span>&#123;&#123;</span>/materialize-badge<span>&#125;&#125;</span>
</code>
</pre>

</div>
</div>
</div>

</div>
35 changes: 29 additions & 6 deletions tests/dummy/app/templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,35 @@
<h2 class="col s12 header">Usage</h2>
<div class="section">
<ul class="collection">
{{#link-to 'buttons' class="collection-item"}}Buttons<span class="badge">6</span>{{/link-to}}
{{#link-to 'navbar' class="collection-item"}}Navbar<span class="new badge">1</span>{{/link-to}}
{{#link-to 'cards' class="collection-item"}}Cards<span class="new badge">1</span>{{/link-to}}
{{#link-to 'collapsible' class="collection-item"}}Collapsible<span class="new badge">1</span>{{/link-to}}
{{#link-to 'input' class="collection-item"}}Input<span class="new badge">4</span>{{/link-to}}
{{#link-to 'parallax' class="collection-item"}}Parallax<span class="new badge">1</span>{{/link-to}}
{{#link-to 'badges' class="collection-item"}}
Badges
{{#materialize-badge class="new"}}1{{/materialize-badge}}
{{/link-to}}

{{#link-to 'buttons' class="collection-item"}}
Buttons
{{#materialize-badge}}6{{/materialize-badge}}
{{/link-to}}

{{#link-to 'navbar' class="collection-item"}}
Navbar{{#materialize-badge class="new"}}1{{/materialize-badge}}
{{/link-to}}

{{#link-to 'cards' class="collection-item"}}
Cards{{#materialize-badge class="new"}}1{{/materialize-badge}}
{{/link-to}}

{{#link-to 'collapsible' class="collection-item"}}
Collapsible{{#materialize-badge class="new"}}1{{/materialize-badge}}
{{/link-to}}

{{#link-to 'input' class="collection-item"}}
Input{{#materialize-badge class="new"}}4{{/materialize-badge}}
{{/link-to}}

{{#link-to 'parallax' class="collection-item"}}
Parallax{{#materialize-badge class="new"}}1{{/materialize-badge}}
{{/link-to}}
</ul>
</div>

Expand Down
40 changes: 40 additions & 0 deletions tests/unit/components/materialize-badge-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Ember from 'ember';

import {
moduleForComponent,
test
} from 'ember-qunit';

moduleForComponent('materialize-badge', {
// Specify the other units that are required for this test
// needs: ['component:foo', 'helper:bar']
});

test('it renders', function(assert) {
assert.expect(2);

// Creates the component instance
var component = this.subject();
assert.equal(component._state, 'preRender');

// Renders the component to the page
this.render();
assert.equal(component._state, 'inDOM');
});


test('binding to the text property works', function(assert) {
assert.expect(2);

var component = this.subject();

this.render();
assert.equal(component.$().text().trim(), '', 'By default the text property is empty');

Ember.run(function () {
component.set('text', 'Heisenberg');
Ember.run.schedule('afterRender', function () {
assert.equal(component.$().text().trim(), 'Heisenberg', 'Setting the text property updates the content of the badge');
});
});
});