2020-06-10 12:42:44 +01:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
import { VNode } from 'vue';
|
|
|
|
import { DirectiveBinding } from 'vue/types/options';
|
|
|
|
|
2020-07-03 12:25:53 +01:00
|
|
|
import HistoryDropdown from '@/components/account/billing/HistoryDropdown.vue';
|
2020-06-10 12:42:44 +01:00
|
|
|
|
2020-09-15 18:05:26 +01:00
|
|
|
import { RouteConfig, router } from '@/router';
|
2020-06-10 12:42:44 +01:00
|
|
|
import { createLocalVue, mount } from '@vue/test-utils';
|
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
|
|
|
|
let clickOutsideEvent: EventListener;
|
|
|
|
|
|
|
|
localVue.directive('click-outside', {
|
|
|
|
bind: function (el: HTMLElement, binding: DirectiveBinding, vnode: VNode) {
|
|
|
|
clickOutsideEvent = function(event: Event): void {
|
|
|
|
if (el === event.target) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vnode.context) {
|
|
|
|
vnode.context[binding.expression](event);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
document.body.addEventListener('click', clickOutsideEvent);
|
|
|
|
},
|
|
|
|
unbind: function(): void {
|
|
|
|
document.body.removeEventListener('click', clickOutsideEvent);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-07-03 12:25:53 +01:00
|
|
|
describe('HistoryDropdown', (): void => {
|
|
|
|
it('renders correctly if credit history', (): void => {
|
|
|
|
const creditsHistory: string = RouteConfig.Account.with(RouteConfig.CreditsHistory).path;
|
|
|
|
const wrapper = mount(HistoryDropdown, {
|
2020-06-10 12:42:44 +01:00
|
|
|
localVue,
|
2020-07-03 12:25:53 +01:00
|
|
|
propsData: {
|
|
|
|
label: 'Credits History',
|
2020-09-15 18:05:26 +01:00
|
|
|
route: creditsHistory,
|
2020-07-03 12:25:53 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders correctly if balance history', (): void => {
|
|
|
|
const balanceHistory: string = RouteConfig.Account.with(RouteConfig.DepositHistory).path;
|
|
|
|
const wrapper = mount(HistoryDropdown, {
|
|
|
|
localVue,
|
|
|
|
propsData: {
|
|
|
|
label: 'Balance History',
|
2020-09-15 18:05:26 +01:00
|
|
|
route: balanceHistory,
|
2020-07-03 12:25:53 +01:00
|
|
|
},
|
2020-06-10 12:42:44 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2020-09-15 18:05:26 +01:00
|
|
|
it('click works correctly', async (): Promise<void> => {
|
|
|
|
const balanceHistory: string = RouteConfig.Account.with(RouteConfig.DepositHistory).path;
|
2020-07-03 12:25:53 +01:00
|
|
|
const wrapper = mount(HistoryDropdown, {
|
2020-06-10 12:42:44 +01:00
|
|
|
localVue,
|
2020-09-15 18:05:26 +01:00
|
|
|
propsData: {
|
|
|
|
label: 'Balance History',
|
|
|
|
route: balanceHistory,
|
2020-06-10 12:42:44 +01:00
|
|
|
},
|
2020-09-15 18:05:26 +01:00
|
|
|
router,
|
2020-06-10 12:42:44 +01:00
|
|
|
});
|
|
|
|
|
2020-07-03 12:25:53 +01:00
|
|
|
await wrapper.find('.history-dropdown__link-container').trigger('click');
|
2020-06-10 12:42:44 +01:00
|
|
|
|
2020-09-15 18:05:26 +01:00
|
|
|
expect(wrapper.vm.$route.name).toBe(RouteConfig.DepositHistory.name);
|
2020-06-10 12:42:44 +01:00
|
|
|
});
|
|
|
|
});
|