diff --git a/client/core/src/components/tooltip/tooltip.js b/client/core/src/components/tooltip/tooltip.js index 6da52513c..052e30267 100644 --- a/client/core/src/components/tooltip/tooltip.js +++ b/client/core/src/components/tooltip/tooltip.js @@ -74,45 +74,19 @@ function tooltip($document, $compile, $interpolate, $sce, $templateCache, $http, function _bindEvents() { element.bind('mouseover', function(e) { - tip.addClass(tipActiveClassName); - - let pos = e.target.getBoundingClientRect(); - let tipPos = tip[0].getBoundingClientRect(); - let offset = {top: 0, left: 0}; - let tipWidth = tipPos.width || tipPos.right - tipPos.left; - let tipHeight = tipPos.height || tipPos.bottom - tipPos.top; - let elWidth = pos.width || pos.right - pos.left; - let elHeight = pos.height || pos.bottom - pos.top; - let tipOffset = 10; - - if (tip.hasClass('tooltip-right')) { - offset.top = pos.top - (tipHeight / 2) + (elHeight / 2); - offset.left = pos.right + tipOffset; - } else if (tip.hasClass('tooltip-left')) { - offset.top = pos.top - (tipHeight / 2) + (elHeight / 2); - offset.left = pos.left - tipWidth - tipOffset; - } else if (tip.hasClass('tooltip-down')) { - offset.top = pos.top + elHeight + tipOffset; - offset.left = pos.left - (tipWidth / 2) + (elWidth / 2); - } else { - offset.top = pos.top - tipHeight - tipOffset; - offset.left = pos.left - (tipWidth / 2) + (elWidth / 2); - } - - tip.css('top', offset.top + 'px'); - tip.css('left', offset.left + 'px'); + _showTooltip(e); }); element.on('mouseout', function() { - tip.removeClass(tipActiveClassName); + _hideTooltip(); }); - tip.on('mouseover', function() { - tip.addClass(tipActiveClassName); + tip.on('mouseover', function(e) { + _showTooltip(e); }); tip.on('mouseout', function() { - tip.removeClass(tipActiveClassName); + _hideTooltip(); }); element.on('$destroy', function() { @@ -120,6 +94,64 @@ function tooltip($document, $compile, $interpolate, $sce, $templateCache, $http, scope.$destroy(); }); } + + function _calculatePosition(e) { + let pos = element[0].getBoundingClientRect(); + let tipPos = tip[0].getBoundingClientRect(); + let offset = {top: 0, left: 0}; + let tipWidth = tipPos.width || tipPos.right - tipPos.left; + let tipHeight = tipPos.height || tipPos.bottom - tipPos.top; + let elWidth = pos.width || pos.right - pos.left; + let elHeight = pos.height || pos.bottom - pos.top; + let tipOffset = 10; + + if (tip.hasClass('tooltip-right')) { + offset.top = pos.top - (tipHeight / 2) + (elHeight / 2); + offset.left = pos.right + tipOffset; + } else if (tip.hasClass('tooltip-left')) { + offset.top = pos.top - (tipHeight / 2) + (elHeight / 2); + offset.left = pos.left - tipWidth - tipOffset; + } else if (tip.hasClass('tooltip-down')) { + offset.top = pos.top + elHeight + tipOffset; + offset.left = pos.left - (tipWidth / 2) + (elWidth / 2); + } else { + offset.top = pos.top - tipHeight - tipOffset; + offset.left = pos.left - (tipWidth / 2) + (elWidth / 2); + } + // outsides + if (offset.left + tipPos.width > window.innerWidth) { // right outside + let diffLeft = (offset.left + tipPos.width) - window.innerWidth; + offset.left -= diffLeft + 10; + + let arrow = tip[0].querySelector('.tooltip-arrow'); + if (arrow) { + angular.element(arrow).css('margin-left', diffLeft + 'px'); + } + } else if (offset.left < 10) { // left outside + offset.left = 10; + let arrow = tip[0].querySelector('.tooltip-arrow'); + if (arrow) { + angular.element(arrow).css('margin-left', '10px'); + } + } + if (offset.top > window.innerHeight) { // down outside + offset.top = pos.top - tipHeight - tipOffset; + } else if (offset.top < 10) { // top outside + offset.top = pos.top + elHeight + tipOffset; + } + + tip.css('top', offset.top + 'px'); + tip.css('left', offset.left + 'px'); + } + + function _showTooltip(e) { + tip.addClass(tipActiveClassName); + _calculatePosition(e); + } + + function _hideTooltip() { + tip.removeClass(tipActiveClassName); + } } }; } diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 8480a8b74..ee90c48d3 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -182,6 +182,7 @@ export default { submitBasicDataButton: `${components.vnSubmit}` }, itemTags: { + goToItemIndexButton: 'body > vn-app > vn-vertical > vn-vertical > ui-view > vn-item-card > vn-main-block > vn-horizontal > vn-auto > vn-item-descriptor > vn-card > div > vn-vertical > vn-auto.descriptor-header.pointer > img', tagsButton: `${components.vnMenuItem}[ui-sref="item.card.tags"]`, firstTagSelect: `vn-horizontal:nth-child(3) > ${components.vnAutocomplete}[field="itemTag.tagFk"] > vn-vertical > ${components.vnTextfield}`, firstTagSelectOptionOne: `vn-horizontal:nth-child(3) > ${components.vnAutocomplete}[field="itemTag.tagFk"] > vn-vertical > vn-drop-down > vn-vertical:not(.ng-hide) > vn-auto:nth-child(2) > ul > li:nth-child(1)`, @@ -244,7 +245,7 @@ export default { }, itemSummary: { basicData: `${components.vnItemSummary} > vn-horizontal:nth-child(1) > vn-one:nth-child(2) > vn-vertical > p:nth-child(2)`, - tags: `${components.vnItemSummary} > vn-horizontal:nth-child(1) > vn-one:nth-child(3) > vn-vertical > p`, + tags: `${components.vnItemSummary} > vn-horizontal:nth-child(1) > vn-one:nth-child(3) > vn-vertical > p:nth-child(2)`, niche: `${components.vnItemSummary} > vn-horizontal:nth-child(2) > vn-one:nth-child(1) > vn-vertical > p:nth-child(2)`, botanical: `${components.vnItemSummary} > vn-horizontal:nth-child(2) > vn-one:nth-child(2) > vn-vertical > p`, barcode: `${components.vnItemSummary} > vn-horizontal:nth-child(2) > vn-one:nth-child(3) > vn-vertical > p` diff --git a/e2e/paths/item-module/03_edit_item_tax.spec.js b/e2e/paths/item-module/03_edit_item_tax.spec.js index 6b1dc9fc8..db39aa089 100644 --- a/e2e/paths/item-module/03_edit_item_tax.spec.js +++ b/e2e/paths/item-module/03_edit_item_tax.spec.js @@ -53,10 +53,10 @@ describe('add item tax path', () => { }); }); - it(`should confirm the item name was edited`, () => { + it(`should confirm the item tax class was edited`, () => { return nightmare .click(selectors.itemTags.tagsButton) - .wait(selectors.itemTags.tagsButton) + .wait(selectors.itemTags.firstTagSelect) .waitToClick(selectors.itemTax.taxButton) .wait(200) .getInputValue(selectors.itemTax.firstClassSelect) diff --git a/e2e/paths/item-module/08_item_create_and_clone.spec.js b/e2e/paths/item-module/08_item_create_and_clone.spec.js index 09c5e9197..0275a3f64 100644 --- a/e2e/paths/item-module/08_item_create_and_clone.spec.js +++ b/e2e/paths/item-module/08_item_create_and_clone.spec.js @@ -121,6 +121,7 @@ describe('Item', () => { it('should search for the item Infinity Gauntlet and find two', () => { return nightmare + .waitToClick(selectors.itemTags.goToItemIndexButton) .wait(selectors.itemsIndex.searchResult) .type(selectors.itemsIndex.searchItemInput, 'Infinity Gauntlet') .click(selectors.itemsIndex.searchButton) diff --git a/services/loopback/common/validations/specs/validateDni.spec.js b/services/loopback/common/validations/specs/validateDni.spec.js index 77b1fcea1..2e902d6a2 100644 --- a/services/loopback/common/validations/specs/validateDni.spec.js +++ b/services/loopback/common/validations/specs/validateDni.spec.js @@ -1,86 +1,101 @@ const validateDni = require('../validateDni'); describe('DNI validation', () => { - it('should return false for invented DNI', async () => { + it('should return false for invented DNI', () => { let isValid = validateDni('Pepinillos'); + expect(isValid).toBeFalsy(); }); - // Spanish + describe('Spanish', () => { + it('should return true for valid spanish DNI', () => { + let isValid = validateDni('20849756A'); - it('should return true for valid spanish DNI', async () => { - let isValid = validateDni('20849756A'); - expect(isValid).toBeTruthy(); + expect(isValid).toBeTruthy(); + }); + + it('should return true for spanish DNI with exceeded digits', () => { + let isValid = validateDni('208497563239A'); + + expect(isValid).toBeFalsy(); + }); + + it('should return false for spanish DNI with invalid letter', () => { + let isValid = validateDni('20243746E'); + + expect(isValid).toBeFalsy(); + }); + + it('should return true for valid spanish CIF', () => { + let isValid = validateDni('B97367486'); + + expect(isValid).toBeTruthy(); + }); + + it('should return false for spanish CIF with invalid letter', () => { + let isValid = validateDni('A97527786'); + + expect(isValid).toBeFalsy(); + }); }); - it('should return true for spanish DNI with exceeded digits', async () => { - let isValid = validateDni('208497563239A'); - expect(isValid).toBeFalsy(); + describe('French', () => { + it('should return true for valid french DNI', () => { + let isValid = validateDni('FR1B123456789'); + + expect(isValid).toBeTruthy(); + }); + + it('should return true for french DNI with exceeded digits', () => { + let isValid = validateDni('FR1B12345678910'); + + expect(isValid).toBeFalsy(); + }); + + it('should return true for french DNI with bad syntax', () => { + let isValid = validateDni('FR1B12345678A'); + + expect(isValid).toBeFalsy(); + }); }); - it('should return false for spanish DNI with invalid letter', async () => { - let isValid = validateDni('20243746E'); - expect(isValid).toBeFalsy(); + describe('Italian', () => { + it('should return true for valid italian DNI', () => { + let isValid = validateDni('IT12345678911'); + + expect(isValid).toBeTruthy(); + }); + + it('should return true for italian DNI with exceeded digits', () => { + let isValid = validateDni('IT123456789112'); + + expect(isValid).toBeFalsy(); + }); + + it('should return true for italian DNI with bad syntax', () => { + let isValid = validateDni('IT1234567891A'); + + expect(isValid).toBeFalsy(); + }); }); - it('should return true for valid spanish CIF', async () => { - let isValid = validateDni('B97367486'); - expect(isValid).toBeTruthy(); - }); + describe('Portuguese', () => { + it('should return true for valid portuguese DNI', () => { + let isValid = validateDni('PT123456789'); - it('should return false for spanish CIF with invalid letter', async () => { - let isValid = validateDni('A97527786'); - expect(isValid).toBeFalsy(); - }); + expect(isValid).toBeTruthy(); + }); - // French + it('should return true for portuguese DNI with exceeded digits', () => { + let isValid = validateDni('PT12345678910'); - it('should return true for valid french DNI', async () => { - let isValid = validateDni('FR1B123456789'); - expect(isValid).toBeTruthy(); - }); + expect(isValid).toBeFalsy(); + }); - it('should return true for french DNI with exceeded digits', async () => { - let isValid = validateDni('FR1B12345678910'); - expect(isValid).toBeFalsy(); - }); + it('should return true for portuguese DNI with bad syntax', () => { + let isValid = validateDni('PT12345678A'); - it('should return true for french DNI with bad syntax', async () => { - let isValid = validateDni('FR1B12345678A'); - expect(isValid).toBeFalsy(); - }); - - // Italian - - it('should return true for valid italian DNI', async () => { - let isValid = validateDni('IT12345678911'); - expect(isValid).toBeTruthy(); - }); - - it('should return true for italian DNI with exceeded digits', async () => { - let isValid = validateDni('IT123456789112'); - expect(isValid).toBeFalsy(); - }); - - it('should return true for italian DNI with bad syntax', async () => { - let isValid = validateDni('IT1234567891A'); - expect(isValid).toBeFalsy(); - }); - - // Portuguese - - it('should return true for valid portuguese DNI', async () => { - let isValid = validateDni('PT123456789'); - expect(isValid).toBeTruthy(); - }); - - it('should return true for portuguese DNI with exceeded digits', async () => { - let isValid = validateDni('PT12345678910'); - expect(isValid).toBeFalsy(); - }); - - it('should return true for portuguese DNI with bad syntax', async () => { - let isValid = validateDni('PT12345678A'); - expect(isValid).toBeFalsy(); + expect(isValid).toBeFalsy(); + }); }); });