2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-12-12 13:44:01 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-08-21 14:21:23 +01:00
|
|
|
import { createLocalVue, mount, shallowMount } from '@vue/test-utils';
|
|
|
|
import Vuex from 'vuex';
|
|
|
|
import sinon from 'sinon';
|
2018-12-12 13:44:01 +00:00
|
|
|
import Notification from '@/components/notifications/Notification.vue';
|
|
|
|
import { NOTIFICATION_TYPES } from '@/utils/constants/notification';
|
2019-08-21 14:21:23 +01:00
|
|
|
import { DelayedNotification } from '@/types/DelayedNotification';
|
|
|
|
import { makeNotificationsModule } from '@/store/modules/notifications';
|
|
|
|
import { NOTIFICATION_ACTIONS } from '@/utils/constants/actionNames';
|
|
|
|
|
|
|
|
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);
|
2018-12-12 13:44:01 +00:00
|
|
|
|
|
|
|
describe('Notification.vue', () => {
|
2018-12-18 14:43:23 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
it('renders correctly', () => {
|
|
|
|
const wrapper = shallowMount(Notification);
|
2018-12-12 13:44:01 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
2018-12-12 13:44:01 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
it('renders correctly with props', () => {
|
|
|
|
const testMessage = 'testMessage';
|
2018-12-12 13:44:01 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
const wrapper = mount(Notification, {
|
|
|
|
propsData: {
|
2019-08-21 14:21:23 +01:00
|
|
|
notification: new DelayedNotification(
|
|
|
|
jest.fn(),
|
|
|
|
NOTIFICATION_TYPES.SUCCESS,
|
|
|
|
testMessage
|
|
|
|
)
|
2019-02-20 13:33:56 +00:00
|
|
|
},
|
|
|
|
});
|
2018-12-12 13:44:01 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
expect(wrapper.find('.notification-wrap__text').text()).toMatch(testMessage);
|
2018-12-12 13:44:01 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
wrapper.setProps({
|
2019-08-21 14:21:23 +01:00
|
|
|
notification: new DelayedNotification(
|
|
|
|
jest.fn(),
|
|
|
|
NOTIFICATION_TYPES.ERROR,
|
|
|
|
testMessage
|
|
|
|
)
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
|
|
|
|
wrapper.setProps({
|
|
|
|
notification: new DelayedNotification(
|
|
|
|
jest.fn(),
|
|
|
|
NOTIFICATION_TYPES.NOTIFICATION,
|
|
|
|
testMessage
|
|
|
|
)
|
2019-02-20 13:33:56 +00:00
|
|
|
});
|
2018-12-12 13:44:01 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
2018-12-12 13:44:01 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
wrapper.setProps({
|
2019-08-21 14:21:23 +01:00
|
|
|
notification: new DelayedNotification(
|
|
|
|
jest.fn(),
|
|
|
|
NOTIFICATION_TYPES.WARNING,
|
|
|
|
testMessage
|
|
|
|
)
|
2019-02-20 13:33:56 +00:00
|
|
|
});
|
2018-12-12 13:44:01 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
2019-08-21 14:21:23 +01:00
|
|
|
|
|
|
|
it('trigger pause correctly', () => {
|
|
|
|
const wrapper = shallowMount(Notification, { store, localVue });
|
|
|
|
|
|
|
|
wrapper.find('.notification-wrap').trigger('mouseover');
|
|
|
|
|
|
|
|
expect(pauseSpy.callCount).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('trigger resume correctly', () => {
|
|
|
|
const wrapper = shallowMount(Notification, { 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 = shallowMount(Notification, { store, localVue });
|
|
|
|
|
|
|
|
wrapper.find('.notification-wrap__buttons-group').trigger('click');
|
|
|
|
|
|
|
|
expect(deleteSpy.callCount).toBe(1);
|
|
|
|
});
|
2018-12-12 13:44:01 +00:00
|
|
|
});
|