salix-front/test/cypress/integration/entry/entryCard/entryBuys.spec.js

102 lines
3.9 KiB
JavaScript

import '../commands.js';
describe('EntryBuys', () => {
beforeEach(() => {
cy.viewport(1920, 1080);
cy.login('buyer');
cy.visit(`/#/entry/list`);
});
it('Edit buys and use toolbar actions', () => {
const COLORS = {
negative: 'rgb(251, 82, 82)',
positive: 'rgb(200, 228, 132)',
enabled: 'rgb(255, 255, 255)',
disable: 'rgb(168, 168, 168)',
};
const selectCell = (field, row = 0) =>
cy.get(`td[data-col-field="${field}"][data-row-index="${row}"]`);
const selectSpan = (field, row = 0) => selectCell(field, row).find('div > span');
const selectButton = (cySelector) => cy.get(`button[data-cy="${cySelector}"]`);
const clickAndType = (field, value, row = 0) => {
selectCell(field, row).click().type(`${value}{esc}`);
};
const checkText = (field, expectedText, row = 0) =>
selectCell(field, row).should('have.text', expectedText);
const checkColor = (field, expectedColor, row = 0) =>
selectSpan(field, row).should('have.css', 'color', expectedColor);
cy.createEntry();
createBuy();
selectCell('isIgnored').click().click().type('{esc}');
checkText('isIgnored', 'close');
clickAndType('stickers', '1');
checkText('stickers', '0/01');
checkText('quantity', '1');
checkText('amount', '50.00');
clickAndType('packing', '2');
checkText('packing', '12');
checkText('weight', '12.0');
checkText('quantity', '12');
checkText('amount', '600.00');
checkColor('packing', COLORS.enabled);
selectCell('groupingMode').click().click().click();
checkColor('packing', COLORS.disable);
checkColor('grouping', COLORS.enabled);
selectCell('buyingValue').click().clear().type('{backspace}{backspace}1');
checkText('amount', '12.00');
checkColor('minPrice', COLORS.disable);
selectCell('hasMinPrice').click().click();
checkColor('minPrice', COLORS.enabled);
selectCell('hasMinPrice').click();
cy.saveCard();
cy.get('span[data-cy="footer-stickers"]').should('have.text', '1');
cy.get('.q-notification__message').contains('Data saved');
selectButton('change-quantity-sign').should('be.disabled');
selectButton('check-buy-amount').should('be.disabled');
cy.get('tr.cursor-pointer > .q-table--col-auto-width > .q-checkbox').click();
selectButton('change-quantity-sign').should('be.enabled');
selectButton('check-buy-amount').should('be.enabled');
selectButton('change-quantity-sign').click();
selectButton('set-negative-quantity').click();
checkText('quantity', '-12');
selectButton('set-positive-quantity').click();
checkText('quantity', '12');
checkColor('amount', COLORS.disable);
selectButton('check-buy-amount').click();
selectButton('uncheck-amount').click();
checkColor('amount', COLORS.disable);
selectButton('check-amount').click();
checkColor('amount', COLORS.positive);
cy.saveCard();
cy.get('tbody > tr [tabindex="0"][role="checkbox"]').click();
cy.dataCy('transferBuys').should('be.enabled').click();
cy.dataCy('entryDestinyInput').should('be.visible').type('100');
cy.dataCy('transferBuysBtn').click();
cy.deleteEntry();
});
function createBuy() {
cy.waitForElement('[data-cy="entry-buys"]');
cy.get('a[data-cy="EntryBuys-menu-item"]').click();
cy.get('button[data-cy="vnTableCreateBtn"]').click();
cy.get('input[data-cy="itemFk-create-popup"]').type('1');
cy.get('div[role="listbox"] > div > div[role="option"]').eq(0).click();
cy.get('input[data-cy="Grouping mode_select"]').should('have.value', 'packing');
cy.get('button[data-cy="FormModelPopup_save"]').click();
}
});