From 367141a80d92fd83e0a2dbcf28bd9e565844d273 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 25 Aug 2023 12:33:38 +0200 Subject: [PATCH] refs #5673 test(CrudModel): add getChanges getDifferences front test --- src/components/CrudModel.vue | 24 +--- .../components/common/CrudModel.spec.js | 118 +++++++++++++++--- 2 files changed, 104 insertions(+), 38 deletions(-) diff --git a/src/components/CrudModel.vue b/src/components/CrudModel.vue index 17b21b0e6..98e2ff62f 100644 --- a/src/components/CrudModel.vue +++ b/src/components/CrudModel.vue @@ -149,17 +149,6 @@ async function insert() { hasChanges.value = true; } -// function addRemove(ids) { -// for (let id of ids) { -// const index = removed.value.indexOf(id); -// if (index > -1) { -// removed.value = removed.value.slice(index, 1); -// continue; -// } -// removed.value.push(id); -// } -// } - async function remove(data) { if (!data.length) return quasar.notify({ @@ -172,7 +161,6 @@ async function remove(data) { let preRemove = data.map((d) => (d[pk] ? null : d.$index)).filter(Boolean); let newData = formData.value; - // addRemove(ids); if (preRemove.length) { newData = newData.filter( (form) => !preRemove.some((index) => index == form.$index) @@ -202,12 +190,6 @@ async function remove(data) { emit('update:selected', []); } -watch(formUrl, async () => { - originalData.value = null; - reset(); - fetch(); -}); - function getChanges() { const updates = []; const creates = []; @@ -258,6 +240,12 @@ function isEmpty(obj) { if (obj.length > 0) return false; } + +watch(formUrl, async () => { + originalData.value = null; + reset(); + fetch(); +});