Skip to content
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
14 changes: 14 additions & 0 deletions app/components/build-messages.js
Original file line number Diff line number Diff line change
@@ -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');
}
}
});
7 changes: 0 additions & 7 deletions app/gist/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 4 additions & 12 deletions app/gist/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,10 @@

<div class="col-md-4 output">
<div class="header">
<span class="build-msgs">
{{#if isBuilding}}
Building...
{{else}}
Output
({{#if buildErrors}}
<a {{action 'showErrors'}}>{{buildErrors.length}} build errors</a>
{{else}}
build ok.
{{/if}})
{{/if}}
</span>
{{build-messages notify=notify
isBuilding=isBuilding
buildErrors=buildErrors
}}
</div>
{{run-or-live-reload liveReloadChanged="liveReloadChanged" runNow="runNow"}}
<div class="url-bar">
Expand Down
10 changes: 10 additions & 0 deletions app/templates/components/build-messages.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{#if isBuilding}}
Building...
{{else}}
Output
({{#if buildErrors}}
<a {{action 'showErrors'}}>{{buildErrors.length}} build errors</a>
{{else}}
build ok.
{{/if}})
{{/if}}
53 changes: 53 additions & 0 deletions tests/integration/components/build-messages-test.js
Original file line number Diff line number Diff line change
@@ -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");
});