0
0
Fork 0

refactor: refs #7354 refactor zones section and fixed e2e tests

This commit is contained in:
Jon Elias 2024-08-13 14:39:50 +02:00
parent aefcfdba51
commit 0e9739f2a5
7 changed files with 39 additions and 58 deletions

View File

@ -168,10 +168,20 @@ function setUserParams(watchedParams, watchedOrder) {
watchedParams = { ...watchedParams, ...where }; watchedParams = { ...watchedParams, ...where };
delete watchedParams.filter; delete watchedParams.filter;
delete params.value?.filter; delete params.value?.filter;
params.value = { ...params.value, ...watchedParams }; params.value = { ...params.value, ...sanitizer(watchedParams) };
orders.value = parseOrder(order); orders.value = parseOrder(order);
} }
function sanitizer(params) {
for (const [key, value] of Object.entries(params)) {
if (typeof value == 'object') {
const param = Object.values(value)[0];
if (typeof param == 'string') params[key] = param.replaceAll('%', '');
}
}
return params;
}
function splitColumns(columns) { function splitColumns(columns) {
splittedColumns.value = { splittedColumns.value = {
columns: [], columns: [],

View File

@ -92,16 +92,18 @@ function setUserParams(watchedParams) {
const order = watchedParams.filter?.order; const order = watchedParams.filter?.order;
delete watchedParams.filter; delete watchedParams.filter;
userParams.value = { ...userParams.value, ...sanitizer(watchedParams) }; userParams.value = sanitizer(watchedParams);
emit('setUserParams', userParams.value, order); emit('setUserParams', userParams.value, order);
} }
watch( watch(
() => [route.query[$props.searchUrl], arrayData.store.userParams], () => route.query[$props.searchUrl],
([newSearchUrl, newUserParams], [oldSearchUrl, oldUserParams]) => { (val, oldValue) => (val || oldValue) && setUserParams(val)
if (newSearchUrl || oldSearchUrl) setUserParams(newSearchUrl); );
if (newUserParams || oldUserParams) setUserParams(newUserParams);
} watch(
() => arrayData.store.userParams,
(val, oldValue) => (val || oldValue) && setUserParams(val)
); );
watch( watch(

View File

@ -28,8 +28,10 @@ function notIsLocations(ifIsFalse, ifIsTrue) {
url: 'Zones', url: 'Zones',
label: notIsLocations(t('list.searchZone'), t('list.searchLocation')), label: notIsLocations(t('list.searchZone'), t('list.searchLocation')),
info: t('list.searchInfo'), info: t('list.searchInfo'),
whereFilter: notIsLocations((text) => { whereFilter: notIsLocations((value) => {
return { name: { like: `%${text}%` } }; return /^\d+$/.test(value)
? { id: value }
: { name: { like: `%${value}%` } };
}), }),
}" }"
/> />

View File

@ -19,24 +19,14 @@ const exprBuilder = (param, value) => {
agencyModeFk: value, agencyModeFk: value,
}; };
case 'search': case 'search':
if (value) { return /^\d+$/.test(value) ? { id: value } : { name: { like: `%${value}%` } };
if (!isNaN(value)) {
return { id: value };
} else {
return {
name: {
like: `%${value}%`,
},
};
}
}
} }
}; };
</script> </script>
<template> <template>
<VnSearchbar <VnSearchbar
data-key="ZoneList" data-key="Zones"
url="Zones" url="Zones"
:filter="{ :filter="{
include: { relation: 'agencyMode', scope: { fields: ['name'] } }, include: { relation: 'agencyMode', scope: { fields: ['name'] } },

View File

@ -15,9 +15,9 @@ import VnTable from 'src/components/VnTable/VnTable.vue';
import VnSelect from 'src/components/common/VnSelect.vue'; import VnSelect from 'src/components/common/VnSelect.vue';
import VnInput from 'src/components/common/VnInput.vue'; import VnInput from 'src/components/common/VnInput.vue';
import VnInputTime from 'src/components/common/VnInputTime.vue'; import VnInputTime from 'src/components/common/VnInputTime.vue';
import VnSearchbar from 'src/components/ui/VnSearchbar.vue';
import RightMenu from 'src/components/common/RightMenu.vue'; import RightMenu from 'src/components/common/RightMenu.vue';
import ZoneFilterPanel from './ZoneFilterPanel.vue'; import ZoneFilterPanel from './ZoneFilterPanel.vue';
import ZoneSearchbar from './Card/ZoneSearchbar.vue';
const { t } = useI18n(); const { t } = useI18n();
const router = useRouter(); const router = useRouter();
@ -39,17 +39,6 @@ const tableFilter = {
], ],
}; };
function exprBuilder(param, value) {
switch (param) {
case 'search':
return /^\d+$/.test(value) ? { id: value } : { name: { like: `%${value}%` } };
case 'name':
return { [param]: { like: `%${value}%` } };
case 'agencyModeFk':
return { [param]: value };
}
}
const columns = computed(() => [ const columns = computed(() => [
{ {
align: 'left', align: 'left',
@ -63,13 +52,16 @@ const columns = computed(() => [
inWhere: true, inWhere: true,
}, },
}, },
//TODO: acabar filtro name porque muestra [object Object]
{ {
align: 'left', align: 'left',
name: 'name', name: 'name',
label: t('list.name'), label: t('list.name'),
isTitle: true, isTitle: true,
create: true, create: true,
columnFilter: {
optionLabel: 'name',
optionValue: 'id',
},
}, },
{ {
align: 'left', align: 'left',
@ -138,20 +130,14 @@ const handleClone = (id) => {
); );
}; };
//TODO: la tabla no tiene en cuenta el menú de la izquierda, arreglar
onMounted(() => (stateStore.rightDrawer = true)); onMounted(() => (stateStore.rightDrawer = true));
</script> </script>
<template> <template>
<VnSearchbar <ZoneSearchbar />
data-key="Zones"
:label="t('Search zone')"
:info="t('You can search zones by id or name')"
:expr-builder="exprBuilder"
/>
<RightMenu> <RightMenu>
<template #right-panel> <template #right-panel>
<ZoneFilterPanel data-key="Zones" :expr-builder="exprBuilder" /> <ZoneFilterPanel data-key="Zones" />
</template> </template>
</RightMenu> </RightMenu>
<VnTable <VnTable
@ -168,7 +154,6 @@ onMounted(() => (stateStore.rightDrawer = true));
:columns="columns" :columns="columns"
redirect="zone" redirect="zone"
:right-search="false" :right-search="false"
:expr-builder="exprBuilder"
auto-load auto-load
> >
<template #more-create-dialog="{ data }"> <template #more-create-dialog="{ data }">

View File

@ -6,15 +6,6 @@ describe('ZoneCreate', () => {
Price: { val: '3' }, Price: { val: '3' },
Bonus: { val: '0' }, Bonus: { val: '0' },
'Traveling days': { val: '0' }, 'Traveling days': { val: '0' },
Close: {
val: {
h: '10',
m: '0',
x: 'PM',
},
type: 'time',
day: 11,
},
Warehouse: { val: 'Algemesi', type: 'select' }, Warehouse: { val: 'Algemesi', type: 'select' },
Volumetric: { val: 'true', type: 'checkbox' }, Volumetric: { val: 'true', type: 'checkbox' },
}; };
@ -30,6 +21,7 @@ describe('ZoneCreate', () => {
cy.fillInForm({ cy.fillInForm({
...data, ...data,
}); });
cy.get('input[aria-label="Close"]').type('1000');
cy.get('.q-mt-lg > .q-btn--standard').click(); cy.get('.q-mt-lg > .q-btn--standard').click();
cy.get(notification).should('contains.text', 'Agency cannot be blank'); cy.get(notification).should('contains.text', 'Agency cannot be blank');
}); });
@ -39,6 +31,7 @@ describe('ZoneCreate', () => {
...data, ...data,
Agency: { val: 'inhouse pickup', type: 'select' }, Agency: { val: 'inhouse pickup', type: 'select' },
}); });
cy.get('input[aria-label="Close"]').type('1000');
cy.get('.q-mt-lg > .q-btn--standard').click(); cy.get('.q-mt-lg > .q-btn--standard').click();
cy.get(notification).should('contains.text', 'Data created'); cy.get(notification).should('contains.text', 'Data created');
}); });

View File

@ -6,14 +6,13 @@ describe('ZoneList', () => {
}); });
it('should filter by agency', () => { it('should filter by agency', () => {
cy.get('.bg-header > :nth-child(3) > .full-width > :nth-child(1) >').type( cy.get(
'{downArrow}{enter}' ':nth-child(1) > .column > .q-field > .q-field__inner > .q-field__control > .q-field__control-container'
); ).type('{downArrow}{enter}');
}); });
it('should open the zone summary', () => { it('should open the zone summary', () => {
cy.get('.bg-header > :nth-child(2) > .full-width > :nth-child(1) >').type( cy.get('input[aria-label="Name"]').type('zone refund');
'zone refund{enter}' cy.get('.q-scrollarea__content > .q-btn--standard > .q-btn__content').click();
);
}); });
}); });