/// <reference types="cypress" />

describe('InvoiceInCorrective', () => {
    const createRectificative = '.q-menu > .q-list > :nth-child(6) > .q-item__section';
    const rectificativeSection = '.q-drawer-container .q-list > a:nth-child(6)';
    const saveDialog = '.q-card > .q-card__actions > .q-btn--standard ';

    it('should create a correcting invoice', () => {
        cy.viewport(1280, 720);
        cy.login('developer');
        cy.visit(`/#/invoice-in/1/summary`);
        cy.intercept('POST', '/api/InvoiceIns/corrective').as('corrective');

        cy.openActionsDescriptor();

        cy.get(createRectificative).click();
        cy.get(saveDialog).click();
        cy.wait('@corrective').then((interception) => {
            const correctingId = interception.response.body;
            cy.url().should('include', `/invoice-in/${correctingId}/summary`);
        });
        cy.get(rectificativeSection).click();
        cy.get('tbody > tr:visible').should('have.length', 1);
    });
});