diff --git a/src/composables/useArrayData.js b/src/composables/useArrayData.js index 403683415..a212cb744 100644 --- a/src/composables/useArrayData.js +++ b/src/composables/useArrayData.js @@ -196,7 +196,7 @@ export function useArrayData(key, userOptions) { for (const param in query) params.append(param, query[param]); url.hash = currentRoute + '?' + params.toString(); - window.history.pushState({}, '', url); + window.history.pushState({}, '', url.hash); } const totalRows = computed(() => (store.data && store.data.length) || 0); diff --git a/test/vitest/__tests__/composables/useArrayData.spec.js b/test/vitest/__tests__/composables/useArrayData.spec.js new file mode 100644 index 000000000..09bfc256f --- /dev/null +++ b/test/vitest/__tests__/composables/useArrayData.spec.js @@ -0,0 +1,27 @@ +import { describe, expect, it, beforeAll } from 'vitest'; +import { axios } from 'app/test/vitest/helper'; +import { useArrayData } from 'composables/useArrayData'; + +describe('useArrayData', () => { + let arrayData; + beforeAll(() => { + axios.get.mockResolvedValue({ data: [] }); + arrayData = useArrayData('InvoiceIn', { url: 'invoice-in/list' }); + Object.defineProperty(window.location, 'href', { + writable: true, + value: 'localhost:9000/invoice-in/list', + }); + window.history.pushState = (data, title, url) => (window.location.href = url); + global.URL = class URL { + constructor(url) { + this.hash = url.split('localhost:9000/')[1]; + } + }; + }); + + it('should add the params to the url', async () => { + arrayData.store.userParams = { supplierFk: 2 }; + arrayData.updateStateParams(); + expect(window.location.href).contain('params=%7B%22supplierFk%22%3A2%7D'); + }); +});