2020-03-18 17:07:29 +00:00
|
|
|
// Copyright (C) 2020 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
import Vuex from 'vuex';
|
|
|
|
|
2020-09-15 13:44:23 +01:00
|
|
|
import EditProjectDetails from '@/components/project/EditProjectDetails.vue';
|
2020-03-18 17:07:29 +00:00
|
|
|
|
|
|
|
import { makeProjectsModule, PROJECTS_MUTATIONS } from '@/store/modules/projects';
|
|
|
|
import { Project } from '@/types/projects';
|
|
|
|
import { NotificatorPlugin } from '@/utils/plugins/notificator';
|
|
|
|
import { createLocalVue, mount } from '@vue/test-utils';
|
|
|
|
|
|
|
|
import { ProjectsApiMock } from '../mock/api/projects';
|
|
|
|
|
|
|
|
const notificationPlugin = new NotificatorPlugin();
|
|
|
|
const localVue = createLocalVue();
|
|
|
|
|
|
|
|
localVue.use(Vuex);
|
|
|
|
localVue.use(notificationPlugin);
|
|
|
|
|
|
|
|
const projectsApi = new ProjectsApiMock();
|
|
|
|
const projectsModule = makeProjectsModule(projectsApi);
|
|
|
|
|
|
|
|
const store = new Vuex.Store({ modules: { projectsModule }});
|
|
|
|
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);
|
|
|
|
|
2020-09-15 13:44:23 +01:00
|
|
|
const wrapper = mount(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> => {
|
|
|
|
const wrapper = mount(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> => {
|
|
|
|
const wrapper = mount(EditProjectDetails, {
|
|
|
|
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
|
|
|
});
|
|
|
|
});
|