import selectors from '../../helpers/selectors.js'; import createNightmare from '../../helpers/nightmare'; describe('Ticket Create packages path', () => { const nightmare = createNightmare(); beforeAll(() => { return nightmare .loginAndModule('employee', 'ticket') .accessToSearchResult('id:1') .accessToSection('ticket.card.package.index'); }); it(`should attempt create a new package but receive an error if package is blank`, async() => { const result = await nightmare .waitToClick(selectors.ticketPackages.firstRemovePackageButton) .waitToClick(selectors.ticketPackages.addPackageButton) .write(selectors.ticketPackages.firstQuantityInput, 99) .waitToClick(selectors.ticketPackages.savePackagesButton) .waitForLastSnackbar(); expect(result).toEqual('Package cannot be blank'); }); it(`should delete the first package and receive and error to save a new one with blank quantity`, async() => { const result = await nightmare .clearInput(selectors.ticketPackages.firstQuantityInput) .autocompleteSearch(selectors.ticketPackages.firstPackageAutocomplete, 'Container medical box 1m') .waitToClick(selectors.ticketPackages.savePackagesButton) .waitForLastSnackbar(); expect(result).toEqual('Some fields are invalid'); }); it(`should confirm the quantity input isn't invalid yet`, async() => { const result = await nightmare .evaluate(selector => { return document.querySelector(selector).checkValidity(); }, selectors.ticketPackages.firstQuantityInput); expect(result).toBeTruthy(); }); it(`should attempt create a new package but receive an error if the quantity is invalid`, async() => { const result = await nightmare .write(selectors.ticketPackages.firstQuantityInput, -99) .waitToClick(selectors.ticketPackages.savePackagesButton) .evaluate(selector => { return document.querySelector(selector).checkValidity(); }, selectors.ticketPackages.firstQuantityInput); expect(result).toBeFalsy(); }); it(`should create a new package with correct data`, async() => { const result = await nightmare .clearInput(selectors.ticketPackages.firstQuantityInput) .write(selectors.ticketPackages.firstQuantityInput, 99) .waitToClick(selectors.ticketPackages.savePackagesButton) .waitForLastSnackbar(); expect(result).toEqual('Data saved!'); }); it(`should confirm the first select is the expected one`, async() => { const result = await nightmare .reloadSection('ticket.card.package.index') .waitForTextInInput(`${selectors.ticketPackages.firstPackageAutocomplete} input`, 'Container medical box 1m') .waitToGetProperty(`${selectors.ticketPackages.firstPackageAutocomplete} input`, 'value'); expect(result).toEqual('7 : Container medical box 1m'); }); it(`should confirm the first quantity is just a number and the string part was ignored by the imput number`, async() => { const result = await nightmare .waitForTextInInput(selectors.ticketPackages.firstQuantityInput, '99') .waitToGetProperty(selectors.ticketPackages.firstQuantityInput, 'value'); expect(result).toEqual('99'); }); });