import selectors from '../../helpers/selectors.js'; import createNightmare from '../../helpers/nightmare'; describe('Item', () => { const nightmare = createNightmare(); describe('Create path', () => { 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 Infinity Gauntlet to confirm it isn't created yet`, done => { return nightmare .wait(selectors.itemsIndex.searchResult) .type(selectors.itemsIndex.searchItemInput, 'Infinity Gauntlet') .click(selectors.itemsIndex.searchButton) .waitForNumberOfElements(selectors.itemsIndex.searchResult, 0) .countElement(selectors.itemsIndex.searchResult) .then(result => { expect(result).toEqual(0); done(); }).catch(done.fail); }); it('should access to the create item view by clicking the create floating button', done => { return nightmare .click(selectors.itemsIndex.createItemButton) .wait(selectors.itemCreateView.createButton) .parsedUrl() .then(url => { expect(url.hash).toEqual('#!/item/create'); done(); }).catch(done.fail); }); it('should return to the item index by clickig the cancel button', done => { return nightmare .click(selectors.itemCreateView.cancelButton) .wait(selectors.itemsIndex.createItemButton) .parsedUrl() .then(url => { expect(url.hash).toEqual('#!/item/index'); done(); }).catch(done.fail); }); it('should now access to the create item view by clicking the create floating button', done => { return nightmare .click(selectors.itemsIndex.createItemButton) .wait(selectors.itemCreateView.createButton) .parsedUrl() .then(url => { expect(url.hash).toEqual('#!/item/create'); done(); }).catch(done.fail); }); it('should create the Infinity Gauntlet item', done => { return nightmare .type(selectors.itemCreateView.name, 'Infinity Gauntlet') .waitToClick(selectors.itemCreateView.typeSelect) .waitToClick(selectors.itemCreateView.typeSelectOptionThree) .waitToClick(selectors.itemCreateView.intrastatSelect) .waitToClick(selectors.itemCreateView.intrastatSelectOptionOne) .waitToClick(selectors.itemCreateView.originSelect) .waitToClick(selectors.itemCreateView.originSelectOptionOne) .click(selectors.itemCreateView.createButton) .waitForLastSnackbar() .then(result => { expect(result).toEqual('Data saved!'); done(); }).catch(done.fail); }); it('should confirm Infinity Gauntlet item was created', done => { return nightmare .wait(selectors.itemBasicData.nameInput) .getInputValue(selectors.itemBasicData.nameInput) .then(result => { expect(result).toBe('Infinity Gauntlet'); return nightmare .getInputValue(selectors.itemBasicData.typeSelect); }) .then(result => { expect(result).toBe('Crisantemo'); return nightmare .getInputValue(selectors.itemBasicData.intrastatSelect); }) .then(result => { expect(result).toBe('Plantas vivas: Esqueje/injerto, Vid'); return nightmare .getInputValue(selectors.itemBasicData.originSelect); }) .then(result => { expect(result).toBe('Spain'); done(); }).catch(done.fail); }); }); describe('Clone path', () => { it('should return to the items index by clicking the return to items button', done => { return nightmare .click(selectors.itemBasicData.goToItemIndexButton) .wait(selectors.itemsIndex.createItemButton) .waitForURL('#!/item/index') .parsedUrl() .then(url => { expect(url.hash).toContain('#!/item/index'); done(); }).catch(done.fail); }); it(`should search for the item Infinity Gauntlet`, done => { return nightmare .wait(selectors.itemsIndex.searchResult) .type(selectors.itemsIndex.searchItemInput, 'Infinity Gauntlet') .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 clone the Infinity Gauntlet`, done => { return nightmare .waitForTextInElement(selectors.itemsIndex.searchResult, 'Infinity Gauntlet') .click(selectors.itemsIndex.searchResultCloneButton) .waitToClick(selectors.itemsIndex.acceptClonationAlertButton) .waitForURL('tags') .parsedUrl() .then(url => { expect(url.hash).toContain('tags'); done(); }).catch(done.fail); }); it('should search for the item Infinity Gauntlet and find two', done => { return nightmare .waitToClick(selectors.itemTags.goToItemIndexButton) .wait(selectors.itemsIndex.searchResult) .type(selectors.itemsIndex.searchItemInput, 'Infinity Gauntlet') .click(selectors.itemsIndex.searchButton) .waitForNumberOfElements(selectors.itemsIndex.searchResult, 2) .countElement(selectors.itemsIndex.searchResult) .then(result => { expect(result).toEqual(2); done(); }).catch(done.fail); }); }); });