storj/web/storagenode/tests/unit/components/payments/TotalPayoutArea.spec.ts
NickolaiYurchenko 9a627b22e8 web/storagenode: frontend refactoring
WHAT:
separation of domain and presentation entities

WHY:
to have ability to easily reuse logic

Change-Id: I48f7d1831c217dec999ff1b678034bb2c10cfbaa
2020-09-16 09:14:12 +00:00

61 lines
1.8 KiB
TypeScript

// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
import Vuex from 'vuex';
import TotalPayoutArea from '@/app/components/TotalPayoutArea.vue';
import { makePayoutModule, PAYOUT_MUTATIONS } from '@/app/store/modules/payout';
import { PayoutHttpApi } from '@/storagenode/api/payout';
import { Paystub, TotalHeldAndPaid } from '@/storagenode/payouts/payouts';
import { PayoutService } from '@/storagenode/payouts/service';
import { createLocalVue, shallowMount } from '@vue/test-utils';
const localVue = createLocalVue();
localVue.use(Vuex);
localVue.filter('centsToDollars', (cents: number): string => {
return `$${(cents / 100).toFixed(2)}`;
});
const payoutApi = new PayoutHttpApi();
const payoutService = new PayoutService(payoutApi);
const payoutModule = makePayoutModule(payoutApi, payoutService);
const store = new Vuex.Store({ modules: { payoutModule }});
describe('TotalPayoutArea', (): void => {
it('renders correctly', (): void => {
const wrapper = shallowMount(TotalPayoutArea, {
store,
localVue,
});
expect(wrapper).toMatchSnapshot();
});
it('renders correctly with actual values', async (): Promise<void> => {
const wrapper = shallowMount(TotalPayoutArea, {
store,
localVue,
});
const paystub = new Paystub();
paystub.held = 600000;
paystub.disposed = 100000;
paystub.paid = 1000000;
const totalHeldAndPaid = new TotalHeldAndPaid([paystub]);
totalHeldAndPaid.setCurrentMonthEarnings(40000);
await store.commit(PAYOUT_MUTATIONS.SET_TOTAL, totalHeldAndPaid);
expect(wrapper).toMatchSnapshot();
totalHeldAndPaid.held = 400000;
await store.commit(PAYOUT_MUTATIONS.SET_TOTAL, totalHeldAndPaid);
expect(wrapper).toMatchSnapshot();
});
});