import selectors from '../../helpers/selectors.js'; import createNightmare from '../../helpers/nightmare'; describe('Item', () => { describe('Edit basic data path', () => { const nightmare = createNightmare(); beforeAll(() => { return nightmare .waitForLogin('buyer'); }); it('should access to the items index by clicking the items button', done => { return nightmare .click(selectors.moduleAccessView.itemsSectionButton) .wait(selectors.itemsIndex.createItemButton) .parsedUrl() .then(url => { expect(url.hash).toEqual('#!/item/index'); done(); }).catch(done.fail); }); it('should search for the item Gem of Mind', done => { return nightmare .wait(selectors.itemsIndex.searchResult) .type(selectors.itemsIndex.searchItemInput, 'Gem of Mind') .click(selectors.itemsIndex.searchButton) .waitForNumberOfElements(selectors.itemsIndex.searchResult, 1) .countElement(selectors.itemsIndex.searchResult) .then(result => { expect(result).toEqual(1); done(); }).catch(done.fail); }); it(`should click on the search result to access to the item basic data`, done => { return nightmare .waitForTextInElement(selectors.itemsIndex.searchResult, 'Gem of Mind') .waitToClick(selectors.itemsIndex.searchResult) .waitToClick(selectors.itemBasicData.basicDataButton) .waitForURL('data') .url() .then(url => { expect(url).toContain('data'); done(); }).catch(done.fail); }); it(`should edit the item basic data`, done => { return nightmare .clearInput(selectors.itemBasicData.nameInput) .type(selectors.itemBasicData.nameInput, 'Rose of Purity') .waitToClick(selectors.itemBasicData.typeSelect) .waitToClick(selectors.itemBasicData.typeSelectOptionThree) .waitToClick(selectors.itemBasicData.intrastatSelect) .waitToClick(selectors.itemBasicData.intrastatSelectOptionOne) .clearInput(selectors.itemBasicData.relevancyInput) .type(selectors.itemBasicData.relevancyInput, '1') .waitToClick(selectors.itemBasicData.originSelect) .waitToClick(selectors.itemBasicData.originSelectOptionTwo) .waitToClick(selectors.itemBasicData.expenceSelect) .waitToClick(selectors.itemBasicData.expenceSelectOptionThree) .clearInput(selectors.itemBasicData.longNameInput) .type(selectors.itemBasicData.longNameInput, 'RS Rose of Purity') .waitToClick(selectors.itemBasicData.isActiveCheckbox) .click(selectors.itemBasicData.submitBasicDataButton) .waitForLastSnackbar() .then(result => { expect(result).toEqual('Data saved!'); done(); }).catch(done.fail); }); it(`should confirm the item name was edited`, done => { return nightmare .click(selectors.itemNiches.nicheButton) .wait(selectors.itemNiches.firstWarehouseDisabled) .waitToClick(selectors.itemBasicData.basicDataButton) .waitForTextInInput(selectors.itemBasicData.nameInput, 'Rose of Purity') .getInputValue(selectors.itemBasicData.nameInput) .then(result => { expect(result).toEqual('Rose of Purity'); done(); }).catch(done.fail); }); it(`should confirm the item type was edited`, done => { return nightmare .getInputValue(selectors.itemBasicData.typeSelect) .then(result => { expect(result).toEqual('Crisantemo'); done(); }).catch(done.fail); }); it(`should confirm the item intrastad was edited`, done => { return nightmare .getInputValue(selectors.itemBasicData.intrastatSelect) .then(result => { expect(result).toEqual('Coral y materiales similares'); done(); }).catch(done.fail); }); it(`should confirm the item relevancy was edited`, done => { return nightmare .getInputValue(selectors.itemBasicData.relevancyInput) .then(result => { expect(result).toEqual('1'); done(); }).catch(done.fail); }); it(`should confirm the item origin was edited`, done => { return nightmare .getInputValue(selectors.itemBasicData.originSelect) .then(result => { expect(result).toEqual('Spain'); done(); }).catch(done.fail); }); it(`should confirm the item expence was edited`, done => { return nightmare .getInputValue(selectors.itemBasicData.expenceSelect) .then(result => { expect(result).toEqual('Adquisición mercancia Extracomunitaria'); done(); }).catch(done.fail); }); it(`should confirm the item long name was edited`, done => { return nightmare .getInputValue(selectors.itemBasicData.longNameInput) .then(result => { expect(result).toEqual('RS Rose of Purity'); done(); }).catch(done.fail); }); it('should confirm isActive checkbox is unchecked', done => { return nightmare .evaluate(selector => { return document.querySelector(selector).checked; }, selectors.itemBasicData.isActiveCheckbox) .then(value => { expect(value).toBeFalsy(); done(); }).catch(done.fail); }); }); });