2015-10-07 17:44:23 +03:00
|
|
|
/* jshint expr:true */
|
2016-06-30 13:21:47 +03:00
|
|
|
import Service from 'ember-service';
|
2017-05-29 21:50:03 +03:00
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
import {describe, it} from 'mocha';
|
2016-06-30 13:21:47 +03:00
|
|
|
import {A as emberA} from 'ember-array/utils';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {expect} from 'chai';
|
|
|
|
import {setupComponentTest} from 'ember-mocha';
|
2015-10-28 14:36:45 +03:00
|
|
|
|
2016-06-11 19:52:36 +03:00
|
|
|
let notificationsStub = Service.extend({
|
2015-10-28 14:36:45 +03:00
|
|
|
alerts: emberA()
|
|
|
|
});
|
2015-10-07 17:44:23 +03:00
|
|
|
|
2016-11-24 01:50:57 +03:00
|
|
|
describe('Integration: Component: gh-alerts', function () {
|
|
|
|
setupComponentTest('gh-alerts', {
|
2015-10-07 17:44:23 +03:00
|
|
|
integration: true
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
this.register('service:notifications', notificationsStub);
|
|
|
|
this.inject.service('notifications', {as: 'notifications'});
|
|
|
|
|
|
|
|
this.set('notifications.alerts', [
|
|
|
|
{message: 'First', type: 'error'},
|
|
|
|
{message: 'Second', type: 'warn'}
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders', function () {
|
|
|
|
this.render(hbs`{{gh-alerts}}`);
|
|
|
|
expect(this.$('.gh-alerts').length).to.equal(1);
|
|
|
|
expect(this.$('.gh-alerts').children().length).to.equal(2);
|
|
|
|
|
|
|
|
this.set('notifications.alerts', emberA());
|
|
|
|
expect(this.$('.gh-alerts').children().length).to.equal(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('triggers "notify" action when message count changes', function () {
|
|
|
|
let expectedCount = 0;
|
|
|
|
|
|
|
|
// test double for notify action
|
|
|
|
this.set('notify', (count) => expect(count).to.equal(expectedCount));
|
|
|
|
|
|
|
|
this.render(hbs`{{gh-alerts notify=(action notify)}}`);
|
|
|
|
|
|
|
|
expectedCount = 3;
|
|
|
|
this.get('notifications.alerts').pushObject({message: 'Third', type: 'success'});
|
|
|
|
|
|
|
|
expectedCount = 0;
|
|
|
|
this.set('notifications.alerts', emberA());
|
|
|
|
});
|
|
|
|
});
|