0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-13 22:41:32 -05:00
ghost/core/client/tests/integration/components/gh-alerts-test.js
Kevin Ansfield 156260343b Avoid duplicate alerts, clear alerts on successful retry or sign-in
closes #5903, refs #5409
- switch alert/notification component tests from unit to integration where appropriate
- rename `notifications.closeAll` to `notifications.clearAll` to better represent it's behaviour
- add concept of a "key" to alerts/notifications and ability to close only specified keys through notifications service
- close duplicate alerts/notifications before showing a new one
- specify a key for all existing alerts
- close failure alerts on successful retries
- clear all currently displayed alerts on successful sign-in
2015-10-12 19:21:30 +01:00

56 lines
1.6 KiB
JavaScript

/* jshint expr:true */
import { expect } from 'chai';
import {
describeComponent,
it
} from 'ember-mocha';
import hbs from 'htmlbars-inline-precompile';
import Ember from 'ember';
const {run} = Ember,
notificationsStub = Ember.Service.extend({
alerts: Ember.A()
});
describeComponent(
'gh-alerts',
'Integration: Component: gh-alerts',
{
integration: true
},
function () {
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', Ember.A());
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', Ember.A());
});
}
);