test: improve test
gitea/salix-front/pipeline/pr-master This commit looks good Details

This commit is contained in:
Javier Segarra 2025-02-19 23:42:10 +01:00
parent 874fbb48f5
commit b2184635d3
3 changed files with 213 additions and 116 deletions

View File

@ -46,7 +46,7 @@ defineExpose({ save });
</script> </script>
<template> <template>
<QPopupProxy ref="QPopupProxyRef"> <QPopupProxy ref="QPopupProxyRef" data-cy="ticketEditManaProxy">
<div class="container"> <div class="container">
<QSpinner v-if="!mana" color="primary" size="md" /> <QSpinner v-if="!mana" color="primary" size="md" />
<div v-else> <div v-else>

View File

@ -325,7 +325,11 @@ const changeDiscount = async (sale) => {
}; };
const updateDiscounts = async (sales, newDiscount = null) => { const updateDiscounts = async (sales, newDiscount = null) => {
const someSaleIsPrepared = await sales.some(isSalePrepared); const salesTracking = await fetchSalesTracking();
const someSaleIsPrepared = salesTracking.some((sale) =>
matchSale(salesTracking, sale),
);
if (someSaleIsPrepared) await confirmUpdate(() => updateDiscount(sales, newDiscount)); if (someSaleIsPrepared) await confirmUpdate(() => updateDiscount(sales, newDiscount));
else updateDiscount(sales, newDiscount); else updateDiscount(sales, newDiscount);
}; };
@ -484,7 +488,7 @@ const endNewRow = (row) => {
}; };
async function confirmUpdate(cb) { async function confirmUpdate(cb) {
quasar await quasar
.dialog({ .dialog({
component: VnConfirm, component: VnConfirm,
componentProps: { componentProps: {
@ -494,8 +498,7 @@ async function confirmUpdate(cb) {
}) })
.onOk(cb); .onOk(cb);
} }
async function fetchSalesTracking() {
async function isSalePrepared(sale) {
const filter = { const filter = {
params: { params: {
where: { ticketFk: route.params.id }, where: { ticketFk: route.params.id },
@ -507,12 +510,23 @@ async function isSalePrepared(sale) {
filter: JSON.stringify(filter), filter: JSON.stringify(filter),
}, },
}); });
return data;
}
async function isSalePrepared(sale) {
const data = await fetchSalesTracking();
return matchSale(data, sale);
}
function matchSale(data, sale) {
const matchingSale = data.find(({ itemFk }) => itemFk === sale.itemFk); const matchingSale = data.find(({ itemFk }) => itemFk === sale.itemFk);
if (!matchingSale) { if (!matchingSale) {
return false; return false;
} }
return isPrepared(matchingSale);
}
function isPrepared(sale) {
const flagsToCheck = [ const flagsToCheck = [
'hasSaleGroupDetail', 'hasSaleGroupDetail',
'isControled', 'isControled',
@ -520,12 +534,8 @@ async function isSalePrepared(sale) {
'isPrevious', 'isPrevious',
'isPreviousSelected', 'isPreviousSelected',
]; ];
if (flagsToCheck.some((flag) => matchingSale[flag] === 1)) { return flagsToCheck.some((flag) => sale[flag] === 1);
return true;
}
return false;
} }
watch( watch(
() => newRow.value.itemFk, () => newRow.value.itemFk,
(newItemFk) => { (newItemFk) => {
@ -802,6 +812,7 @@ watch(
</template> </template>
<template #column-quantity="{ row }"> <template #column-quantity="{ row }">
<VnInput <VnInput
data-cy="ticketSaleQuantityInput"
v-if="row.isNew || isTicketEditable" v-if="row.isNew || isTicketEditable"
type="number" type="number"
v-model.number="row.quantity" v-model.number="row.quantity"

View File

@ -1,122 +1,208 @@
/// <reference types="cypress" /> /// <reference types="cypress" />
describe('TicketSale', () => { describe('TicketSale', () => {
beforeEach(() => { describe('Free ticket #31', () => {
cy.login('developer'); beforeEach(() => {
cy.viewport(1920, 1080); cy.login('developer');
cy.visit('/#/ticket/31/sale'); cy.viewport(1920, 1080);
}); cy.visit('/#/ticket/31/sale');
const firstRow = 'tbody > :nth-child(1)';
const selectFirstRow = () => {
cy.waitForElement(firstRow);
cy.get(firstRow).find('.q-checkbox__inner').click();
};
it('it should add item to basket', () => {
cy.window().then((win) => {
cy.stub(win, 'open').as('windowOpen');
}); });
cy.dataCy('ticketSaleAddToBasketBtn').should('exist');
cy.dataCy('ticketSaleAddToBasketBtn').click();
cy.get('@windowOpen').should('be.calledWithMatch', /\/order\/\d+\/catalog/);
});
it('should send SMS', () => { const firstRow = 'tbody > :nth-child(1)';
selectFirstRow();
cy.dataCy('ticketSaleMoreActionsDropdown').click();
cy.waitForElement('[data-cy="sendShortageSMSItem"]');
cy.dataCy('sendShortageSMSItem').should('exist');
cy.dataCy('sendShortageSMSItem').click();
cy.dataCy('vnSmsDialog').should('exist');
cy.dataCy('sendSmsBtn').click();
cy.checkNotification('SMS sent');
});
it('should recalculate price when "Recalculate price" is clicked', () => { const selectFirstRow = () => {
cy.intercept('POST', '**/recalculatePrice').as('recalculatePrice'); cy.waitForElement(firstRow);
selectFirstRow(); cy.get(firstRow).find('.q-checkbox__inner').click();
cy.dataCy('ticketSaleMoreActionsDropdown').click(); };
cy.waitForElement('[data-cy="recalculatePriceItem"]');
cy.dataCy('recalculatePriceItem').should('exist');
cy.dataCy('recalculatePriceItem').click();
cy.wait('@recalculatePrice').its('response.statusCode').should('eq', 200);
cy.checkNotification('Data saved');
});
it('should update discount when "Update discount" is clicked', () => { it('it should add item to basket', () => {
selectFirstRow(); cy.window().then((win) => {
cy.dataCy('ticketSaleMoreActionsDropdown').click(); cy.stub(win, 'open').as('windowOpen');
cy.waitForElement('[data-cy="updateDiscountItem"]'); });
cy.dataCy('updateDiscountItem').should('exist'); cy.dataCy('ticketSaleAddToBasketBtn').should('exist');
cy.dataCy('updateDiscountItem').click(); cy.dataCy('ticketSaleAddToBasketBtn').click();
cy.waitForElement('[data-cy="ticketSaleDiscountInput"]'); cy.get('@windowOpen').should('be.calledWithMatch', /\/order\/\d+\/catalog/);
cy.dataCy('ticketSaleDiscountInput').find('input').focus(); });
cy.dataCy('ticketSaleDiscountInput').find('input').type('10');
cy.dataCy('saveManaBtn').click();
cy.waitForElement('.q-notification__message');
cy.checkNotification('Data saved');
});
it('adds claim', () => { it('should send SMS', () => {
selectFirstRow(); selectFirstRow();
cy.dataCy('ticketSaleMoreActionsDropdown').click(); cy.dataCy('ticketSaleMoreActionsDropdown').click();
cy.dataCy('createClaimItem').click(); cy.waitForElement('[data-cy="sendShortageSMSItem"]');
cy.dataCy('VnConfirm_confirm').click(); cy.dataCy('sendShortageSMSItem').should('exist');
cy.url().should('contain', 'claim/'); cy.dataCy('sendShortageSMSItem').click();
// Delete created claim to avoid cluttering the database cy.dataCy('vnSmsDialog').should('exist');
cy.dataCy('descriptor-more-opts').click(); cy.dataCy('sendSmsBtn').click();
cy.dataCy('deleteClaim').click(); cy.checkNotification('SMS sent');
cy.dataCy('VnConfirm_confirm').click(); });
cy.checkNotification('Data deleted');
});
it('marks row as reserved', () => { it('should recalculate price when "Recalculate price" is clicked', () => {
selectFirstRow(); cy.intercept('POST', '**/recalculatePrice').as('recalculatePrice');
cy.dataCy('ticketSaleMoreActionsDropdown').click(); selectFirstRow();
cy.waitForElement('[data-cy="markAsReservedItem"]'); cy.dataCy('ticketSaleMoreActionsDropdown').click();
cy.dataCy('markAsReservedItem').click(); cy.waitForElement('[data-cy="recalculatePriceItem"]');
cy.dataCy('ticketSaleReservedIcon').should('exist'); cy.dataCy('recalculatePriceItem').should('exist');
}); cy.dataCy('recalculatePriceItem').click();
cy.wait('@recalculatePrice').its('response.statusCode').should('eq', 200);
cy.checkNotification('Data saved');
});
it('unmarks row as reserved', () => { it('should update discount when "Update discount" is clicked', () => {
selectFirstRow(); selectFirstRow();
cy.dataCy('ticketSaleMoreActionsDropdown').click(); cy.dataCy('ticketSaleMoreActionsDropdown').click();
cy.waitForElement('[data-cy="unmarkAsReservedItem"]'); cy.waitForElement('[data-cy="updateDiscountItem"]');
cy.dataCy('unmarkAsReservedItem').click(); cy.dataCy('updateDiscountItem').should('exist');
cy.dataCy('ticketSaleReservedIcon').should('not.exist'); cy.dataCy('updateDiscountItem').click();
}); cy.waitForElement('[data-cy="ticketSaleDiscountInput"]');
cy.dataCy('ticketSaleDiscountInput').find('input').focus();
cy.dataCy('ticketSaleDiscountInput').find('input').type('10');
cy.dataCy('saveManaBtn').click();
cy.waitForElement('.q-notification__message');
cy.checkNotification('Data saved');
});
it('refunds row with warehouse', () => { it('adds claim', () => {
selectFirstRow(); selectFirstRow();
cy.dataCy('ticketSaleMoreActionsDropdown').click(); cy.dataCy('ticketSaleMoreActionsDropdown').click();
cy.dataCy('ticketSaleRefundItem').click(); cy.dataCy('createClaimItem').click();
cy.dataCy('ticketSaleRefundWithWarehouse').click(); cy.dataCy('VnConfirm_confirm').click();
cy.checkNotification('The following refund ticket have been created'); cy.url().should('contain', 'claim/');
}); // Delete created claim to avoid cluttering the database
cy.dataCy('descriptor-more-opts').click();
cy.dataCy('deleteClaim').click();
cy.dataCy('VnConfirm_confirm').click();
cy.checkNotification('Data deleted');
});
it('refunds row without warehouse', () => { it('marks row as reserved', () => {
selectFirstRow(); selectFirstRow();
cy.dataCy('ticketSaleMoreActionsDropdown').click(); cy.dataCy('ticketSaleMoreActionsDropdown').click();
cy.dataCy('ticketSaleRefundItem').click(); cy.waitForElement('[data-cy="markAsReservedItem"]');
cy.dataCy('ticketSaleRefundWithoutWarehouse').click(); cy.dataCy('markAsReservedItem').click();
cy.checkNotification('The following refund ticket have been created'); cy.dataCy('ticketSaleReservedIcon').should('exist');
}); });
it('transfer sale to a new ticket', () => { it('unmarks row as reserved', () => {
cy.visit('/#/ticket/32/sale'); selectFirstRow();
cy.get('.q-item > .q-item__label').should('have.text', ' #32'); cy.dataCy('ticketSaleMoreActionsDropdown').click();
selectFirstRow(); cy.waitForElement('[data-cy="unmarkAsReservedItem"]');
cy.dataCy('ticketSaleTransferBtn').click(); cy.dataCy('unmarkAsReservedItem').click();
cy.dataCy('ticketTransferPopup').should('exist'); cy.dataCy('ticketSaleReservedIcon').should('not.exist');
cy.dataCy('ticketTransferNewTicketBtn').click(); });
//check the new ticket has been created succesfully
cy.get('.q-item > .q-item__label').should('not.have.text', ' #32');
});
it('should redirect to ticket logs', () => { it('refunds row with warehouse', () => {
cy.get(firstRow).find('.q-btn:last').click(); selectFirstRow();
cy.url().should('match', /\/ticket\/31\/log/); cy.dataCy('ticketSaleMoreActionsDropdown').click();
cy.dataCy('ticketSaleRefundItem').click();
cy.dataCy('ticketSaleRefundWithWarehouse').click();
cy.checkNotification('The following refund ticket have been created');
});
it('refunds row without warehouse', () => {
selectFirstRow();
cy.dataCy('ticketSaleMoreActionsDropdown').click();
cy.dataCy('ticketSaleRefundItem').click();
cy.dataCy('ticketSaleRefundWithoutWarehouse').click();
cy.checkNotification('The following refund ticket have been created');
});
it('transfer sale to a new ticket', () => {
cy.visit('/#/ticket/32/sale');
cy.get('.q-item > .q-item__label').should('have.text', ' #32');
selectFirstRow();
cy.dataCy('ticketSaleTransferBtn').click();
cy.dataCy('ticketTransferPopup').should('exist');
cy.dataCy('ticketTransferNewTicketBtn').click();
//check the new ticket has been created succesfully
cy.get('.q-item > .q-item__label').should('not.have.text', ' #32');
});
it('should redirect to ticket logs', () => {
cy.get(firstRow).find('.q-btn:last').click();
cy.url().should('match', /\/ticket\/31\/log/);
});
});
describe.only('Ticket prepared #23', () => {
beforeEach(() => {
cy.login('developer');
cy.viewport(1920, 1080);
cy.visit('/#/ticket/23/sale');
});
const firstRow = 'tbody > :nth-child(1)';
const selectFirstRow = () => {
cy.waitForElement(firstRow);
cy.get(firstRow).find('.q-checkbox__inner').click();
};
it('update price', () => {
const price = Number((Math.random() * 99 + 1).toFixed(2));
cy.waitForElement(firstRow);
cy.get(':nth-child(10) > .q-btn').click();
cy.waitForElement('[data-cy="ticketEditManaProxy"]');
cy.dataCy('ticketEditManaProxy').should('exist');
cy.waitForElement('[data-cy="Price_input"]');
cy.dataCy('Price_input').clear();
cy.dataCy('Price_input').type(price);
cy.dataCy('saveManaBtn').click();
handleVnConfirm();
cy.get(':nth-child(10) > .q-btn > .q-btn__content').should(
'have.text',
`${price}`,
);
});
it('update dicount', () => {
const discount = Math.floor(Math.random() * 100) + 1;
selectFirstRow();
cy.get(':nth-child(11) > .q-btn').click();
cy.waitForElement('[data-cy="ticketEditManaProxy"]');
cy.dataCy('ticketEditManaProxy').should('exist');
cy.waitForElement('[data-cy="Disc_input"]');
cy.dataCy('Disc_input').clear();
cy.dataCy('Disc_input').type(discount);
cy.dataCy('saveManaBtn').click();
handleVnConfirm();
cy.get(':nth-child(11) > .q-btn > .q-btn__content').should(
'have.text',
`${discount}.00%`,
);
});
it('change concept', () => {
const quantity = Math.floor(Math.random() * 100) + 1;
cy.waitForElement(firstRow);
cy.get(':nth-child(8) > .row').click();
cy.get(
'.q-menu > [data-v-ca3f07a4=""] > .q-field > .q-field__inner > .q-field__control > .q-field__control-container > [data-cy="undefined_input"]',
)
.type(quantity)
.type('{enter}');
handleVnConfirm();
cy.get(':nth-child(8) >.row').should('contain.text', `${quantity}`);
});
it('changequantity ', () => {
const quantity = Math.floor(Math.random() * 100) + 1;
cy.waitForElement(firstRow);
cy.dataCy('ticketSaleQuantityInput').clear();
cy.dataCy('ticketSaleQuantityInput').type(quantity).trigger('tab');
cy.get('.q-page > :nth-child(6)').click();
handleVnConfirm();
cy.get('[data-cy="ticketSaleQuantityInput"]')
.find('[data-cy="undefined_input"]')
.should('have.value', `${quantity}`);
});
}); });
}); });
function handleVnConfirm() {
cy.get('[data-cy="VnConfirm_confirm"] > .q-btn__content > .block').click();
cy.waitForElement('.q-notification__message');
cy.get('.q-notification__message').should('be.visible');
cy.checkNotification('Data saved');
}