diff --git a/app/components/build-messages.js b/app/components/build-messages.js new file mode 100644 index 00000000..c87d3a97 --- /dev/null +++ b/app/components/build-messages.js @@ -0,0 +1,14 @@ +import Ember from "ember"; + +export default Ember.Component.extend({ + tagName: 'span', + classNames: ['build-msgs'], + actions: { + showErrors () { + this.get('buildErrors').forEach((error) => { + console.error(error); + }); + this.get('notify').info('Errors were dumped to console'); + } + } +}); diff --git a/app/gist/controller.js b/app/gist/controller.js index c867e04f..1577dc08 100644 --- a/app/gist/controller.js +++ b/app/gist/controller.js @@ -161,13 +161,6 @@ export default Ember.Controller.extend({ } }, - showErrors () { - this.get('buildErrors').forEach((error) => { - console.error(error); - }); - this.notify.info('Errors were dumped to console'); - }, - fork (gist) { gist.fork().then((response) => { this.transitionToRoute('gist.edit', response.id); diff --git a/app/gist/template.hbs b/app/gist/template.hbs index 5658d958..6e67fb84 100644 --- a/app/gist/template.hbs +++ b/app/gist/template.hbs @@ -45,18 +45,10 @@
- - {{#if isBuilding}} - Building... - {{else}} - Output - ({{#if buildErrors}} - {{buildErrors.length}} build errors - {{else}} - build ok. - {{/if}}) - {{/if}} - + {{build-messages notify=notify + isBuilding=isBuilding + buildErrors=buildErrors + }}
{{run-or-live-reload liveReloadChanged="liveReloadChanged" runNow="runNow"}}
diff --git a/app/templates/components/build-messages.hbs b/app/templates/components/build-messages.hbs new file mode 100644 index 00000000..3689770c --- /dev/null +++ b/app/templates/components/build-messages.hbs @@ -0,0 +1,10 @@ +{{#if isBuilding}} + Building... +{{else}} + Output + ({{#if buildErrors}} + {{buildErrors.length}} build errors + {{else}} + build ok. + {{/if}}) +{{/if}} \ No newline at end of file diff --git a/tests/integration/components/build-messages-test.js b/tests/integration/components/build-messages-test.js new file mode 100644 index 00000000..b5b58137 --- /dev/null +++ b/tests/integration/components/build-messages-test.js @@ -0,0 +1,53 @@ +import Ember from 'ember'; +import { moduleForComponent, test } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; + +moduleForComponent('build-messages', 'Integration | Component | build messages', { + integration: true, + beforeEach() { + this.cacheConsole = console.error; + }, + afterEach() { + console.error = this.cacheConsole; + } +}); + +test('it shows the number of build messages', function(assert) { + assert.expect(2); + + this.set('buildErrors', []); + this.set('isBuilding', false); + this.set('notify', { + info() {} + }); + + this.render(hbs`{{build-messages buildErrors=buildErrors isBuilding=isBuilding notify=notify}}`); + + assert.equal(this.$('span').text().replace(/\s+/g, " ").trim(), 'Output ( build ok. )', 'shows build ok when no buildErrors'); + + this.set('buildErrors', ['error1', 'error2']); + + assert.equal(this.$('span').text().replace(/\s+/g, " ").trim(), 'Output ( 2 build errors )', 'shows number of build errors'); +}); + +test('it calls notify.info() when clicking on build errors', function(assert) { + assert.expect(1); + + let notifyObject = Ember.Object.create({ + called: false, + info() { + this.set('called', true); + } + }); + + console.error = () => {}; + this.set('buildErrors', ['error1', 'error2']); + this.set('isBuilding', false); + this.set('notify', notifyObject); + + this.render(hbs`{{build-messages buildErrors=buildErrors isBuilding=isBuilding notify=notify}}`); + + this.$('span a').click(); + + assert.ok(notifyObject.get('called'), "notify.info() was called"); +});