Skip to content
Snippets Groups Projects
Commit b676a85a authored by Philip Dorsch's avatar Philip Dorsch
Browse files

Addes test for parentId after restore. Fixed wrong use of Object.assign().

parent 31db94c9
No related branches found
No related tags found
1 merge request!484Fix: project creation form saved values
Pipeline #1625829 passed
......@@ -224,7 +224,7 @@ export const testProjectForCreation: ProjectForCreation = {
keywords: [] as string[],
name: "Some Name",
principleInvestigators: "Prince Investigator",
grantId: "123",
grantId: "grant-123",
disciplines: [],
organizations: [],
visibility: {} as VisibilityForProjectManipulationDto,
......
......@@ -17,33 +17,31 @@ import CreateProject from "./CreateProject.vue";
/* Import of relevant mockup data */
import { testProjectForCreation } from "@/data/mockup/testProject";
import { warnDeprecation } from "@vue/compiler-dom";
describe("CreateProject.vue", () => {
/* Describe Pre-initialization steps */
/* Description of the test */
test("ParentId from project is not saved to local storage.", async () => {
/* Test Pre-initialization steps */
// Test Pre-initialization steps
/* Mount the Component */
// Mount the Component
const wrapper = mount(CreateProject, {
pinia: createTestingPinia({
createSpy: vitest.fn,
initialState: {
projectForCreation: testProjectForCreation,
},
}),
});
await wrapper.vm.$nextTick();
wrapper.vm.projectForCreation = testProjectForCreation;
wrapper.vm.projectForCreation = Object.assign({}, testProjectForCreation);
// Check initial state of parentId
expect(wrapper.vm.projectForCreation.parentId).toBeDefined();
await wrapper.vm.$nextTick();
// save to local storage
wrapper.vm.saveProjectForCreationLocalStorage();
await wrapper.vm.saveProjectForCreationLocalStorage();
await wrapper.vm.$nextTick();
......@@ -59,5 +57,43 @@ describe("CreateProject.vue", () => {
expect(projectJson).not.toBeNull();
expect(project).not.toBeNull();
expect(project.projectId).toBeUndefined();
wrapper.unmount();
});
test("ParentId from project is correct after load from local storage.", async () => {
/* Test Pre-initialization steps */
/* Mount the Component */
const wrapper = mount(CreateProject, {
pinia: createTestingPinia({
createSpy: vitest.fn,
}),
});
await wrapper.vm.$nextTick();
wrapper.vm.projectForCreation = Object.assign({}, testProjectForCreation);
await wrapper.vm.$nextTick();
// Check initial state of parentId
expect(wrapper.vm.projectForCreation.parentId).toBeDefined();
await wrapper.vm.$nextTick();
// save to local storage
await wrapper.vm.saveProjectForCreationLocalStorage();
await wrapper.vm.$nextTick();
// change parentId after save to the local storage
const testParentId = "123-abc-def-456";
wrapper.vm.projectForCreation.parentId = testParentId;
await wrapper.vm.$nextTick();
// load from local storage
await wrapper.vm.restoreProjectForCreationLocalStorage();
await wrapper.vm.$nextTick();
// check if set parentId is still the one we set
expect(wrapper.vm.projectForCreation.parentId).toBe(testParentId);
wrapper.unmount();
});
});
......@@ -205,7 +205,7 @@ export default defineComponent({
* Does not save the values for "parentId" and "copyOwnersFromParent".
*/
async saveProjectForCreationLocalStorage(): Promise<void> {
const projectCopy = Object.assign(this.projectForCreation, {});
const projectCopy = Object.assign({}, this.projectForCreation);
// remove the parentId and copyOwnersFromParent, as those could lead to problems when restoring with another project as parent.
projectCopy.parentId = undefined;
projectCopy.copyOwnersFromParent = undefined;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment