2020-02-28 16:33:11 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
import Vuex from 'vuex';
|
|
|
|
|
|
|
|
import NewProjectArea from '@/components/header/NewProjectArea.vue';
|
|
|
|
|
2020-04-28 13:26:32 +01:00
|
|
|
import { router } from '@/router';
|
2020-02-28 16:33:11 +00:00
|
|
|
import { appStateModule } from '@/store/modules/appState';
|
|
|
|
import { makePaymentsModule, PAYMENTS_MUTATIONS } from '@/store/modules/payments';
|
2020-03-11 15:21:32 +00:00
|
|
|
import { makeProjectsModule, PROJECTS_MUTATIONS } from '@/store/modules/projects';
|
|
|
|
import { makeUsersModule, USER_MUTATIONS } from '@/store/modules/users';
|
2020-02-28 16:33:11 +00:00
|
|
|
import { APP_STATE_MUTATIONS } from '@/store/mutationConstants';
|
2020-05-12 18:16:04 +01:00
|
|
|
import {
|
|
|
|
AccountBalance,
|
|
|
|
BillingHistoryItem,
|
|
|
|
BillingHistoryItemStatus,
|
|
|
|
BillingHistoryItemType,
|
|
|
|
CreditCard,
|
|
|
|
} from '@/types/payments';
|
2020-03-11 15:21:32 +00:00
|
|
|
import { Project } from '@/types/projects';
|
2020-02-28 16:33:11 +00:00
|
|
|
import { User } from '@/types/users';
|
|
|
|
import { createLocalVue, mount } from '@vue/test-utils';
|
|
|
|
|
|
|
|
import { PaymentsMock } from '../../mock/api/payments';
|
|
|
|
import { ProjectsApiMock } from '../../mock/api/projects';
|
|
|
|
import { UsersApiMock } from '../../mock/api/users';
|
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
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);
|
|
|
|
|
|
|
|
const store = new Vuex.Store({ modules: { usersModule, projectsModule, paymentsModule, appStateModule }});
|
|
|
|
|
|
|
|
describe('NewProjectArea', () => {
|
|
|
|
it('renders correctly without projects and without payment methods', () => {
|
|
|
|
const wrapper = mount(NewProjectArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
2020-04-28 13:26:32 +01:00
|
|
|
router,
|
2020-02-28 16:33:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
2020-03-12 15:32:40 +00:00
|
|
|
expect(wrapper.findAll('.new-project-button-container').length).toBe(0); // user is unable to create project.
|
2020-02-28 16:33:11 +00:00
|
|
|
});
|
|
|
|
|
2020-03-11 15:21:32 +00:00
|
|
|
it('renders correctly without projects and with credit card', async () => {
|
2020-02-28 16:33:11 +00:00
|
|
|
const creditCard = new CreditCard('id', 1, 2000, 'test', '0000', true);
|
2020-03-11 15:21:32 +00:00
|
|
|
|
|
|
|
await store.commit(PAYMENTS_MUTATIONS.SET_CREDIT_CARDS, [creditCard]);
|
2020-02-28 16:33:11 +00:00
|
|
|
|
|
|
|
const wrapper = mount(NewProjectArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
2020-04-28 13:26:32 +01:00
|
|
|
router,
|
2020-02-28 16:33:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
2020-03-11 15:21:32 +00:00
|
|
|
expect(wrapper.findAll('.new-project-button-container').length).toBe(1);
|
2020-02-28 16:33:11 +00:00
|
|
|
|
|
|
|
await wrapper.find('.new-project-button-container').trigger('click');
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2020-03-11 15:21:32 +00:00
|
|
|
it('renders correctly without projects and with completed 50$ transaction', () => {
|
|
|
|
const billingTransactionItem = new BillingHistoryItem('itemId', 'test', 50, 50,
|
|
|
|
BillingHistoryItemStatus.Completed, 'test', new Date(), new Date(), BillingHistoryItemType.Transaction);
|
|
|
|
store.commit(PAYMENTS_MUTATIONS.CLEAR);
|
|
|
|
store.commit(PAYMENTS_MUTATIONS.SET_BILLING_HISTORY, [billingTransactionItem]);
|
2020-05-12 18:16:04 +01:00
|
|
|
store.commit(PAYMENTS_MUTATIONS.SET_BALANCE, new AccountBalance(0, 5000));
|
2020-03-11 15:21:32 +00:00
|
|
|
|
|
|
|
const wrapper = mount(NewProjectArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
2020-04-28 13:26:32 +01:00
|
|
|
router,
|
2020-03-11 15:21:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.findAll('.new-project-button-container').length).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('user is unable to create project with his project and with payment method', () => {
|
|
|
|
const user = new User('ownerId', 'test', 'test', 'test@test.test', 'test', 'test');
|
|
|
|
const project = new Project('id', 'test', 'test', 'test', 'ownerId', true);
|
2020-02-28 16:33:11 +00:00
|
|
|
store.commit(APP_STATE_MUTATIONS.TOGGLE_NEW_PROJECT_POPUP);
|
2020-03-11 15:21:32 +00:00
|
|
|
store.commit(USER_MUTATIONS.SET_USER, user);
|
|
|
|
store.commit(PROJECTS_MUTATIONS.SET_PROJECTS, [project]);
|
2020-02-28 16:33:11 +00:00
|
|
|
|
|
|
|
const wrapper = mount(NewProjectArea, {
|
|
|
|
store,
|
|
|
|
localVue,
|
2020-04-28 13:26:32 +01:00
|
|
|
router,
|
2020-02-28 16:33:11 +00:00
|
|
|
});
|
|
|
|
|
2020-03-11 15:21:32 +00:00
|
|
|
expect(wrapper.findAll('.new-project-button-container').length).toBe(0);
|
2020-02-28 16:33:11 +00:00
|
|
|
});
|
|
|
|
});
|