diff --git a/cypress.config.js b/cypress.config.js index 401c6c82d..e9aeb547a 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -12,7 +12,7 @@ module.exports = defineConfig({ supportFile: 'test/cypress/support/index.js', videosFolder: 'test/cypress/videos', video: false, - specPattern: 'test/cypress/integration/vnComponent/vnLocation.spec.js', + specPattern: 'test/cypress/integration/**/*.spec.js', experimentalRunAllSpecs: true, watchForFileChanges: true, reporter: 'cypress-mochawesome-reporter', diff --git a/src/components/CrudModel.vue b/src/components/CrudModel.vue index 5eba97dc8..a4713c078 100644 --- a/src/components/CrudModel.vue +++ b/src/components/CrudModel.vue @@ -10,6 +10,7 @@ import VnPaginate from 'components/ui/VnPaginate.vue'; import VnConfirm from 'components/ui/VnConfirm.vue'; import SkeletonTable from 'components/ui/SkeletonTable.vue'; import { tMobile } from 'src/composables/tMobile'; +import getDifferences from 'src/filters/getDifferences'; const { push } = useRouter(); const quasar = useQuasar(); @@ -267,28 +268,6 @@ function getChanges() { return changes; } -function getDifferences(obj1, obj2) { - let diff = {}; - delete obj1.$index; - delete obj2.$index; - - for (let key in obj1) { - if (obj2[key] && JSON.stringify(obj1[key]) !== JSON.stringify(obj2[key])) { - diff[key] = obj2[key]; - } - } - for (let key in obj2) { - if ( - obj1[key] === undefined || - JSON.stringify(obj1[key]) !== JSON.stringify(obj2[key]) - ) { - diff[key] = obj2[key]; - } - } - - return diff; -} - function isEmpty(obj) { if (obj == null) return true; if (obj === undefined) return true; diff --git a/src/components/FormModel.vue b/src/components/FormModel.vue index c668769e5..4504ea6ad 100644 --- a/src/components/FormModel.vue +++ b/src/components/FormModel.vue @@ -106,6 +106,7 @@ const originalData = ref({}); const formData = computed(() => state.get(modelValue)); const defaultButtons = computed(() => ({ save: { + dataCy: 'saveDefaultBtn', color: 'primary', icon: 'save', label: 'globals.save', @@ -113,6 +114,7 @@ const defaultButtons = computed(() => ({ type: 'submit', }, reset: { + dataCy: 'resetDefaultBtn', color: 'primary', icon: 'restart_alt', label: 'globals.reset', @@ -203,7 +205,9 @@ async function save() { isLoading.value = true; try { formData.value = trimData(formData.value); - const body = $props.mapper ? $props.mapper(formData.value) : formData.value; + const body = $props.mapper + ? $props.mapper(formData.value, originalData.value) + : formData.value; const method = $props.urlCreate ? 'post' : 'patch'; const url = $props.urlCreate || $props.urlUpdate || $props.url || arrayData.store.url; @@ -317,6 +321,7 @@ defineExpose({ :title="t(defaultButtons.reset.label)" /> { - emit('onSubmit'); - closeForm(); + if ($props.submitOnEnter) { + emit('onSubmit'); + closeForm(); + } }; const closeForm = () => { diff --git a/src/components/ui/VnNotes.vue b/src/components/ui/VnNotes.vue index dbcb2f3fe..bcbf0945e 100644 --- a/src/components/ui/VnNotes.vue +++ b/src/components/ui/VnNotes.vue @@ -101,6 +101,7 @@ onBeforeRouteLeave((to, from, next) => { @click="insert" class="q-mb-xs" dense + data-cy="saveNote" /> diff --git a/src/components/ui/VnPaginate.vue b/src/components/ui/VnPaginate.vue index b058dc642..f3f6d64f1 100644 --- a/src/components/ui/VnPaginate.vue +++ b/src/components/ui/VnPaginate.vue @@ -132,10 +132,24 @@ const addFilter = async (filter, params) => { async function fetch(params) { useArrayData(props.dataKey, params); - arrayData.reset(['filter.skip', 'skip']); + arrayData.reset(['filter.skip', 'skip', 'page']); await arrayData.fetch({ append: false }); - if (!store.hasMoreData) isLoading.value = false; + return emitStoreData(); +} +async function update(params) { + useArrayData(props.dataKey, params); + const { limit, skip } = store; + store.limit = limit + skip; + store.skip = 0; + await arrayData.fetch({ append: false }); + store.limit = limit; + store.skip = skip; + return emitStoreData(); +} + +function emitStoreData() { + if (!store.hasMoreData) isLoading.value = false; emit('onFetch', store.data); return store.data; } @@ -181,7 +195,7 @@ async function onLoad(index, done) { done(isDone); } -defineExpose({ fetch, addFilter, paginate }); +defineExpose({ fetch, update, addFilter, paginate });