From 66d327a5520a9274d1c5a642be7f47c91833195c Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 24 Feb 2025 02:10:19 +0100 Subject: [PATCH] test: improve test --- src/pages/Ticket/Card/TicketSplit.vue | 4 +- src/pages/Ticket/Card/components/split.js | 33 ++- .../Negative/components/ChangeItemDialog.vue | 7 - .../components/ChangeQuantityDialog.vue | 28 +-- .../Negative/components/ChangeStateDialog.vue | 10 +- .../Negative/components/HandleSplitDialog.vue | 117 +++------ .../ticket/negative/TicketLackDetail.spec.js | 225 ++++++++++-------- 7 files changed, 185 insertions(+), 239 deletions(-) diff --git a/src/pages/Ticket/Card/TicketSplit.vue b/src/pages/Ticket/Card/TicketSplit.vue index e79057266..66ba3e9a6 100644 --- a/src/pages/Ticket/Card/TicketSplit.vue +++ b/src/pages/Ticket/Card/TicketSplit.vue @@ -2,7 +2,7 @@ import { ref } from 'vue'; import VnInputDate from 'src/components/common/VnInputDate.vue'; -import split from './components/split'; +import { splitTicket } from './components/split'; const emit = defineEmits(['ticketTransfered']); const $props = defineProps({ @@ -12,6 +12,8 @@ const $props = defineProps({ }, }); +const { split } = splitTicket(); + const splitDate = ref(Date.vnNew()); const splitSelectedRows = async () => { diff --git a/src/pages/Ticket/Card/components/split.js b/src/pages/Ticket/Card/components/split.js index feef6dbb1..7d3cd9ed8 100644 --- a/src/pages/Ticket/Card/components/split.js +++ b/src/pages/Ticket/Card/components/split.js @@ -1,25 +1,24 @@ import axios from 'axios'; -import notifyResults from 'src/utils/notifyResults'; import { showResultsAsTable } from 'src/composables/showResultsTable'; import HandleSplitDialog from 'src/pages/Ticket/Negative/components/HandleSplitDialog.vue'; -export default async function (data, date) { - const reducedData = data.reduce((acc, item) => { - const existing = acc.find(({ ticketFk }) => ticketFk === item.id); - if (existing) { - existing.sales.push(item.saleFk); - } else { - acc.push({ ticketFk: item.id, sales: [item.saleFk], date }); - } - return acc; - }, []); - - const promises = reducedData.map((params) => axios.post(`Tickets/split`, params)); +export function splitTicket() { const { openTable } = showResultsAsTable(); - const results = await Promise.allSettled(promises); - openTable(HandleSplitDialog, result, 'ticketFk', 'changeState'); + async function split(data, date) { + const reducedData = data.reduce((acc, item) => { + const existing = acc.find(({ ticketFk }) => ticketFk === item.ticketFk); + if (existing) { + existing.sales.push(item.saleFk); + } else { + acc.push({ ticketFk: item.ticketFk, sales: [item.saleFk], landed: date }); + } + return acc; + }, []); - notifyResults(results, 'ticketFk'); + const promises = reducedData.map((params) => axios.post(`Tickets/split`, params)); - return results; + const result = await Promise.allSettled(promises); + openTable(HandleSplitDialog, result, 'ticket', 'split'); + } + return { split }; } diff --git a/src/pages/Ticket/Negative/components/ChangeItemDialog.vue b/src/pages/Ticket/Negative/components/ChangeItemDialog.vue index bcba4caf0..1d8967ac0 100644 --- a/src/pages/Ticket/Negative/components/ChangeItemDialog.vue +++ b/src/pages/Ticket/Negative/components/ChangeItemDialog.vue @@ -1,18 +1,12 @@ diff --git a/src/pages/Ticket/Negative/components/ChangeStateDialog.vue b/src/pages/Ticket/Negative/components/ChangeStateDialog.vue index 8bf9bc730..ec9b9fcd1 100644 --- a/src/pages/Ticket/Negative/components/ChangeStateDialog.vue +++ b/src/pages/Ticket/Negative/components/ChangeStateDialog.vue @@ -5,7 +5,6 @@ import VnSelect from 'src/components/common/VnSelect.vue'; import FetchData from 'components/FetchData.vue'; import { showResultsAsTable } from 'src/composables/showResultsTable'; import HandleSplitDialog from './HandleSplitDialog.vue'; -// import notifyResults from 'src/utils/notifyResults'; const { openTable } = showResultsAsTable(); const emit = defineEmits(['update-state']); @@ -19,7 +18,6 @@ const $props = defineProps({ }, }); const updateState = async () => { - try { showChangeStateDialog.value = true; const rowsToUpdate = $props.selectedRows.map(({ ticketFk }) => axios.post(`Tickets/state`, { @@ -27,15 +25,11 @@ const updateState = async () => { code: newState.value, }), ); + const result = await Promise.allSettled(rowsToUpdate); + openTable(HandleSplitDialog, result, 'ticketFk', 'changeState'); - - // notifyResults(result, 'ticketFk'); - emit('update-state', newState.value); - } catch (err) { - return err; - } }; diff --git a/src/pages/Ticket/Negative/components/HandleSplitDialog.vue b/src/pages/Ticket/Negative/components/HandleSplitDialog.vue index 9aabc21e4..574ad8d76 100644 --- a/src/pages/Ticket/Negative/components/HandleSplitDialog.vue +++ b/src/pages/Ticket/Negative/components/HandleSplitDialog.vue @@ -6,7 +6,6 @@ import FetchData from 'components/FetchData.vue'; import ItemDescriptorProxy from 'src/pages/Item/Card/ItemDescriptorProxy.vue'; const { t } = useI18n(); -const newState = ref(null); const $props = defineProps({ results: { type: Array, @@ -25,10 +24,8 @@ const $props = defineProps({ default: '', }, }); -console.error($props.tag, 'results', $props.results); const results = ref($props.results); - -// const rowsSelected = ref([]); +const states = ref([]); const columns = computed(() => [ { @@ -44,30 +41,18 @@ const columns = computed(() => [ sortable: true, align: 'center', }, - // { - // name: 'newTicket', - // label: t('negative.split.newTicket'), - // field: ({ newTicket }) => newTicket, - // sortable: true, - // }, { name: 'statusText', label: t('negative.split.message'), sortable: true, align: 'center', }, - // { - // name: 'actions', - // align: 'center', - // label: t('negative.split.actions'), - // // style: 'padding-left: 100px', - // // headerStyle: 'padding-left: 100px', - // }, ]); -function handleMessage(value) { - const actions = { - changeState: {}, - }; +function getState(value) { + return states.value.find((state) => state.id === value)?.name; +} +function getTicketRejected(row) { + return JSON.parse(row.reason.config.data)?.ticketFk; } function getIcon(value) { const icons = { @@ -86,19 +71,17 @@ function getIcon(value) { }; return icons[value]; } - -const states = ref([]);