forked from verdnatura/salix-front
feat: refs #5919 test & set workerFk null.
This commit is contained in:
parent
7fd4c43b8b
commit
a692ca4a18
|
@ -12,6 +12,7 @@ import FetchData from 'components/FetchData.vue';
|
|||
const { hasAny } = useRole();
|
||||
const { t } = useI18n();
|
||||
const fetchData = ref();
|
||||
const originaLockerId = ref();
|
||||
const lockers = ref([]);
|
||||
const { store } = useArrayData('Worker');
|
||||
const entityId = computed(() => useRoute().params.id);
|
||||
|
@ -22,10 +23,17 @@ const filter = computed(() => ({
|
|||
},
|
||||
}));
|
||||
|
||||
const canEdit = () => hasAny(['productionBoss', 'hr']);
|
||||
const save = async (data) => {
|
||||
const lockerId = data.id ?? originaLockerId.value;
|
||||
const workerFk = lockerId == originaLockerId.value ? null : entityId.value;
|
||||
|
||||
const save = async (data) =>
|
||||
await axios.patch(`Lockers/${data.id}`, { workerFk: entityId.value });
|
||||
await axios.patch(`Lockers/${lockerId}`, { workerFk });
|
||||
};
|
||||
|
||||
const init = async (data) => {
|
||||
await fetchData.value.fetch();
|
||||
originaLockerId.value = data.id;
|
||||
};
|
||||
</script>
|
||||
<template>
|
||||
<FetchData
|
||||
|
@ -39,7 +47,7 @@ const save = async (data) =>
|
|||
model="worker"
|
||||
auto-load
|
||||
:save-fn="save"
|
||||
@on-fetch="() => canEdit() && fetchData.fetch()"
|
||||
@on-fetch="init"
|
||||
>
|
||||
<template #form="{ data }">
|
||||
<VnSelect
|
||||
|
@ -49,7 +57,7 @@ const save = async (data) =>
|
|||
option-label="code"
|
||||
option-value="id"
|
||||
hide-selected
|
||||
:readonly="!canEdit()"
|
||||
:readonly="!hasAny(['productionBoss', 'hr'])"
|
||||
/>
|
||||
</template>
|
||||
</FormModel>
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
describe('WorkerList', () => {
|
||||
const workerId = 1110;
|
||||
const lockerCode = '200A';
|
||||
const input = '.q-card input';
|
||||
const firstOpt = '[role="listbox"] .q-item:nth-child(1)';
|
||||
beforeEach(() => {
|
||||
cy.viewport(1280, 720);
|
||||
cy.login('productionBoss');
|
||||
cy.visit(`/#/worker/${workerId}/locker`);
|
||||
});
|
||||
|
||||
it('should allocates a locker', () => {
|
||||
cy.get(input).click();
|
||||
cy.get(input).type(lockerCode);
|
||||
cy.get(firstOpt).click();
|
||||
cy.saveCard();
|
||||
cy.get(input).invoke('val').should('eq', lockerCode);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue