Skip to content

Commit

Permalink
Merge pull request #4761 from marcellamaki/ensure-only-check-completi…
Browse files Browse the repository at this point in the history
…on-validation-from-edit-modal

Fix incorrectly marked "incomplete" exercises on exercise copy
  • Loading branch information
akolson committed Sep 27, 2024
2 parents ebeb110 + 4f00c52 commit 7bfe2ae
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
retryFailedCopy: withChangeTracker(function(changeTracker) {
this.updateContentNode({
id: this.nodeId,
checkComplete: true,
[COPYING_STATUS]: COPYING_STATUS_VALUES.COPYING,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -786,10 +786,12 @@
saveFromDiffTracker(id) {
if (this.diffTracker[id]) {
this.changed = true;
return this.updateContentNode({ id, ...this.diffTracker[id] }).then(() => {
delete this.diffTracker[id];
return this.changed;
});
return this.updateContentNode({ id, checkComplete: true, ...this.diffTracker[id] }).then(
() => {
delete this.diffTracker[id];
return this.changed;
}
);
}
return Promise.resolve(this.changed);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,11 @@
if (completeCheck !== node.complete) {
validationPromises.push(
vm.updateContentNode({ id: nodeId, complete: completeCheck })
vm.updateContentNode({
id: nodeId,
complete: completeCheck,
checkComplete: true,
})
);
}
});
Expand Down Expand Up @@ -578,7 +582,12 @@
inheritMetadata(metadata) {
const setMetadata = () => {
for (const nodeId of this.newNodeIds) {
this.updateContentNode({ id: nodeId, ...metadata, mergeMapFields: true });
this.updateContentNode({
id: nodeId,
...metadata,
mergeMapFields: true,
checkComplete: true,
});
}
this.newNodeIds = [];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe('contentNode actions', () => {
});
});
describe('updateContentNode action for an existing contentNode', () => {
it('should call ContentNode.update', () => {
it('should call ContentNode.update without complete if completeCheck is false', () => {
store.commit('contentNode/ADD_CONTENTNODE', {
id,
title: 'test',
Expand All @@ -125,6 +125,32 @@ describe('contentNode actions', () => {
language: 'no',
learning_activities: { test: true },
})
.then(() => {
expect(updateSpy).toHaveBeenCalledWith(id, {
title: 'notatest',
description: 'very',
language: 'no',
changed: true,
learning_activities: { test: true },
});
updateSpy.mockRestore();
});
});
it('should call ContentNode.update with complete false if completeCheck is true', () => {
store.commit('contentNode/ADD_CONTENTNODE', {
id,
title: 'test',
});
const updateSpy = jest.spyOn(ContentNode, 'update');
return store
.dispatch('contentNode/updateContentNode', {
id,
title: 'notatest',
description: 'very',
language: 'no',
learning_activities: { test: true },
checkComplete: true,
})
.then(() => {
expect(updateSpy).toHaveBeenCalledWith(id, {
title: 'notatest',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import flatMap from 'lodash/flatMap';
import uniq from 'lodash/uniq';
import isEmpty from 'lodash/isEmpty';
import { NEW_OBJECT, NOVALUE, DescendantsUpdatableFields } from 'shared/constants';
import client from 'shared/client';
import {
Expand Down Expand Up @@ -349,10 +350,16 @@ const mapFields = [
'tags',
];

export function updateContentNode(context, { id, mergeMapFields, ...payload } = {}) {
export function updateContentNode(
context,
{ id, mergeMapFields, checkComplete = false, ...payload } = {}
) {
if (!id) {
throw ReferenceError('id must be defined to update a contentNode');
}
if (isEmpty(payload)) {
return Promise.resolve();
}
let contentNodeData = generateContentNodeData(payload);

const node = context.getters.getContentNode(id);
Expand Down Expand Up @@ -421,19 +428,21 @@ export function updateContentNode(context, { id, mergeMapFields, ...payload } =
}
}

const newNode = {
...node,
...contentNodeData,
};
const complete = isNodeComplete({
nodeDetails: newNode,
assessmentItems: context.rootGetters['assessmentItem/getAssessmentItems'](id),
files: context.rootGetters['file/getContentNodeFiles'](id),
});
contentNodeData = {
...contentNodeData,
complete,
};
if (checkComplete) {
const newNode = {
...node,
...contentNodeData,
};
const complete = isNodeComplete({
nodeDetails: newNode,
assessmentItems: context.rootGetters['assessmentItem/getAssessmentItems'](id),
files: context.rootGetters['file/getContentNodeFiles'](id),
});
contentNodeData = {
...contentNodeData,
complete,
};
}

context.commit('ADD_CONTENTNODE', { id, ...contentNodeData });
return ContentNode.update(id, contentNodeData);
Expand Down

0 comments on commit 7bfe2ae

Please sign in to comment.