@@ -196,6 +182,7 @@ onMounted(() => {
:label="isNew ? t('globals.add') : t('globals.save')"
type="submit"
color="primary"
+ @click="onSubmit()"
/>
diff --git a/src/pages/Zone/Card/ZoneEventInclusionForm.vue b/src/pages/Zone/Card/ZoneEventInclusionForm.vue
index 8b1645426..b4096e5a2 100644
--- a/src/pages/Zone/Card/ZoneEventInclusionForm.vue
+++ b/src/pages/Zone/Card/ZoneEventInclusionForm.vue
@@ -57,45 +57,34 @@ const inclusionType = computed({
const arrayData = useArrayData('ZoneEvents');
const createEvent = async () => {
- try {
- eventInclusionFormData.value.weekDays = weekdayStore.toSet(
- eventInclusionFormData.value.wdays
+ eventInclusionFormData.value.weekDays = weekdayStore.toSet(
+ eventInclusionFormData.value.wdays
+ );
+
+ if (inclusionType.value == 'day') eventInclusionFormData.value.weekDays = '';
+ else eventInclusionFormData.value.dated = null;
+
+ if (inclusionType.value != 'range') {
+ eventInclusionFormData.value.started = null;
+ eventInclusionFormData.value.ended = null;
+ }
+
+ if (isNew.value)
+ await axios.post(`Zones/${route.params.id}/events`, eventInclusionFormData.value);
+ else
+ await axios.put(
+ `Zones/${route.params.id}/events/${props.event?.id}`,
+ eventInclusionFormData.value
);
- if (inclusionType.value == 'day') eventInclusionFormData.value.weekDays = '';
- else eventInclusionFormData.value.dated = null;
-
- if (inclusionType.value != 'range') {
- eventInclusionFormData.value.started = null;
- eventInclusionFormData.value.ended = null;
- }
-
- if (isNew.value)
- await axios.post(
- `Zones/${route.params.id}/events`,
- eventInclusionFormData.value
- );
- else
- await axios.put(
- `Zones/${route.params.id}/events/${props.event?.id}`,
- eventInclusionFormData.value
- );
-
- await refetchEvents();
- emit('onSubmit');
- } catch (err) {
- console.error('Error creating event', err);
- }
+ await refetchEvents();
+ emit('onSubmit');
};
const deleteEvent = async () => {
- try {
- if (!props.event) return;
- await axios.delete(`Zones/${route.params.id}/events/${props.event?.id}`);
- await refetchEvents();
- } catch (err) {
- console.error('Error deleting event: ', err);
- }
+ if (!props.event) return;
+ await axios.delete(`Zones/${route.params.id}/events/${props.event?.id}`);
+ await refetchEvents();
};
const closeForm = () => {
diff --git a/src/pages/Zone/Card/ZoneEventsPanel.vue b/src/pages/Zone/Card/ZoneEventsPanel.vue
index 55bc27ebe..4a030cbea 100644
--- a/src/pages/Zone/Card/ZoneEventsPanel.vue
+++ b/src/pages/Zone/Card/ZoneEventsPanel.vue
@@ -57,15 +57,11 @@ const arrayData = useArrayData('ZoneEvents', {
});
const fetchData = async () => {
- try {
- if (!params.value.zoneFk || !params.value.started || !params.value.ended) return;
+ if (!params.value.zoneFk || !params.value.started || !params.value.ended) return;
- await arrayData.applyFilter({
- params: params.value,
- });
- } catch (err) {
- console.error('Error fetching events: ', err);
- }
+ await arrayData.applyFilter({
+ params: params.value,
+ });
};
watch(
@@ -87,13 +83,9 @@ const formatWdays = (event) => {
};
const deleteEvent = async (id) => {
- try {
- if (!id) return;
- await axios.delete(`Zones/${route.params.id}/events/${id}`);
- await fetchData();
- } catch (err) {
- console.error('Error deleting event: ', err);
- }
+ if (!id) return;
+ await axios.delete(`Zones/${route.params.id}/events/${id}`);
+ await fetchData();
};
const openInclusionForm = (event) => {
diff --git a/src/pages/Zone/Card/ZoneLocations.vue b/src/pages/Zone/Card/ZoneLocations.vue
index 321748f00..08b99df60 100644
--- a/src/pages/Zone/Card/ZoneLocations.vue
+++ b/src/pages/Zone/Card/ZoneLocations.vue
@@ -10,13 +10,9 @@ const { t } = useI18n();
const route = useRoute();
const onSelected = async (val, node) => {
- try {
- if (val === null) val = undefined;
- const params = { geoId: node.id, isIncluded: val };
- await axios.post(`Zones/${route.params.id}/toggleIsIncluded`, params);
- } catch (err) {
- console.error('Error updating included', err);
- }
+ if (val === null) val = undefined;
+ const params = { geoId: node.id, isIncluded: val };
+ await axios.post(`Zones/${route.params.id}/toggleIsIncluded`, params);
};
diff --git a/src/pages/Zone/Card/ZoneLocationsTree.vue b/src/pages/Zone/Card/ZoneLocationsTree.vue
index 23a37ef7c..650047e40 100644
--- a/src/pages/Zone/Card/ZoneLocationsTree.vue
+++ b/src/pages/Zone/Card/ZoneLocationsTree.vue
@@ -38,6 +38,7 @@ const datakey = 'ZoneLocations';
const url = computed(() => `Zones/${route.params.id}/getLeaves`);
const arrayData = useArrayData(datakey, {
url: url.value,
+ limit: null,
});
const store = arrayData.store;
@@ -74,6 +75,7 @@ const onNodeExpanded = async (nodeKeysArray) => {
if (response.data) {
node.childs = response.data.map((n) => {
if (n.sons > 0) n.childs = [{}];
+ n.selected = isSelected(n.selected);
return n;
});
}
@@ -90,21 +92,16 @@ const onNodeExpanded = async (nodeKeysArray) => {
previousExpandedNodes.value = nodeKeysSet;
};
-const formatNodeSelected = (node) => {
- if (node.selected === 1) node.selected = true;
- else if (node.selected === 0) node.selected = false;
-
- if (node.sons > 0 && !node.childs) node.childs = [{}];
-};
-
const fetchNodeLeaves = async (nodeKey) => {
if (!treeRef.value) return;
const node = treeRef.value?.getNodeByKey(nodeKey);
- if (node.selected === 1) node.selected = true;
- else if (node.selected === 0) node.selected = false;
+ if (typeof node.selected === 'number') node.selected = !!node.selected;
+ if (node.sons > 0 && !node.childs) {
+ node.childs = [{}];
+ const index = expanded.value.indexOf(node.id);
+ expanded.value.splice(index, 1);
+ }
if (!node || node.sons === 0) return;
-
- state.set('Tree', node);
};
function getNodeIds(node) {
@@ -119,6 +116,10 @@ function getNodeIds(node) {
return ids;
}
+function isSelected(selected) {
+ if (typeof selected === 'number') return !!selected;
+}
+
watch(
() => store.data,
async (val) => {
@@ -128,18 +129,9 @@ watch(
nodes.value[0].childs = [...val];
const fetchedNodeKeys = val.flatMap(getNodeIds);
state.set('Tree', [...fetchedNodeKeys]);
-
- if (!store.userParams?.search) {
- val.forEach((n) => {
- formatNodeSelected(n);
- });
- store.data = null;
- expanded.value = [null];
- } else {
- for (let n of state.get('Tree')) {
- await fetchNodeLeaves(n);
- }
- expanded.value = [null, ...fetchedNodeKeys];
+ expanded.value = [null, ...fetchedNodeKeys];
+ for (let n of state.get('Tree')) {
+ await fetchNodeLeaves(n);
}
previousExpandedNodes.value = new Set(expanded.value);
},
@@ -147,13 +139,11 @@ watch(
);
const reFetch = async () => {
- const { data } = await arrayData.fetch({ append: false });
- nodes.value = data;
- expanded.value = [null];
+ await arrayData.fetch({});
};
onMounted(async () => {
- if (store.userParams?.search) await arrayData.fetch({});
+ await reFetch();
});
onUnmounted(() => {
@@ -167,13 +157,13 @@ onUnmounted(() => {
v-if="showSearchBar"
v-model="store.userParams.search"
:placeholder="$t('globals.search')"
- @update:model-value="reFetch()"
+ @keydown.enter.stop.prevent="reFetch"
>
-
+
{
- try {
- const { data } = params
- ? await arrayData.applyFilter({
- params,
- })
- : await arrayData.fetch({ append: false });
- if (!data.events || !data.events.length)
- notify(t('deliveryPanel.noEventsWarning'), 'warning');
- } catch (err) {
- console.error('Error fetching events: ', err);
- }
+ const { data } = params
+ ? await arrayData.applyFilter({
+ params,
+ })
+ : await arrayData.fetch({ append: false });
+ if (!data.events || !data.events.length)
+ notify(t('deliveryPanel.noEventsWarning'), 'warning');
};
const onSubmit = async () => {
diff --git a/test/cypress/integration/vnComponent/vnLocation.spec.js b/test/cypress/integration/vnComponent/vnLocation.spec.js
index aeb938c6f..c83befbe7 100644
--- a/test/cypress/integration/vnComponent/vnLocation.spec.js
+++ b/test/cypress/integration/vnComponent/vnLocation.spec.js
@@ -99,7 +99,7 @@ describe('VnLocation', () => {
});
it('Create postCode', () => {
- const postCode = '1234475';
+ const postCode = Math.floor(100000 + Math.random() * 900000);
const province = 'Valencia';
cy.get(createLocationButton).click();
cy.get('.q-card > h1').should('have.text', 'New postcode');
@@ -115,20 +115,68 @@ describe('VnLocation', () => {
checkVnLocation(postCode, province);
});
- it('Create city', () => {
- const postCode = '9011';
- const province = 'Saskatchew';
+
+ it('Create city without country', () => {
+ const cityName = 'Saskatchew'.concat(Math.random(1 * 100));
cy.get(createLocationButton).click();
- cy.get(dialogInputs).eq(0).type(postCode);
cy.get(
`${createForm.prefix} > :nth-child(4) > .q-select > ${createForm.sufix} > :nth-child(2) > .q-icon`
).click();
cy.selectOption('#q-portal--dialog--3 .q-select', 'one');
- cy.get('#q-portal--dialog--3 .q-input').type(province);
+ cy.get('#q-portal--dialog--3 .q-input').type(cityName);
cy.get('#q-portal--dialog--3 .q-btn--standard').click();
- cy.get('#q-portal--dialog--1 .q-btn--standard').click();
- cy.waitForElement('.q-form');
- checkVnLocation(postCode, province);
+ });
+
+ it('Create province without country', () => {
+ const provinceName = 'Saskatchew'.concat(Math.random(1 * 100));
+ cy.get(createLocationButton).click();
+ cy.get(
+ `${createForm.prefix} > :nth-child(5) > .q-select > ${createForm.sufix} > :nth-child(2) `
+ )
+ .eq(0)
+ .click();
+ cy.selectOption('#q-portal--dialog--3 .q-select', 'one');
+ cy.countSelectOptions('#q-portal--dialog--3 .q-select', 4);
+ cy.get('#q-portal--dialog--3 .q-input').type(provinceName);
+
+ cy.get('#q-portal--dialog--3 .q-btn--standard').click();
+ });
+
+ it('Create city with country', () => {
+ const cityName = 'Saskatchew'.concat(Math.random(1 * 100));
+ cy.get(createLocationButton).click();
+ cy.selectOption(
+ `${createForm.prefix} > :nth-child(5) > :nth-child(3) `,
+ 'Italia'
+ );
+ cy.get(
+ `${createForm.prefix} > :nth-child(4) > .q-select > ${createForm.sufix} > :nth-child(2) > .q-icon`
+ ).click();
+ cy.selectOption('#q-portal--dialog--4 .q-select', 'Province four');
+ cy.countSelectOptions('#q-portal--dialog--4 .q-select', 1);
+
+ cy.get('#q-portal--dialog--4 .q-input').type(cityName);
+ cy.get('#q-portal--dialog--4 .q-btn--standard').click();
+ });
+
+ it('Create province with country', () => {
+ const provinceName = 'Saskatchew'.concat(Math.random(1 * 100));
+ cy.get(createLocationButton).click();
+ cy.selectOption(
+ `${createForm.prefix} > :nth-child(5) > :nth-child(3) `,
+ 'España'
+ );
+ cy.get(
+ `${createForm.prefix} > :nth-child(5) > .q-select > ${createForm.sufix} > :nth-child(2) `
+ )
+ .eq(0)
+ .click();
+
+ cy.selectOption('#q-portal--dialog--4 .q-select', 'one');
+ cy.countSelectOptions('#q-portal--dialog--4 .q-select', 2);
+
+ cy.get('#q-portal--dialog--4 .q-input').type(provinceName);
+ cy.get('#q-portal--dialog--4 .q-btn--standard').click();
});
function checkVnLocation(postCode, province) {
diff --git a/test/cypress/support/commands.js b/test/cypress/support/commands.js
index 728342304..53f9d1d73 100755
--- a/test/cypress/support/commands.js
+++ b/test/cypress/support/commands.js
@@ -91,6 +91,11 @@ Cypress.Commands.add('selectOption', (selector, option) => {
cy.get(selector).click();
cy.get('.q-menu .q-item').contains(option).click();
});
+Cypress.Commands.add('countSelectOptions', (selector, option) => {
+ cy.waitForElement(selector);
+ cy.get(selector).click();
+ cy.get('.q-menu .q-item').should('have.length', option);
+});
Cypress.Commands.add('fillInForm', (obj, form = '.q-form > .q-card') => {
cy.waitForElement('.q-form > .q-card');
diff --git a/test/vitest/__tests__/composables/downloadFile.spec.js b/test/vitest/__tests__/composables/downloadFile.spec.js
index f611479bf..8d480fcef 100644
--- a/test/vitest/__tests__/composables/downloadFile.spec.js
+++ b/test/vitest/__tests__/composables/downloadFile.spec.js
@@ -1,25 +1,36 @@
-import { vi, describe, expect, it } from 'vitest';
+import { vi, describe, expect, it, beforeAll, afterAll } from 'vitest';
import { axios } from 'app/test/vitest/helper';
import { downloadFile } from 'src/composables/downloadFile';
import { useSession } from 'src/composables/useSession';
-
const session = useSession();
const token = session.getToken();
describe('downloadFile', () => {
+ const baseUrl = 'http://localhost:9000';
+ let defaulCreateObjectURL;
+
+ beforeAll(() => {
+ defaulCreateObjectURL = window.URL.createObjectURL;
+ window.URL.createObjectURL = vi.fn(() => 'blob:http://localhost:9000/blob-id');
+ });
+
+ afterAll(() => (window.URL.createObjectURL = defaulCreateObjectURL));
+
it('should open a new window to download the file', async () => {
- const url = 'http://localhost:9000';
-
- vi.spyOn(axios, 'get').mockResolvedValueOnce({ data: url });
-
- const mockWindowOpen = vi.spyOn(window, 'open');
+ const res = {
+ data: new Blob(['file content'], { type: 'application/octet-stream' }),
+ headers: { 'content-disposition': 'attachment; filename="test-file.txt"' },
+ };
+ vi.spyOn(axios, 'get').mockImplementation((url) => {
+ if (url == 'Urls/getUrl') return Promise.resolve({ data: baseUrl });
+ else if (url.includes('downloadFile')) return Promise.resolve(res);
+ });
await downloadFile(1);
- expect(mockWindowOpen).toHaveBeenCalledWith(
- `${url}/api/dms/1/downloadFile?access_token=${token}`
+ expect(axios.get).toHaveBeenCalledWith(
+ `${baseUrl}/dms/1/downloadFile?access_token=${token}`,
+ { responseType: 'blob' }
);
-
- mockWindowOpen.mockRestore();
});
});