diff --git a/e2e/helpers/extensions.js b/e2e/helpers/extensions.js index fb36e3279..022b282d3 100644 --- a/e2e/helpers/extensions.js +++ b/e2e/helpers/extensions.js @@ -6,6 +6,93 @@ import config from './config.js'; let currentUser; +let asyncActions = { + // Generic extensions + + clickIfExists: async function(selector) { + let exists = await this.exists(selector); + if (exists) await this.click(selector); + }, + + // Salix specific extensions + + changeLanguageToEnglish: async function() { + let langSelector = '.user-popover vn-autocomplete[ng-model="$ctrl.lang"]'; + + let lang = await this.waitToClick('#user') + .wait(langSelector) + .waitToGetProperty(`${langSelector} input`, 'value'); + + if (lang !== 'English') + await this.autocompleteSearch(langSelector, 'English'); + }, + + login: async function(userName) { + if (currentUser !== userName) { + this.clickIfExists('#logout') + .clickIfExists('.vn-dialog.shown button[response=ACCEPT]'); + + try { + await this.waitForURL('#!/login'); + } catch (e) { + this.goto(`${config.url}/#!/login`); + } + + await this.wait(`vn-login input[name=user]`) + .clearInput(`vn-login input[name=user]`) + .write(`vn-login input[name=user]`, userName) + .write(`vn-login input[name=password]`, 'nightmare') + .click(`vn-login input[type=submit]`) + .waitForURL('#!/') + .changeLanguageToEnglish(); + + currentUser = userName; + } else + await this.waitToClick('vn-topbar a[ui-sref="home"]'); + }, + + waitForLogin: async function(userName) { + await this.login(userName); + }, + + selectModule: async function(moduleName) { + let snakeName = moduleName.replace(/[\w]([A-Z])/g, m => { + return m[0] + '-' + m[1]; + }).toLowerCase(); + + await this.waitToClick(`vn-home a[ui-sref="${moduleName}.index"]`) + .waitForURL(snakeName); + }, + + loginAndModule: async function(userName, moduleName) { + await this.login(userName) + .selectModule(moduleName); + }, + + datePicker: async function(selector, changeMonth, day) { + let date = new Date(); + if (changeMonth) date.setMonth(date.getMonth() + changeMonth); + date.setDate(day ? day : 16); + date = date.toISOString().substr(0, 10); + + await this.wait(selector) + .evaluate((selector, date) => { + let input = document.querySelector(selector).$ctrl.input; + input.value = date; + input.dispatchEvent(new Event('change')); + }, selector, date); + }, + + pickTime: async function(selector, time) { + await this.wait(selector) + .evaluate((selector, time) => { + let input = document.querySelector(selector); + input.value = time; + input.dispatchEvent(new Event('change')); + }, selector, time); + } +}; + let actions = { clearTextarea: function(selector, done) { this.wait(selector) @@ -28,48 +115,6 @@ let actions = { .catch(done); }, - login: function(userName, done) { - if (currentUser) - this.waitToClick('#logout'); - - let doLogin = () => { - this.wait(`vn-login input[name=user]`) - .clearInput(`vn-login input[name=user]`) - .write(`vn-login input[name=user]`, userName) - .write(`vn-login input[name=password]`, 'nightmare') - .click(`vn-login input[type=submit]`) - .then(() => { - currentUser = userName; - done(); - }) - .catch(done); - }; - - this.waitForURL('#!/login') - .then(doLogin) - .catch(() => { - this.goto(`${config.url}/#!/login`) - .then(doLogin) - .catch(done); - }); - }, - - waitForLogin: function(userName, done) { - if (currentUser === userName) { - return this.waitToClick('vn-topbar a[ui-sref="home"]') - .waitForURL('#!/') - .changeLanguageToEnglish() - .then(done) - .catch(done); - } - return this.login(userName) - .waitForURL('#!/') - .url() - .changeLanguageToEnglish() - .then(done) - .catch(done); - }, - resetLogin: function(done) { this.then(() => { currentUser = undefined; @@ -78,41 +123,6 @@ let actions = { .catch(done); }, - changeLanguageToEnglish: function(done) { - let langSelector = '.user-popover vn-autocomplete[ng-model="$ctrl.lang"]'; - - this.waitToClick('#user') - .wait(langSelector) - .waitToGetProperty(`${langSelector} input`, 'value') - .then(lang => { - if (lang === 'English') { - this.then(done) - .catch(done); - } else { - this.autocompleteSearch(langSelector, 'English') - .then(done) - .catch(done); - } - }); - }, - - selectModule: function(moduleName, done) { - let snakeName = moduleName.replace(/[\w]([A-Z])/g, m => { - return m[0] + '-' + m[1]; - }).toLowerCase(); - this.waitToClick(`vn-home a[ui-sref="${moduleName}.index"]`) - .waitForURL(snakeName) - .then(done) - .catch(done); - }, - - loginAndModule: function(userName, moduleName, done) { - this.waitForLogin(userName) - .selectModule(moduleName) - .then(done) - .catch(done); - }, - parsedUrl: function(done) { this.url() .then(url => { @@ -419,51 +429,6 @@ let actions = { }); }, - pickTime: function(selector, time, done) { - this.wait(selector) - .evaluate((selector, time) => { - let input = document.querySelector(selector); - input.value = time; - input.dispatchEvent(new Event('change')); - }, selector, time) - .then(done) - .catch(done); - }, - - datePicker: function(selector, changeMonth, day, done) { - this.wait(selector) - .mousedown(`${selector} input`) - .wait('.flatpickr-calendar.open'); - - if (changeMonth > 0) - this.mousedown(`.flatpickr-calendar.open .flatpickr-next-month`); - if (changeMonth < 0) - this.mousedown(`.flatpickr-calendar.open .flatpickr-prev-month`); - - let daySelector; - - if (!day) - daySelector = `.flatpickr-calendar.open .flatpickr-day:nth-child(16)`; - if (day) - daySelector = `.flatpickr-calendar.open .flatpickr-day[aria-label~="${day},"]:not(.prevMonthDay):not(.nextMonthDay)`; - - this.wait(selector => { - return document.querySelector(selector); - }, daySelector) - .evaluate(selector => { - let event = new MouseEvent('mousedown', { - bubbles: true, - cancelable: true, - view: window - }); - document.querySelector(selector).dispatchEvent(event); - }, daySelector) - .then(done) - .catch(() => { - done(new Error(`.datePicker(), for ${daySelector} timed out`)); - }); - }, - reloadSection: function(sectionRoute, done) { this.waitToClick('vn-icon[icon="desktop_windows"]') .wait('vn-card.summary') @@ -520,3 +485,13 @@ Object.keys(actions).forEach(function(name) { let fn = actions[name]; Nightmare.action(name, fn); }); + +for (let name in asyncActions) { + let fn = asyncActions[name]; + + Nightmare.action(name, function(...args) { + let done = args[args.length - 1]; + fn.apply(this, args) + .then(res => done(null, res), done); + }); +} diff --git a/e2e/helpers/nightmare.js b/e2e/helpers/nightmare.js index a76b50093..f93523856 100644 --- a/e2e/helpers/nightmare.js +++ b/e2e/helpers/nightmare.js @@ -1,4 +1,6 @@ const Nightmare = require('nightmare'); +const config = require('./config.js'); + let nightmare; module.exports = function createNightmare(width = 1280, height = 720) { @@ -22,5 +24,5 @@ module.exports = function createNightmare(width = 1280, height = 720) { }); nightmare.header('Accept-Language', 'en'); - return nightmare; + return nightmare.goto(config.url); }; diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 81ad3a0dc..5a3f131a8 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -420,7 +420,6 @@ export default { firstSaleQuantity: 'vn-input-number[ng-model="sale.quantity"]:nth-child(1) input', firstSaleQuantityCell: 'vn-ticket-sale vn-tr:nth-child(1) > vn-td-editable:nth-child(5)', firstSaleQuantityClearInput: 'vn-textfield[ng-model="sale.quantity"] div.suffix > i', - firstSaleIdInput: 'vn-ticket-sale vn-table vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(4) > vn-autocomplete input', firstSaleIdAutocomplete: 'vn-ticket-sale vn-table vn-tbody > vn-tr:nth-child(1) > vn-td:nth-child(4) > vn-autocomplete', idAutocompleteFirstResult: '.vn-popover.shown .vn-drop-down li', firstSalePrice: 'vn-ticket-sale vn-table vn-tr:nth-child(1) > vn-td:nth-child(7) > span', diff --git a/e2e/paths/01-login/01_login.spec.js b/e2e/paths/01-login/01_login.spec.js index a33be0c25..e5a70703e 100644 --- a/e2e/paths/01-login/01_login.spec.js +++ b/e2e/paths/01-login/01_login.spec.js @@ -1,5 +1,4 @@ import createNightmare from '../../helpers/nightmare'; -import config from '../../helpers/config.js'; describe('Login path', () => { @@ -10,7 +9,6 @@ describe('Login path', () => { const password = 'nightmare'; const result = await nightmare - .goto(`${config.url}/#!/login`) .wait(`vn-login input[name=user]`) .write(`vn-login input[name=user]`, username) .write(`vn-login input[name=password]`, password) diff --git a/front/core/components/autocomplete/index.html b/front/core/components/autocomplete/index.html index 2e5cc39f6..c0caf061b 100755 --- a/front/core/components/autocomplete/index.html +++ b/front/core/components/autocomplete/index.html @@ -1,6 +1,6 @@