diff --git a/src/components/CrudModel.vue b/src/components/CrudModel.vue index 93a2ac96a..8c4f70f3b 100644 --- a/src/components/CrudModel.vue +++ b/src/components/CrudModel.vue @@ -184,8 +184,11 @@ async function saveChanges(data) { if ($props.beforeSaveFn) { changes = await $props.beforeSaveFn(changes, getChanges); } - try { + if (changes?.creates?.length === 0 && changes?.updates?.length === 0) { + return; + } + await axios.post($props.saveUrl || $props.url + '/crud', changes); } finally { isLoading.value = false; diff --git a/src/components/__tests__/CrudModel.spec.js b/src/components/__tests__/CrudModel.spec.js index e0afd30ad..f6c93e0d5 100644 --- a/src/components/__tests__/CrudModel.spec.js +++ b/src/components/__tests__/CrudModel.spec.js @@ -30,8 +30,8 @@ describe('CrudModel', () => { saveFn: '', }, }); - wrapper=wrapper.wrapper; - vm=wrapper.vm; + wrapper = wrapper.wrapper; + vm = wrapper.vm; }); beforeEach(() => { @@ -143,14 +143,14 @@ describe('CrudModel', () => { }); it('should return true if object is empty', async () => { - dummyObj ={}; - result = vm.isEmpty(dummyObj); + dummyObj = {}; + result = vm.isEmpty(dummyObj); expect(result).toBe(true); }); it('should return false if object is not empty', async () => { - dummyObj = {a:1, b:2, c:3}; + dummyObj = { a: 1, b: 2, c: 3 }; result = vm.isEmpty(dummyObj); expect(result).toBe(false); @@ -158,29 +158,31 @@ describe('CrudModel', () => { it('should return true if array is empty', async () => { dummyArray = []; - result = vm.isEmpty(dummyArray); + result = vm.isEmpty(dummyArray); expect(result).toBe(true); }); - + it('should return false if array is not empty', async () => { - dummyArray = [1,2,3]; + dummyArray = [1, 2, 3]; result = vm.isEmpty(dummyArray); expect(result).toBe(false); - }) + }); }); describe('resetData()', () => { it('should add $index to elements in data[] and sets originalData and formData with data', async () => { - data = [{ - name: 'Tony', - lastName: 'Stark', - age: 42, - }]; + data = [ + { + name: 'Tony', + lastName: 'Stark', + age: 42, + }, + ]; vm.resetData(data); - + expect(vm.originalData).toEqual(data); expect(vm.originalData[0].$index).toEqual(0); expect(vm.formData).toEqual(data); @@ -200,7 +202,7 @@ describe('CrudModel', () => { lastName: 'Stark', age: 42, }; - + vm.resetData(data); expect(vm.originalData).toEqual(data); @@ -210,17 +212,19 @@ describe('CrudModel', () => { }); describe('saveChanges()', () => { - data = [{ - name: 'Tony', - lastName: 'Stark', - age: 42, - }]; + data = [ + { + name: 'Tony', + lastName: 'Stark', + age: 42, + }, + ]; it('should call saveFn if exists', async () => { await wrapper.setProps({ saveFn: vi.fn() }); vm.saveChanges(data); - + expect(vm.saveFn).toHaveBeenCalledOnce(); expect(vm.isLoading).toBe(false); expect(vm.hasChanges).toBe(false); @@ -229,13 +233,15 @@ describe('CrudModel', () => { }); it("should use default url if there's not saveFn", async () => { - const postMock =vi.spyOn(axios, 'post'); - - vm.formData = [{ - name: 'Bruce', - lastName: 'Wayne', - age: 45, - }] + const postMock = vi.spyOn(axios, 'post'); + + vm.formData = [ + { + name: 'Bruce', + lastName: 'Wayne', + age: 45, + }, + ]; await vm.saveChanges(data); diff --git a/src/pages/Item/Card/ItemDiary.vue b/src/pages/Item/Card/ItemDiary.vue index 83cd562a0..f839c1f71 100644 --- a/src/pages/Item/Card/ItemDiary.vue +++ b/src/pages/Item/Card/ItemDiary.vue @@ -158,15 +158,10 @@ const getBadgeAttrs = (_date) => { const scrollToToday = async () => { await nextTick(); - const todayCell = document.querySelector(`td[data-date="${today.toISOString()}"]`); - if (todayCell) { - todayCell.scrollIntoView({ behavior: 'smooth', block: 'center' }); - } -}; - -const formatDateForAttribute = (dateValue) => { - if (dateValue instanceof Date) return date.formatDate(dateValue, 'YYYY-MM-DD'); - return dateValue; + const todayCell = document.querySelector( + `td[data-date="${date.formatDate(today, 'YYYY-MM-DD')}"]`, + ); + if (todayCell) todayCell.scrollIntoView({ behavior: 'smooth', block: 'center' }); }; async function updateWarehouse(warehouseFk) { @@ -242,7 +237,7 @@ async function updateWarehouse(warehouseFk) {