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 .wait(selectors.itemsIndex.searchItemInput) .type(selectors.itemsIndex.searchItemInput, 'Infinity Gauntlet') .click(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 .click(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 .click(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 .click(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 .type(selectors.itemCreateView.name, 'Infinity Gauntlet') .autocompleteSearch(selectors.itemCreateView.typeAutocomplete, 'Crisantemo') .autocompleteSearch(selectors.itemCreateView.intrastatAutocomplete, 'Coral y materiales similares') .autocompleteSearch(selectors.itemCreateView.originAutocomplete, 'Holand') .click(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 .click(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 .wait(selectors.itemsIndex.searchItemInput) .type(selectors.itemsIndex.searchItemInput, 'Infinity Gauntlet') .click(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') .click(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) .wait(selectors.itemsIndex.searchItemInput) .type(selectors.itemsIndex.searchItemInput, 'Infinity Gauntlet') .click(selectors.itemsIndex.searchButton) .waitForNumberOfElements(selectors.itemsIndex.searchResult, 2) .countElement(selectors.itemsIndex.searchResult); expect(result).toEqual(2); }); }); });