2017-08-22 10:53:26 +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';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {A as emberA} from '@ember/array';
|
2017-05-29 21:50:03 +03:00
|
|
|
import {expect} from 'chai';
|
2019-01-02 12:58:55 +03:00
|
|
|
import {find, findAll, render, settled} from '@ember/test-helpers';
|
|
|
|
import {setupRenderingTest} 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 () {
|
2019-01-02 12:58:55 +03:00
|
|
|
setupRenderingTest();
|
2016-11-24 01:50:57 +03:00
|
|
|
|
|
|
|
beforeEach(function () {
|
2019-01-02 12:58:55 +03:00
|
|
|
this.owner.register('service:notifications', notificationsStub);
|
|
|
|
let notifications = this.owner.lookup('service:notifications');
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
notifications.set('alerts', [
|
2016-11-24 01:50:57 +03:00
|
|
|
{message: 'First', type: 'error'},
|
|
|
|
{message: 'Second', type: 'warn'}
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('renders', async function () {
|
|
|
|
let notifications = this.owner.lookup('service:notifications');
|
|
|
|
|
|
|
|
await render(hbs`{{gh-alerts}}`);
|
|
|
|
expect(findAll('.gh-alerts').length).to.equal(1);
|
|
|
|
expect(find('.gh-alerts').children.length).to.equal(2);
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
notifications.set('alerts', emberA());
|
|
|
|
await settled();
|
|
|
|
expect(find('.gh-alerts').children.length).to.equal(0);
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
it('triggers "notify" action when message count changes', async function () {
|
|
|
|
let notifications = this.owner.lookup('service:notifications');
|
2016-11-24 01:50:57 +03:00
|
|
|
let expectedCount = 0;
|
|
|
|
|
|
|
|
// test double for notify action
|
2018-01-05 18:38:23 +03:00
|
|
|
this.set('notify', count => expect(count).to.equal(expectedCount));
|
2016-11-24 01:50:57 +03:00
|
|
|
|
2019-01-02 12:58:55 +03:00
|
|
|
await render(hbs`{{gh-alerts notify=(action notify)}}`);
|
2016-11-24 01:50:57 +03:00
|
|
|
|
|
|
|
expectedCount = 3;
|
2019-01-02 12:58:55 +03:00
|
|
|
notifications.alerts.pushObject({message: 'Third', type: 'success'});
|
|
|
|
await settled();
|
2016-11-24 01:50:57 +03:00
|
|
|
|
|
|
|
expectedCount = 0;
|
2019-01-02 12:58:55 +03:00
|
|
|
notifications.set('alerts', emberA());
|
|
|
|
await settled();
|
2016-11-24 01:50:57 +03:00
|
|
|
});
|
|
|
|
});
|