2020-03-18 17:07:29 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
import Vuex from 'vuex';
|
2022-09-29 00:51:19 +01:00
|
|
|
import { createLocalVue, shallowMount } from '@vue/test-utils';
|
2020-03-18 17:07:29 +00:00
|
|
|
|
2023-04-04 14:16:52 +01:00
|
|
|
import { ProjectsApiMock } from '@/../tests/unit/mock/api/projects';
|
2020-03-18 17:07:29 +00:00
|
|
|
import { makeProjectsModule, PROJECTS_MUTATIONS } from '@/store/modules/projects';
|
2021-08-02 23:06:15 +01:00
|
|
|
import { Project, ProjectLimits } from '@/types/projects';
|
2020-03-18 17:07:29 +00:00
|
|
|
import { NotificatorPlugin } from '@/utils/plugins/notificator';
|
2022-09-08 15:11:09 +01:00
|
|
|
import { makeNotificationsModule } from '@/store/modules/notifications';
|
2020-03-18 17:07:29 +00:00
|
|
|
|
2022-09-08 15:11:09 +01:00
|
|
|
import EditProjectDetails from '@/components/project/EditProjectDetails.vue';
|
2020-03-18 17:07:29 +00:00
|
|
|
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
localVue.use(Vuex);
|
|
|
|
|
2021-08-02 23:06:15 +01:00
|
|
|
const projectLimits = new ProjectLimits(1000, 100, 1000, 100);
|
2020-03-18 17:07:29 +00:00
|
|
|
const projectsApi = new ProjectsApiMock();
|
2021-08-02 23:06:15 +01:00
|
|
|
projectsApi.setMockLimits(projectLimits);
|
2020-03-18 17:07:29 +00:00
|
|
|
const projectsModule = makeProjectsModule(projectsApi);
|
2022-04-07 12:04:24 +01:00
|
|
|
const notificationsModule = makeNotificationsModule();
|
2020-03-18 17:07:29 +00:00
|
|
|
|
2021-10-14 15:29:45 +01:00
|
|
|
const store = new Vuex.Store({
|
|
|
|
modules: {
|
|
|
|
projectsModule,
|
2022-04-07 12:04:24 +01:00
|
|
|
notificationsModule,
|
2021-10-14 15:29:45 +01:00
|
|
|
usersModule: {
|
|
|
|
state: {
|
|
|
|
user: { paidTier: false },
|
2022-09-08 15:11:09 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
} });
|
2022-04-07 12:04:24 +01:00
|
|
|
|
|
|
|
localVue.use(new NotificatorPlugin(store));
|
|
|
|
|
2020-03-18 17:07:29 +00:00
|
|
|
const project = new Project('id', 'test', 'test', 'test', 'ownedId', false);
|
|
|
|
|
2020-09-15 13:44:23 +01:00
|
|
|
describe('EditProjectDetails.vue', () => {
|
2020-03-18 17:07:29 +00:00
|
|
|
it('renders correctly', (): void => {
|
|
|
|
store.commit(PROJECTS_MUTATIONS.ADD, project);
|
|
|
|
store.commit(PROJECTS_MUTATIONS.SELECT_PROJECT, project.id);
|
2021-08-02 23:06:15 +01:00
|
|
|
store.commit(PROJECTS_MUTATIONS.SET_LIMITS, projectLimits);
|
2020-03-18 17:07:29 +00:00
|
|
|
|
2022-09-29 00:51:19 +01:00
|
|
|
const wrapper = shallowMount<EditProjectDetails>(EditProjectDetails, {
|
2020-03-18 17:07:29 +00:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2020-09-15 13:44:23 +01:00
|
|
|
it('editing name works correctly', async (): Promise<void> => {
|
2022-09-29 00:51:19 +01:00
|
|
|
const wrapper = shallowMount<EditProjectDetails>(EditProjectDetails, {
|
2020-03-18 17:07:29 +00:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
2020-09-15 13:44:23 +01:00
|
|
|
await wrapper.vm.toggleNameEditing();
|
2020-03-18 17:07:29 +00:00
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
|
2020-09-15 13:44:23 +01:00
|
|
|
const newName = 'new name';
|
|
|
|
|
|
|
|
wrapper.vm.$data.nameValue = newName;
|
|
|
|
await wrapper.vm.onSaveNameButtonClick();
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
await expect(store.getters.selectedProject.name).toMatch(newName);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('editing description works correctly', async (): Promise<void> => {
|
2022-09-29 00:51:19 +01:00
|
|
|
const wrapper = shallowMount<EditProjectDetails>(EditProjectDetails, {
|
2020-09-15 13:44:23 +01:00
|
|
|
store,
|
|
|
|
localVue,
|
|
|
|
});
|
|
|
|
|
|
|
|
await wrapper.vm.toggleDescriptionEditing();
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
|
|
|
|
const newDescription = 'new description';
|
|
|
|
|
|
|
|
wrapper.vm.$data.descriptionValue = newDescription;
|
|
|
|
await wrapper.vm.onSaveDescriptionButtonClick();
|
2020-03-18 17:07:29 +00:00
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
2020-09-15 13:44:23 +01:00
|
|
|
await expect(store.getters.selectedProject.description).toMatch(newDescription);
|
2020-03-18 17:07:29 +00:00
|
|
|
});
|
|
|
|
});
|