2020-03-04 13:23:10 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
import Vuex from 'vuex';
|
|
|
|
|
2020-03-26 13:34:16 +00:00
|
|
|
import UsageAndChargesItem from '@/components/account/billing/estimatedCostsAndCredits/UsageAndChargesItem.vue';
|
2020-03-04 13:23:10 +00:00
|
|
|
|
|
|
|
import { makePaymentsModule } from '@/store/modules/payments';
|
|
|
|
import { makeProjectsModule } from '@/store/modules/projects';
|
2020-03-26 13:34:16 +00:00
|
|
|
import { ProjectUsageAndCharges } from '@/types/payments';
|
2020-03-04 13:23:10 +00:00
|
|
|
import { Project } from '@/types/projects';
|
|
|
|
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
|
|
|
|
|
|
|
import { PaymentsMock } from '../../../mock/api/payments';
|
|
|
|
import { ProjectsApiMock } from '../../../mock/api/projects';
|
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.filter('centsToDollars', (cents: number): string => {
|
|
|
|
return `USD $${(cents / 100).toFixed(2)}`;
|
|
|
|
});
|
|
|
|
localVue.use(Vuex);
|
|
|
|
|
|
|
|
const projectsApi = new ProjectsApiMock();
|
|
|
|
const projectsModule = makeProjectsModule(projectsApi);
|
|
|
|
const paymentsApi = new PaymentsMock();
|
|
|
|
const paymentsModule = makePaymentsModule(paymentsApi);
|
|
|
|
const store = new Vuex.Store({ modules: { projectsModule, paymentsModule }});
|
|
|
|
|
2020-05-22 14:37:25 +01:00
|
|
|
describe('UsageAndChargesItem', (): void => {
|
2020-03-04 13:23:10 +00:00
|
|
|
const project = new Project('id', 'projectName', 'projectDescription', 'test', 'testOwnerId', true);
|
|
|
|
projectsApi.setMockProjects([project]);
|
|
|
|
const date = new Date(Date.UTC(1970, 1, 1));
|
2020-03-26 13:34:16 +00:00
|
|
|
const projectCharge = new ProjectUsageAndCharges(date, date, 100, 100, 100, 'id', 100, 100, 100);
|
2020-03-04 13:23:10 +00:00
|
|
|
|
2020-05-22 14:37:25 +01:00
|
|
|
it('renders correctly', (): void => {
|
2020-03-26 13:34:16 +00:00
|
|
|
const wrapper = shallowMount(UsageAndChargesItem, {
|
2020-03-04 13:23:10 +00:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2020-05-22 14:37:25 +01:00
|
|
|
it('toggling dropdown works correctly', async (): Promise<void> => {
|
2020-03-26 13:34:16 +00:00
|
|
|
const wrapper = shallowMount(UsageAndChargesItem, {
|
2020-03-04 13:23:10 +00:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
propsData: {
|
|
|
|
item: projectCharge,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-03-26 13:34:16 +00:00
|
|
|
await wrapper.find('.usage-charges-item-container__summary').trigger('click');
|
2020-03-04 13:23:10 +00:00
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
|
2020-03-26 13:34:16 +00:00
|
|
|
await wrapper.find('.usage-charges-item-container__summary').trigger('click');
|
2020-03-04 13:23:10 +00:00
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|