salix-front/test/vitest/__tests__/composables/useArrayData.spec.js

32 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-04-08 14:38:36 +00:00
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',
});
2024-04-09 13:08:54 +00:00
// Mock the window.history.pushState method within useArrayData
2024-04-08 14:38:36 +00:00
window.history.pushState = (data, title, url) => (window.location.href = url);
2024-04-09 13:08:54 +00:00
// Mock the URL constructor within useArrayData
2024-04-08 14:38:36 +00:00
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');
});
});