import selectors from '../../helpers/selectors.js';
import createNightmare from '../../helpers/nightmare';

describe('Item Create barcodes path', () => {
    const nightmare = createNightmare();

    beforeAll(() => {
        nightmare
            .loginAndModule('buyer', 'item')
            .accessToSearchResult('Ranged weapon longbow 2m')
            .accessToSection('item.card.itemBarcode');
    });

    it(`should click create a new code and delete a former one`, async() => {
        const result = await nightmare
            .waitToClick(selectors.itemBarcodes.firstCodeRemoveButton)
            .waitToClick(selectors.itemBarcodes.addBarcodeButton)
            .write(selectors.itemBarcodes.thirdCodeInput, '5')
            .waitToClick(selectors.itemBarcodes.submitBarcodesButton)
            .waitForLastSnackbar();

        expect(result).toEqual('Data saved!');
    });

    it(`should confirm the barcode 5 is created and it is now the third barcode as the first was deleted`, async() => {
        const result = await nightmare
            .reloadSection('item.card.itemBarcode')
            .waitForTextInInput(selectors.itemBarcodes.thirdCodeInput, '5')
            .waitToGetProperty(selectors.itemBarcodes.thirdCodeInput, 'value');

        expect(result).toEqual('5');
    });
});