2019-08-31 20:51:14 -07:00
|
|
|
|
import { module, test } from 'qunit';
|
|
|
|
|
import { setupRenderingTest } from 'ember-qunit';
|
|
|
|
|
import { render } from '@ember/test-helpers';
|
|
|
|
|
import hbs from 'htmlbars-inline-precompile';
|
|
|
|
|
import { INotification } from '@datahub/utils/types/notifications/service';
|
|
|
|
|
import { NotificationEvent, NotificationType } from '@datahub/utils/constants/notifications';
|
2020-08-26 15:44:50 -07:00
|
|
|
|
import { noop } from 'lodash';
|
2019-08-31 20:51:14 -07:00
|
|
|
|
|
|
|
|
|
const toastBaseClass = '.notifications__toast';
|
|
|
|
|
const makeToast: (props?: { content?: string }) => INotification = (props = { content: 'Success!' }) => ({
|
|
|
|
|
props: {
|
|
|
|
|
type: NotificationEvent.success,
|
|
|
|
|
content: props.content
|
|
|
|
|
},
|
|
|
|
|
type: NotificationType.Toast,
|
|
|
|
|
notificationResolution: {
|
|
|
|
|
createPromiseToHandleThisNotification: () => Promise.resolve()
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2020-08-26 15:44:50 -07:00
|
|
|
|
module('Integration | Component | notifications-toast', function(hooks): void {
|
2019-08-31 20:51:14 -07:00
|
|
|
|
setupRenderingTest(hooks);
|
|
|
|
|
|
2020-08-26 15:44:50 -07:00
|
|
|
|
test('toast rendering', async function(assert): Promise<void> {
|
|
|
|
|
this.set('onDismiss', noop);
|
2019-08-31 20:51:14 -07:00
|
|
|
|
await render(hbs`<NotificationsToast @onDismiss={{this.onDismiss}}/>`);
|
|
|
|
|
|
|
|
|
|
assert.dom(toastBaseClass).exists();
|
|
|
|
|
assert.dom(`${toastBaseClass}__dismiss`).hasText('×');
|
|
|
|
|
|
|
|
|
|
await render(hbs`
|
|
|
|
|
<NotificationsToast @onDismiss={{this.onDismiss}} as |Toast|>
|
|
|
|
|
{{Toast.content}}
|
|
|
|
|
</NotificationsToast>`);
|
|
|
|
|
|
|
|
|
|
assert.dom(`${toastBaseClass}__content__msg`).exists();
|
|
|
|
|
});
|
|
|
|
|
|
2020-08-26 15:44:50 -07:00
|
|
|
|
test('toast property rendering', async function(assert): Promise<void> {
|
2019-08-31 20:51:14 -07:00
|
|
|
|
const fakeToast = makeToast();
|
|
|
|
|
const { content = '' } = fakeToast.props;
|
2020-08-26 15:44:50 -07:00
|
|
|
|
this.setProperties({ onDismiss: noop, toast: fakeToast });
|
2019-08-31 20:51:14 -07:00
|
|
|
|
await render(hbs`<NotificationsToast @onDismiss={{this.onDismiss}} @toast={{this.toast}}/>`);
|
|
|
|
|
|
|
|
|
|
assert.dom(`${toastBaseClass}__content--success`).exists();
|
|
|
|
|
assert.dom(`${toastBaseClass}__content__msg`).hasText(content);
|
|
|
|
|
});
|
|
|
|
|
|
2020-08-26 15:44:50 -07:00
|
|
|
|
test('toast content truncation and content detail', async function(assert): Promise<void> {
|
2019-08-31 20:51:14 -07:00
|
|
|
|
const fakeToast = makeToast({
|
|
|
|
|
content:
|
|
|
|
|
'A long string of text for user notification that contains more than the required number of characters to be displayed in a toast'
|
|
|
|
|
});
|
2020-08-26 15:44:50 -07:00
|
|
|
|
this.setProperties({ onDismiss: noop, toast: fakeToast });
|
2019-08-31 20:51:14 -07:00
|
|
|
|
await render(
|
|
|
|
|
hbs`<NotificationsToast @onDismiss={{this.onDismiss}} @toast={{this.toast}} @onShowDetail={{this.onDismiss}} />`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
assert
|
|
|
|
|
.dom(`${toastBaseClass}__content__msg`)
|
|
|
|
|
.hasText('A long string of text for user notification that...number of characters to be displayed in a toast');
|
|
|
|
|
|
|
|
|
|
assert.dom(`${toastBaseClass}__content-detail`).hasText('See Detail');
|
|
|
|
|
});
|
|
|
|
|
});
|