From c164c39a2d70f802c1b5440baf5bb61ef9475604 Mon Sep 17 00:00:00 2001 From: Jtubau Date: Thu, 12 Dec 2024 15:52:36 +0100 Subject: [PATCH 01/20] feat: refs #7050 7050 add test to isEmpty() --- .../components/common/CrudModel.spec.js | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/test/vitest/__tests__/components/common/CrudModel.spec.js b/test/vitest/__tests__/components/common/CrudModel.spec.js index 6ce93e59c..e8cf43473 100644 --- a/test/vitest/__tests__/components/common/CrudModel.spec.js +++ b/test/vitest/__tests__/components/common/CrudModel.spec.js @@ -1,5 +1,6 @@ import { createWrapper } from 'app/test/vitest/helper'; import CrudModel from 'components/CrudModel.vue'; +import c from 'croppie'; import { vi, afterEach, beforeEach, beforeAll, describe, expect, it } from 'vitest'; describe('CrudModel', () => { @@ -117,4 +118,47 @@ describe('CrudModel', () => { }); }); }); + + describe('isEmpty()', () => { + let dummyObj; + let dummyArray; + let result; + it('should return true if object si null', async () => { + dummyObj = null; + result = vm.isEmpty(dummyObj); + + expect(result).toBe(true); + }); + + it('should return true if object si undefined', async () => { + dummyObj = undefined; + result = vm.isEmpty(dummyObj); + + expect(result).toBe(true); + }); + + it('should return true if object is empty', async () => { + dummyObj ={}; + result = vm.isEmpty(dummyObj); + + expect(result).toBe(true); + + dummyArray = []; + result = vm.isEmpty(dummyArray); + + expect(result).toBe(true); + }); + + it('should return false if object is not empty', async () => { + dummyObj = {a:1, b:2, c:3}; + result = vm.isEmpty(dummyObj); + + expect(result).toBe(false); + + dummyArray = [1,2,3]; + result = vm.isEmpty(dummyArray); + + expect(result).toBe(false); + }) + }); }); From 77f4949ba6297c4a585bd60e7ac43f51f6852682 Mon Sep 17 00:00:00 2001 From: Jtubau Date: Thu, 12 Dec 2024 15:53:56 +0100 Subject: [PATCH 02/20] feat: refs #7050 7050 add object check --- src/components/CrudModel.vue | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/components/CrudModel.vue b/src/components/CrudModel.vue index 7fdb54bc4..cff18f2de 100644 --- a/src/components/CrudModel.vue +++ b/src/components/CrudModel.vue @@ -270,10 +270,8 @@ function getChanges() { function isEmpty(obj) { if (obj == null) return true; - if (obj === undefined) return true; - if (Object.keys(obj).length === 0) return true; - - if (obj.length > 0) return false; + if (Array.isArray(obj)) return !obj.length; + return Object.keys(obj).length === 0 ; } async function reload(params) { From 0706c9d58ed0c28ed38f58f20f83a0b91b0252ca Mon Sep 17 00:00:00 2001 From: Jtubau Date: Thu, 12 Dec 2024 16:04:57 +0100 Subject: [PATCH 03/20] fix: refs #7050 delete import added by mistake --- test/vitest/__tests__/components/common/CrudModel.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/vitest/__tests__/components/common/CrudModel.spec.js b/test/vitest/__tests__/components/common/CrudModel.spec.js index e8cf43473..2d7493cca 100644 --- a/test/vitest/__tests__/components/common/CrudModel.spec.js +++ b/test/vitest/__tests__/components/common/CrudModel.spec.js @@ -1,6 +1,5 @@ import { createWrapper } from 'app/test/vitest/helper'; import CrudModel from 'components/CrudModel.vue'; -import c from 'croppie'; import { vi, afterEach, beforeEach, beforeAll, describe, expect, it } from 'vitest'; describe('CrudModel', () => { From 35cef37d4f31f09e975e1ac023a9a666cfa282d9 Mon Sep 17 00:00:00 2001 From: Jon Date: Fri, 13 Dec 2024 08:04:05 +0100 Subject: [PATCH 04/20] fix: refs #8201 use arrayData to fix the error --- src/pages/Supplier/Card/SupplierDescriptor.vue | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pages/Supplier/Card/SupplierDescriptor.vue b/src/pages/Supplier/Card/SupplierDescriptor.vue index 28cfe49ce..9d469bcc1 100644 --- a/src/pages/Supplier/Card/SupplierDescriptor.vue +++ b/src/pages/Supplier/Card/SupplierDescriptor.vue @@ -9,7 +9,7 @@ import VnLv from 'src/components/ui/VnLv.vue'; import { toDateString } from 'src/filters'; import useCardDescription from 'src/composables/useCardDescription'; import { getUrl } from 'src/composables/getUrl'; -import { useState } from 'src/composables/useState'; +import { useArrayData } from 'src/composables/useArrayData'; const $props = defineProps({ id: { @@ -26,7 +26,7 @@ const $props = defineProps({ const route = useRoute(); const { t } = useI18n(); const url = ref(); -const state = useState(); +const arrayData = useArrayData(); const filter = { fields: [ @@ -77,7 +77,7 @@ const setData = (entity) => { data.value = useCardDescription(entity.ref, entity.id); }; -const supplier = computed(() => state.get('supplier')); +const supplier = computed(() => arrayData.store.data); const getEntryQueryParams = (supplier) => { if (!supplier) return null; @@ -127,6 +127,7 @@ const getEntryQueryParams = (supplier) => {