storj/web/satellite/tests/unit/notifications/NotificationItem.spec.ts
NickolaiYurchenko 33b9d24c47 web/satellite: NotificationItem: support link added
link to support added if support mentioned in message

Change-Id: I9da5b869b2bfed39671b9c622e5262e2a80d0f09
2022-01-25 14:31:42 +00:00

149 lines
4.8 KiB
TypeScript

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
import sinon from 'sinon';
import Vuex from 'vuex';
import NotificationItem from '@/components/notifications/NotificationItem.vue';
import { makeNotificationsModule } from '@/store/modules/notifications';
import { DelayedNotification } from '@/types/DelayedNotification';
import { NOTIFICATION_ACTIONS } from '@/utils/constants/actionNames';
import { NOTIFICATION_TYPES } from '@/utils/constants/notification';
import { createLocalVue, mount } from '@vue/test-utils';
const localVue = createLocalVue();
localVue.use(Vuex);
const pauseSpy = sinon.spy();
const resumeSpy = sinon.spy();
const deleteSpy = sinon.spy();
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.callCount).toBe(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.callCount).toBe(1);
});
it('trigger delete correctly', () => {
const wrapper = mount(NotificationItem, { store, localVue });
wrapper.find('.notification-wrap__buttons-group').trigger('click');
expect(deleteSpy.callCount).toBe(1);
});
});