mirror of
https://github.com/finos/SymphonyElectron.git
synced 2024-11-29 04:03:59 -06:00
122 lines
4.3 KiB
TypeScript
122 lines
4.3 KiB
TypeScript
|
import { shallow } from 'enzyme';
|
||
|
import * as React from 'react';
|
||
|
import NotificationComp from '../src/renderer/components/notification-comp';
|
||
|
import { Themes } from '../src/renderer/components/notification-settings';
|
||
|
import { ipcRenderer } from './__mocks__/electron';
|
||
|
|
||
|
const IPC_RENDERER_NOTIFICATION_DATA_CHANNEL = 'notification-data';
|
||
|
describe('Toast notification component', () => {
|
||
|
const defaultProps = {
|
||
|
title: 'Oompa Loompa',
|
||
|
};
|
||
|
const spy = jest.spyOn(NotificationComp.prototype, 'setState');
|
||
|
let wrapper;
|
||
|
beforeEach(() => {
|
||
|
wrapper = shallow(React.createElement(NotificationComp));
|
||
|
});
|
||
|
|
||
|
it('should render correctly', () => {
|
||
|
ipcRenderer.send(IPC_RENDERER_NOTIFICATION_DATA_CHANNEL, defaultProps);
|
||
|
expect(spy).toBeCalledWith(defaultProps);
|
||
|
const container = wrapper.find('.title');
|
||
|
expect(container.text()).toBe(defaultProps.title);
|
||
|
});
|
||
|
|
||
|
it('should render Symphony logo if no image provided', () => {
|
||
|
const logo = '';
|
||
|
ipcRenderer.send(IPC_RENDERER_NOTIFICATION_DATA_CHANNEL, {
|
||
|
...defaultProps,
|
||
|
logo,
|
||
|
});
|
||
|
const defaultLogoContainer = wrapper.find('.default-logo');
|
||
|
expect(defaultLogoContainer).toBeTruthy();
|
||
|
const imageContainer = wrapper.find('.profile-picture');
|
||
|
expect(imageContainer.exists()).toBeFalsy();
|
||
|
});
|
||
|
|
||
|
it('should render Symphony logo if Symphony default image provided', () => {
|
||
|
const logo = './default.png';
|
||
|
ipcRenderer.send(IPC_RENDERER_NOTIFICATION_DATA_CHANNEL, {
|
||
|
...defaultProps,
|
||
|
logo,
|
||
|
});
|
||
|
const defaultLogoContainer = wrapper.find('.default-logo');
|
||
|
expect(defaultLogoContainer).toBeTruthy();
|
||
|
const imageContainer = wrapper.find('.profile-picture');
|
||
|
expect(imageContainer.exists()).toBeFalsy();
|
||
|
});
|
||
|
|
||
|
it('should flash in a custom way when theme is set', () => {
|
||
|
const flash = true;
|
||
|
const theme = Themes.DARK;
|
||
|
ipcRenderer.send(IPC_RENDERER_NOTIFICATION_DATA_CHANNEL, {
|
||
|
...defaultProps,
|
||
|
flash,
|
||
|
theme,
|
||
|
});
|
||
|
const flashingNotification = wrapper.find(`.${theme}-flashing`);
|
||
|
expect(flashingNotification.exists()).toBeTruthy();
|
||
|
});
|
||
|
|
||
|
it('should display ext badge when external', () => {
|
||
|
let externalBadge = wrapper.find('.ext-badge-container');
|
||
|
expect(externalBadge.exists()).toBeFalsy();
|
||
|
const isExternal = true;
|
||
|
ipcRenderer.send(IPC_RENDERER_NOTIFICATION_DATA_CHANNEL, {
|
||
|
...defaultProps,
|
||
|
isExternal,
|
||
|
});
|
||
|
externalBadge = wrapper.find('.ext-badge-container');
|
||
|
expect(externalBadge.exists()).toBeTruthy();
|
||
|
});
|
||
|
|
||
|
it('should flash as a mention when mention sent', () => {
|
||
|
const theme = Themes.DARK;
|
||
|
const flash = true;
|
||
|
const hasMention = true;
|
||
|
const themedMentionFlashing = `.${theme}-mention-flashing`;
|
||
|
let themedToastNotification = wrapper.find(themedMentionFlashing);
|
||
|
expect(themedToastNotification.exists()).toBeFalsy();
|
||
|
ipcRenderer.send(IPC_RENDERER_NOTIFICATION_DATA_CHANNEL, {
|
||
|
...defaultProps,
|
||
|
hasMention,
|
||
|
theme,
|
||
|
flash,
|
||
|
});
|
||
|
themedToastNotification = wrapper.find(themedMentionFlashing);
|
||
|
expect(themedToastNotification.exists()).toBeTruthy();
|
||
|
});
|
||
|
|
||
|
it('should flash as mention even if it is a message from an external user', () => {
|
||
|
const theme = Themes.DARK;
|
||
|
const isExternal = true;
|
||
|
const hasMention = true;
|
||
|
const flash = true;
|
||
|
const themedMentionFlashing = `.${theme}-ext-mention-flashing`;
|
||
|
let themedToastNotification = wrapper.find(themedMentionFlashing);
|
||
|
expect(themedToastNotification.exists()).toBeFalsy();
|
||
|
ipcRenderer.send(IPC_RENDERER_NOTIFICATION_DATA_CHANNEL, {
|
||
|
...defaultProps,
|
||
|
hasMention,
|
||
|
theme,
|
||
|
isExternal,
|
||
|
flash,
|
||
|
});
|
||
|
themedToastNotification = wrapper.find(themedMentionFlashing);
|
||
|
expect(themedToastNotification.exists()).toBeTruthy();
|
||
|
});
|
||
|
|
||
|
it('should display reply button when requested', () => {
|
||
|
const hasReply = true;
|
||
|
const replyButtonSelector = `.action-button`;
|
||
|
let toastNotificationReplyButton = wrapper.find(replyButtonSelector);
|
||
|
expect(toastNotificationReplyButton.exists()).toBeFalsy();
|
||
|
ipcRenderer.send(IPC_RENDERER_NOTIFICATION_DATA_CHANNEL, {
|
||
|
...defaultProps,
|
||
|
hasReply,
|
||
|
});
|
||
|
toastNotificationReplyButton = wrapper.find(replyButtonSelector);
|
||
|
expect(toastNotificationReplyButton.exists()).toBeTruthy();
|
||
|
});
|
||
|
});
|