2020-03-13 18:14:41 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
import Vuex from 'vuex';
|
2022-09-08 15:11:09 +01:00
|
|
|
import { createLocalVue, mount } from '@vue/test-utils';
|
2020-03-13 18:14:41 +00:00
|
|
|
|
2022-09-08 15:11:09 +01:00
|
|
|
import { PaymentsMock } from '../../../mock/api/payments';
|
|
|
|
import { ProjectsApiMock } from '../../../mock/api/projects';
|
|
|
|
import { UsersApiMock } from '../../../mock/api/users';
|
2020-03-13 18:14:41 +00:00
|
|
|
|
|
|
|
import { makePaymentsModule, PAYMENTS_MUTATIONS } from '@/store/modules/payments';
|
|
|
|
import { makeProjectsModule, PROJECTS_MUTATIONS } from '@/store/modules/projects';
|
|
|
|
import { makeUsersModule, USER_MUTATIONS } from '@/store/modules/users';
|
2020-05-12 18:16:04 +01:00
|
|
|
import { ProjectUsageAndCharges } from '@/types/payments';
|
2020-03-13 18:14:41 +00:00
|
|
|
import { Project } from '@/types/projects';
|
|
|
|
import { User } from '@/types/users';
|
|
|
|
|
2022-09-08 15:11:09 +01:00
|
|
|
import EstimatedCostsAndCredits from '@/components/account/billing/estimatedCostsAndCredits/EstimatedCostsAndCredits.vue';
|
2020-03-13 18:14:41 +00:00
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.filter('centsToDollars', (cents: number): string => {
|
|
|
|
return `USD $${(cents / 100).toFixed(2)}`;
|
|
|
|
});
|
|
|
|
localVue.use(Vuex);
|
|
|
|
|
|
|
|
const usersApi = new UsersApiMock();
|
|
|
|
const usersModule = makeUsersModule(usersApi);
|
|
|
|
const projectsApi = new ProjectsApiMock();
|
|
|
|
const projectsModule = makeProjectsModule(projectsApi);
|
|
|
|
const paymentsApi = new PaymentsMock();
|
|
|
|
const paymentsModule = makePaymentsModule(paymentsApi);
|
2022-09-08 15:11:09 +01:00
|
|
|
const store = new Vuex.Store({ modules: { usersModule, projectsModule, paymentsModule } });
|
2020-03-13 18:14:41 +00:00
|
|
|
|
2022-04-07 12:04:24 +01:00
|
|
|
const now = new Date(2020, 4, 1, 12 /* avoid timezone issues */, 1, 1, 1);
|
|
|
|
paymentsModule.state.startDate = now; // TODO: we shouldn't need to do this
|
|
|
|
paymentsModule.state.endDate = now;
|
|
|
|
|
2020-03-13 18:14:41 +00:00
|
|
|
const project = new Project('id', 'projectName', 'projectDescription', 'test', 'testOwnerId', true);
|
2020-05-22 14:37:25 +01:00
|
|
|
const project1 = new Project('id1', 'projectName1', 'projectDescription1', 'test', 'testOwnerId1', false);
|
2020-03-13 18:14:41 +00:00
|
|
|
const user = new User('testOwnerId');
|
|
|
|
const date = new Date(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-05-22 14:37:25 +01:00
|
|
|
const projectCharge1 = new ProjectUsageAndCharges(date, date, 100, 100, 100, 'id1', 100, 100, 100);
|
2020-03-26 13:34:16 +00:00
|
|
|
const {
|
|
|
|
SET_PROJECT_USAGE_AND_CHARGES,
|
|
|
|
SET_PRICE_SUMMARY,
|
|
|
|
} = PAYMENTS_MUTATIONS;
|
2020-03-13 18:14:41 +00:00
|
|
|
|
2020-05-22 14:37:25 +01:00
|
|
|
describe('EstimatedCostsAndCredits', (): void => {
|
|
|
|
beforeEach(() => {
|
2022-09-08 15:11:09 +01:00
|
|
|
jest.useFakeTimers('modern');
|
2022-04-07 12:04:24 +01:00
|
|
|
jest.setSystemTime(now);
|
|
|
|
});
|
|
|
|
afterAll(() => {
|
|
|
|
jest.useRealTimers();
|
2020-05-22 14:37:25 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders correctly with project and no project usage and charges', async (): Promise<void> => {
|
|
|
|
await store.commit(USER_MUTATIONS.SET_USER, user);
|
|
|
|
await store.commit(PROJECTS_MUTATIONS.ADD, project);
|
|
|
|
|
|
|
|
const wrapper = mount(EstimatedCostsAndCredits, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
2021-06-09 16:13:19 +01:00
|
|
|
await wrapper.setData({ isDataFetching: false });
|
|
|
|
|
2020-05-22 14:37:25 +01:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders correctly with project and project usage and charges', async (): Promise<void> => {
|
2021-06-09 16:13:19 +01:00
|
|
|
await store.commit(PROJECTS_MUTATIONS.ADD, project);
|
2020-05-22 14:37:25 +01:00
|
|
|
await store.commit(SET_PROJECT_USAGE_AND_CHARGES, [projectCharge]);
|
|
|
|
await store.commit(SET_PRICE_SUMMARY, [projectCharge]);
|
2020-03-13 18:14:41 +00:00
|
|
|
|
|
|
|
const wrapper = mount(EstimatedCostsAndCredits, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
2021-06-09 16:13:19 +01:00
|
|
|
await wrapper.setData({ isDataFetching: false });
|
|
|
|
|
2020-03-13 18:14:41 +00:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2020-05-22 14:37:25 +01:00
|
|
|
it('renders correctly with 2 projects and project usage and charges', async (): Promise<void> => {
|
2021-06-09 16:13:19 +01:00
|
|
|
await store.commit(PROJECTS_MUTATIONS.ADD, project);
|
2020-05-22 14:37:25 +01:00
|
|
|
await store.commit(PROJECTS_MUTATIONS.ADD, project1);
|
|
|
|
await store.commit(SET_PROJECT_USAGE_AND_CHARGES, [projectCharge, projectCharge1]);
|
|
|
|
await store.commit(SET_PRICE_SUMMARY, [projectCharge, projectCharge1]);
|
2020-03-26 13:34:16 +00:00
|
|
|
|
|
|
|
const wrapper = mount(EstimatedCostsAndCredits, {
|
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
2021-06-09 16:13:19 +01:00
|
|
|
await wrapper.setData({ isDataFetching: false });
|
|
|
|
|
2020-03-26 13:34:16 +00:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
2020-03-13 18:14:41 +00:00
|
|
|
});
|