import selectors from '../../helpers/selectors.js'; import createNightmare from '../../helpers/nightmare'; describe('Item Create/Clone path', () => { const nightmare = createNightmare(); describe('create', () => { beforeAll(() => { nightmare .loginAndModule('buyer', 'item'); }); it(`should search for the item Infinity Gauntlet to confirm it isn't created yet`, async() => { const result = await nightmare .write(selectors.itemsIndex.searchItemInput, 'Infinity Gauntlet') .waitToClick(selectors.itemsIndex.searchButton) .waitForNumberOfElements(selectors.itemsIndex.searchResult, 0) .countElement(selectors.itemsIndex.searchResult); expect(result).toEqual(0); }); it('should access to the create item view by clicking the create floating button', async() => { const url = await nightmare .waitToClick(selectors.itemsIndex.createItemButton) .wait(selectors.itemCreateView.createButton) .parsedUrl(); expect(url.hash).toEqual('#!/item/create'); }); it('should return to the item index by clickig the cancel button', async() => { const url = await nightmare .waitToClick(selectors.itemCreateView.cancelButton) .wait(selectors.itemsIndex.createItemButton) .parsedUrl(); expect(url.hash).toEqual('#!/item/index'); }); it('should now access to the create item view by clicking the create floating button', async() => { const url = await nightmare .waitToClick(selectors.itemsIndex.createItemButton) .wait(selectors.itemCreateView.createButton) .parsedUrl(); expect(url.hash).toEqual('#!/item/create'); }); it('should create the Infinity Gauntlet item', async() => { const result = await nightmare .write(selectors.itemCreateView.temporalName, 'Infinity Gauntlet') .autocompleteSearch(selectors.itemCreateView.typeAutocomplete, 'Crisantemo') .autocompleteSearch(selectors.itemCreateView.intrastatAutocomplete, 'Coral y materiales similares') .autocompleteSearch(selectors.itemCreateView.originAutocomplete, 'Holand') .waitToClick(selectors.itemCreateView.createButton) .waitForLastSnackbar(); expect(result).toEqual('Data saved!'); }); it('should confirm Infinity Gauntlet item was created', async() => { let result = await nightmare .waitToGetProperty(selectors.itemBasicData.nameInput, 'value'); expect(result).toEqual('Infinity Gauntlet'); result = await nightmare .waitToGetProperty(`${selectors.itemBasicData.typeAutocomplete} input`, 'value'); expect(result).toEqual('Crisantemo'); result = await nightmare .waitToGetProperty(`${selectors.itemBasicData.intrastatAutocomplete} input`, 'value'); expect(result).toEqual('5080000 Coral y materiales similares'); result = await nightmare .waitToGetProperty(`${selectors.itemBasicData.originAutocomplete} input`, 'value'); expect(result).toEqual('Holand'); }); }); describe('clone', () => { it('should return to the items index by clicking the return to items button', async() => { const url = await nightmare .waitToClick(selectors.itemBasicData.goToItemIndexButton) .wait(selectors.itemsIndex.createItemButton) .waitForURL('#!/item/index') .parsedUrl(); expect(url.hash).toContain('#!/item/index'); }); it(`should search for the item Infinity Gauntlet`, async() => { const result = await nightmare .write(selectors.itemsIndex.searchItemInput, 'Infinity Gauntlet') .waitToClick(selectors.itemsIndex.searchButton) .waitForNumberOfElements(selectors.itemsIndex.searchResult, 1) .countElement(selectors.itemsIndex.searchResult); expect(result).toEqual(1); }); it(`should clone the Infinity Gauntlet`, async() => { const url = await nightmare .waitForTextInElement(selectors.itemsIndex.searchResult, 'Infinity Gauntlet') .waitToClick(selectors.itemsIndex.searchResultCloneButton) .waitToClick(selectors.itemsIndex.acceptClonationAlertButton) .waitForURL('tags') .parsedUrl(); expect(url.hash).toContain('tags'); }); it('should search for the item Infinity Gauntlet and find two', async() => { const result = await nightmare .waitToClick(selectors.itemTags.goToItemIndexButton) .write(selectors.itemsIndex.searchItemInput, 'Infinity Gauntlet') .waitToClick(selectors.itemsIndex.searchButton) .waitForNumberOfElements(selectors.itemsIndex.searchResult, 2) .countElement(selectors.itemsIndex.searchResult); expect(result).toEqual(2); }); }); });