diff --git a/e2e/helpers/extensions.js b/e2e/helpers/extensions.js index a41b5855c..b635de9de 100644 --- a/e2e/helpers/extensions.js +++ b/e2e/helpers/extensions.js @@ -190,6 +190,19 @@ let actions = { }, done, selector); }, + clickIfVisible: function(selector, done) { + this.wait(selector) + .isVisible(selector) + .then(visible => { + if (visible) + return this.click(selector); + + throw new Error(`invisible selector: ${selector}`); + }) + .then(done) + .catch(done); + }, + countElement: function(selector, done) { this.evaluate_now(selector => { return document.querySelectorAll(selector).length; diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 42d05aafa..eddf8ad11 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -192,6 +192,7 @@ export default { moreMenuRegularizeButton: `vn-item-descriptor vn-icon-menu > div > vn-drop-down > vn-popover ul > li:nth-child(1)`, regularizeQuantityInput: `vn-item-descriptor > vn-dialog > div > form > div.body > tpl-body > div > vn-textfield > div > div > div.infix > input`, regularizeWarehouseAutocomplete: 'vn-item-descriptor > vn-dialog vn-autocomplete[field="$ctrl.warehouseFk"]', + editButton: 'vn-item-card vn-item-descriptor vn-float-button[icon="edit"]', regularizeSaveButton: `vn-item-descriptor > vn-dialog > div > form > div.buttons > tpl-buttons > button` }, itemBasicData: { @@ -335,7 +336,7 @@ export default { descriptorItemDiaryButton: `vn-item-descriptor .quicklinks.ng-scope > vn-horizontal > a > vn-icon > i`, newItemButton: 'vn-float-button[icon="add"]', firstSaleText: `vn-table div > vn-tbody > vn-tr:nth-child(1)`, - firstSaleThumbnailImage: 'vn-ticket-sale:nth-child(1) vn-td:nth-child(3) > img', + firstSaleThumbnailImage: 'vn-ticket-sale:nth-child(1) vn-tr:nth-child(1) vn-td:nth-child(3) > img', firstSaleZoomedImage: 'body > div > div > img', firstSaleQuantity: `vn-textfield[model="sale.quantity"]:nth-child(1) input`, firstSaleQuantityClearInput: `vn-textfield[model="sale.quantity"] div.suffix > i`, diff --git a/e2e/paths/item-module/01_item_summary.spec.js b/e2e/paths/item-module/01_item_summary.spec.js index ee6fd8785..1364aa00a 100644 --- a/e2e/paths/item-module/01_item_summary.spec.js +++ b/e2e/paths/item-module/01_item_summary.spec.js @@ -163,6 +163,13 @@ describe('Item summary path', () => { expect(url.hash).toContain('summary'); }); + it(`should check the descritor edit button is not visible for employee`, async() => { + const visibleButton = await nightmare + .isVisible(selectors.itemDescriptor.editButton); + + expect(visibleButton).toBeFalsy(); + }); + it(`should check the item summary shows fields from basic data section`, async() => { const result = await nightmare .waitForTextInElement(selectors.itemSummary.basicData, 'Object2 Gem2 3') diff --git a/e2e/paths/item-module/02_edit_item_basic_data.spec.js b/e2e/paths/item-module/02_edit_item_basic_data.spec.js index 56bdf6647..3a06a2a77 100644 --- a/e2e/paths/item-module/02_edit_item_basic_data.spec.js +++ b/e2e/paths/item-module/02_edit_item_basic_data.spec.js @@ -11,6 +11,13 @@ describe('Item Edit basic data path', () => { .accessToSection('item.card.data'); }); + it(`should check the descritor edit button is visible for buyer`, async() => { + const visibleButton = await nightmare + .isVisible(selectors.itemDescriptor.editButton); + + expect(visibleButton).toBeTruthy(); + }); + it(`should edit the item basic data`, async() => { const result = await nightmare .clearInput(selectors.itemBasicData.nameInput) diff --git a/e2e/paths/ticket-module/05_create_new_tracking_state.spec.js b/e2e/paths/ticket-module/05_create_new_tracking_state.spec.js index af2fd8a31..787809a86 100644 --- a/e2e/paths/ticket-module/05_create_new_tracking_state.spec.js +++ b/e2e/paths/ticket-module/05_create_new_tracking_state.spec.js @@ -14,10 +14,11 @@ describe('Ticket Create new tracking state path', () => { it('should access to the create state view by clicking the create floating button', async() => { let url = await nightmare - .waitToClick(selectors.ticketTracking.createStateButton) + .clickIfVisible(selectors.ticketTracking.createStateButton) .wait(selectors.createStateView.stateAutocomplete) .parsedUrl(); + expect(url.hash).toContain('tracking/edit'); }); diff --git a/e2e/paths/ticket-module/07_edit_sale.spec.js b/e2e/paths/ticket-module/07_edit_sale.spec.js index 1e1302ab8..84d793ec0 100644 --- a/e2e/paths/ticket-module/07_edit_sale.spec.js +++ b/e2e/paths/ticket-module/07_edit_sale.spec.js @@ -62,7 +62,7 @@ describe('Ticket Edit sale path', () => { it(`should click on the thumbnail image of the 1st sale and see the zoomed image`, async() => { const result = await nightmare - .waitToClick(selectors.ticketSales.firstSaleThumbnailImage) + .clickIfVisible(selectors.ticketSales.firstSaleThumbnailImage) .countElement(selectors.ticketSales.firstSaleZoomedImage); expect(result).toEqual(1); @@ -70,7 +70,7 @@ describe('Ticket Edit sale path', () => { it(`should click on the zoomed image to close it`, async() => { const result = await nightmare - .waitToClick(selectors.ticketSales.firstSaleZoomedImage) + .clickIfVisible(selectors.ticketSales.firstSaleZoomedImage) .countElement(selectors.ticketSales.firstSaleZoomedImage); expect(result).toEqual(0); @@ -94,7 +94,7 @@ describe('Ticket Edit sale path', () => { it(`should click on the descriptor image of the 1st sale and see the zoomed image`, async() => { const result = await nightmare - .waitToClick('vn-item-descriptor img') + .clickIfVisible('vn-item-descriptor img') .countElement(selectors.ticketSales.firstSaleZoomedImage); expect(result).toEqual(1); @@ -102,7 +102,7 @@ describe('Ticket Edit sale path', () => { it(`should click on the zoomed image to close it`, async() => { const result = await nightmare - .waitToClick(selectors.ticketSales.firstSaleZoomedImage) + .clickIfVisible(selectors.ticketSales.firstSaleZoomedImage) .countElement(selectors.ticketSales.firstSaleZoomedImage); expect(result).toEqual(0);