Update check from new value instead of merging into old object
* Updating checks by merging the new object into the old creates
a bug where a property that's deleted in the new object, is still
preserved in the new object.
Fix this issue by updating checks by assigning the new value directly.
Change-Id: I7ed84eb84e287d88980098c9181f4316912c3c2f
diff --git a/gr-checks/gr-checks-view.js b/gr-checks/gr-checks-view.js
index f27eb11..135756f 100644
--- a/gr-checks/gr-checks-view.js
+++ b/gr-checks/gr-checks-view.js
@@ -243,10 +243,8 @@
},
/**
- * Merge new checks into old checks to maintain showCheckMessage
- * property
+ * Explicity add showCheckMessage to maintain it
* Loop over checks to make sure no new checks are missed
- * Merge new check object into prev check
* Remove any check that is not returned the next time
* Ensure message is updated
*/
@@ -257,7 +255,7 @@
c => c.checker_uuid === check.checker_uuid
);
if (!prevCheck) return Object.assign({}, check);
- return Object.assign({}, prevCheck, check,
+ return Object.assign({}, check,
{showCheckMessage: prevCheck.showCheckMessage});
});
},
diff --git a/gr-checks/gr-checks-view_test.html b/gr-checks/gr-checks-view_test.html
index 4fd7fdb..5316a30 100644
--- a/gr-checks/gr-checks-view_test.html
+++ b/gr-checks/gr-checks-view_test.html
@@ -318,6 +318,17 @@
element._checks[1].showCheckMessage = undefined;
});
+
+ test('url is not set if new check has no url', () => {
+ const NEW_CHECKS = [Object.assign({}, CHECK1),
+ Object.assign({}, CHECK2)];
+ delete NEW_CHECKS[0]['url'];
+ delete NEW_CHECKS[1]['url'];
+ const UPDATED_CHECKS = element._updateChecks(NEW_CHECKS);
+ assert.isNotOk(UPDATED_CHECKS[0].url);
+ assert.isNotOk(UPDATED_CHECKS[1].url);
+ });
+
test('message is not shown if new check has no message', () => {
const NEW_CHECKS = [Object.assign({}, CHECK1),
Object.assign({}, CHECK2)];