storj/web/satellite/tests/unit/notifications/NotificationItem.spec.ts
Egon Elbre 8620532a05 web/satellite: bump dependencies
This contains also multiple fixes to make it work.
The following is a non-exhaustive list.

When @Prop default value is a callback, then it is called
instead of set verbatim. This means, when you want a default
value to be a callback, then it needs to be `default: () => () => X`.

jest does not yet properly support WebWorkers, hence the code introduces
an indirection to provide the worker URL.

This in turn required removing the global "store" dependency from
the tests. As a consequence the new NotificatorPlugin takes store
as a dependency. And many of the tests are adjusted to not import
store directly.

Moved StoreModule definition to avoid initializing the global store.

Some of the router code was moved into store. We can later figure out
how to structure it better and move it back.

bip39 needs explicit fallbacks for some of the dependencies.

Fixes to timer mocking. jest supports it natively.

Remove sinon dependency. jest provides all the functionality we need.

Change-Id: I7af3599390c63ce9f99dbd0b1e0870e9f8ca994d
2022-05-04 15:02:01 +00:00

148 lines
4.8 KiB
TypeScript

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
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 = 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);
});
});