storj/web/satellite/tests/unit/notifications/NotificationItem.spec.ts

148 lines
4.8 KiB
TypeScript
Raw Normal View History

2019-01-24 20:15:10 +00:00
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
2019-09-09 11:33:39 +01:00
import Vuex from 'vuex';
import NotificationItem from '@/components/notifications/NotificationItem.vue';
2019-09-09 11:33:39 +01:00
import { makeNotificationsModule } from '@/store/modules/notifications';
2019-09-09 11:33:39 +01:00
import { DelayedNotification } from '@/types/DelayedNotification';
import { NOTIFICATION_ACTIONS } from '@/utils/constants/actionNames';
2019-09-09 11:33:39 +01:00
import { NOTIFICATION_TYPES } from '@/utils/constants/notification';
import { createLocalVue, mount } from '@vue/test-utils';
const localVue = createLocalVue();
localVue.use(Vuex);
const pauseSpy = jest.fn();
const resumeSpy = jest.fn();
const deleteSpy = jest.fn();
const notificationModule = makeNotificationsModule();
notificationModule.actions[NOTIFICATION_ACTIONS.PAUSE] = pauseSpy;
notificationModule.actions[NOTIFICATION_ACTIONS.RESUME] = resumeSpy;
notificationModule.actions[NOTIFICATION_ACTIONS.DELETE] = deleteSpy;
const store = new Vuex.Store(notificationModule);
describe('NotificationItem', () => {
it('renders correctly', () => {
const wrapper = mount(NotificationItem);
expect(wrapper).toMatchSnapshot();
});
it('renders correctly with success props', () => {
const testMessage = 'testMessage';
const wrapper = mount(NotificationItem, {
propsData: {
notification: new DelayedNotification(
jest.fn(),
NOTIFICATION_TYPES.SUCCESS,
testMessage,
),
},
});
expect(wrapper).toMatchSnapshot();
expect(wrapper.find('.notification-wrap__content-area__message').text()).toMatch(testMessage);
});
it('renders correctly with error props', () => {
const testMessage = 'testMessage';
const wrapper = mount(NotificationItem, {
propsData: {
notification: new DelayedNotification(
jest.fn(),
NOTIFICATION_TYPES.ERROR,
testMessage,
),
},
});
expect(wrapper).toMatchSnapshot();
expect(wrapper.find('.notification-wrap__content-area__message').text()).toMatch(testMessage);
});
it('renders correctly with notification props', () => {
const testMessage = 'testMessage';
const wrapper = mount(NotificationItem, {
propsData: {
notification: new DelayedNotification(
jest.fn(),
NOTIFICATION_TYPES.NOTIFICATION,
testMessage,
),
},
});
expect(wrapper).toMatchSnapshot();
expect(wrapper.find('.notification-wrap__content-area__message').text()).toMatch(testMessage);
});
it('renders correctly with warning props', () => {
const testMessage = 'testMessage';
const wrapper = mount(NotificationItem, {
propsData: {
notification: new DelayedNotification(
jest.fn(),
NOTIFICATION_TYPES.WARNING,
testMessage,
),
},
});
expect(wrapper).toMatchSnapshot();
expect(wrapper.find('.notification-wrap__content-area__message').text()).toMatch(testMessage);
});
it('renders correctly with support link', async (): Promise<void> => {
const testMessage = 'testMessage support rest of message';
const wrapper = mount(NotificationItem, {
propsData: {
notification: new DelayedNotification(
jest.fn(),
NOTIFICATION_TYPES.NOTIFICATION,
testMessage,
),
},
});
await wrapper.setData({ requestUrl: 'https://requestUrl.com' })
expect(wrapper).toMatchSnapshot();
expect(wrapper.find('.notification-wrap__content-area__message').text()).toMatch(testMessage);
expect(wrapper.find('.notification-wrap__content-area__link').text()).toBeTruthy();
});
it('trigger pause correctly', () => {
const wrapper = mount(NotificationItem, { store, localVue });
wrapper.find('.notification-wrap').trigger('mouseover');
expect(pauseSpy).toHaveBeenCalledTimes(1);
});
it('trigger resume correctly', () => {
const wrapper = mount(NotificationItem, { store, localVue });
wrapper.find('.notification-wrap').trigger('mouseover');
wrapper.find('.notification-wrap').trigger('mouseleave');
expect(resumeSpy).toHaveBeenCalledTimes(1);
});
it('trigger delete correctly', () => {
const wrapper = mount(NotificationItem, { store, localVue });
wrapper.find('.notification-wrap__buttons-group').trigger('click');
expect(deleteSpy).toHaveBeenCalledTimes(1);
});
});