From 2d2cfacdbe2c3ad6a7b2a3e45465d37c722c4645 Mon Sep 17 00:00:00 2001 From: Gaurav Munjal Date: Fri, 7 Aug 2015 09:21:44 -0400 Subject: [PATCH 1/3] Try to extract build-messages --- app/components/build-messages.js | 14 ++++++++++++++ app/gist/controller.js | 7 ------- app/gist/template.hbs | 16 ++++------------ app/templates/components/build-messages.hbs | 10 ++++++++++ 4 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 app/components/build-messages.js create mode 100644 app/templates/components/build-messages.hbs diff --git a/app/components/build-messages.js b/app/components/build-messages.js new file mode 100644 index 00000000..a9f15492 --- /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.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 From 47572aae0e76486a8fb9887752f2bfca344cce6d Mon Sep 17 00:00:00 2001 From: Gaurav Munjal Date: Sat, 8 Aug 2015 08:32:55 -0400 Subject: [PATCH 2/3] Fix component and write tests --- app/components/build-messages.js | 2 +- .../components/build-messages-test.js | 50 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/integration/components/build-messages-test.js diff --git a/app/components/build-messages.js b/app/components/build-messages.js index a9f15492..c87d3a97 100644 --- a/app/components/build-messages.js +++ b/app/components/build-messages.js @@ -8,7 +8,7 @@ export default Ember.Component.extend({ this.get('buildErrors').forEach((error) => { console.error(error); }); - this.notify.info('Errors were dumped to console'); + this.get('notify').info('Errors were dumped to console'); } } }); diff --git a/tests/integration/components/build-messages-test.js b/tests/integration/components/build-messages-test.js new file mode 100644 index 00000000..6d163cf4 --- /dev/null +++ b/tests/integration/components/build-messages-test.js @@ -0,0 +1,50 @@ +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 +}); + +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); + } + }); + + this.cacheConsole = console.error; + 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"); + + console.error = this.cacheConsole; +}); From f1e2d3aec57b0aa2248379a1b54ce4ebebedd5a7 Mon Sep 17 00:00:00 2001 From: Gaurav Munjal Date: Sat, 8 Aug 2015 08:38:13 -0400 Subject: [PATCH 3/3] Address comments --- tests/integration/components/build-messages-test.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/integration/components/build-messages-test.js b/tests/integration/components/build-messages-test.js index 6d163cf4..b5b58137 100644 --- a/tests/integration/components/build-messages-test.js +++ b/tests/integration/components/build-messages-test.js @@ -3,7 +3,13 @@ import { moduleForComponent, test } from 'ember-qunit'; import hbs from 'htmlbars-inline-precompile'; moduleForComponent('build-messages', 'Integration | Component | build messages', { - integration: true + integration: true, + beforeEach() { + this.cacheConsole = console.error; + }, + afterEach() { + console.error = this.cacheConsole; + } }); test('it shows the number of build messages', function(assert) { @@ -34,7 +40,6 @@ test('it calls notify.info() when clicking on build errors', function(assert) { } }); - this.cacheConsole = console.error; console.error = () => {}; this.set('buildErrors', ['error1', 'error2']); this.set('isBuilding', false); @@ -45,6 +50,4 @@ test('it calls notify.info() when clicking on build errors', function(assert) { this.$('span a').click(); assert.ok(notifyObject.get('called'), "notify.info() was called"); - - console.error = this.cacheConsole; });