/// <reference types="cypress" />
describe('InvoiceInBasicData', () => {
    const formInputs = '.q-form > .q-card input';
    const firstFormSelect = '.q-card > .vn-row:nth-child(1) > .q-select';
    const documentBtns = '[data-cy="dms-buttons"] button';
    const dialogInputs = '.q-dialog input';

    beforeEach(() => {
        cy.login('developer');
        cy.visit(`/#/invoice-in/1/basic-data`);
    });

    it('should edit the provideer and supplier ref', () => {
        cy.selectOption(firstFormSelect, 'Bros');
        cy.get('[title="Reset"]').click();
        cy.get(formInputs).eq(1).type('{selectall}4739');
        cy.saveCard();

        cy.get(`${firstFormSelect} input`).invoke('val').should('eq', 'Plants nick');
        cy.get(formInputs).eq(1).invoke('val').should('eq', '4739');
    });

    it('should edit, remove and create the dms data', () => {
        const firtsInput = 'Ticket:65';
        const secondInput = "I don't know what posting here!";

        //edit
        cy.get(documentBtns).eq(1).click();
        cy.get(dialogInputs).eq(0).type(`{selectall}${firtsInput}`);
        cy.get('textarea').type(`{selectall}${secondInput}`);
        cy.get('[data-cy="FormModelPopup_save"]').click();
        cy.get(documentBtns).eq(1).click();
        cy.get(dialogInputs).eq(0).invoke('val').should('eq', firtsInput);
        cy.get('textarea').invoke('val').should('eq', secondInput);
        cy.get('[data-cy="FormModelPopup_save"]').click();
        cy.checkNotification('Data saved');

        //remove
        cy.get(documentBtns).eq(2).click();
        cy.get('[data-cy="VnConfirm_confirm"]').click();
        cy.checkNotification('Data saved');

        //create
        cy.get('[data-cy="dms-create"]').eq(0).click();
        cy.get('[data-cy="VnDms_inputFile"').selectFile(
            'test/cypress/fixtures/image.jpg',
            {
                force: true,
            }
        );
        cy.get('[data-cy="FormModelPopup_save"]').click();
        cy.checkNotification('Data saved');
    });
});
