From d192a6ab03a69dc1f65fa85a9bf62d50f88bc462 Mon Sep 17 00:00:00 2001 From: Juanfran Date: Tue, 4 Aug 2015 14:57:26 +0200 Subject: [PATCH] e2e attributes --- .../admin/attributes/custom-fields.e2e.js | 123 +++++++++++++++++ e2e/full/admin/attributes/points.e2e.js | 100 ++++++++++++++ e2e/full/admin/attributes/priorities.e2e.js | 98 ++++++++++++++ e2e/full/admin/attributes/status.e2e.js | 124 ++++++++++++++++++ e2e/helpers/admin-attributes-helper.js | 116 ++++++++++++++++ e2e/helpers/index.js | 1 + e2e/utils/common.js | 60 +++++++-- test.js | 17 +++ 8 files changed, 631 insertions(+), 8 deletions(-) create mode 100644 e2e/full/admin/attributes/custom-fields.e2e.js create mode 100644 e2e/full/admin/attributes/points.e2e.js create mode 100644 e2e/full/admin/attributes/priorities.e2e.js create mode 100644 e2e/full/admin/attributes/status.e2e.js create mode 100644 e2e/helpers/admin-attributes-helper.js create mode 100644 test.js diff --git a/e2e/full/admin/attributes/custom-fields.e2e.js b/e2e/full/admin/attributes/custom-fields.e2e.js new file mode 100644 index 00000000..2d98ea4e --- /dev/null +++ b/e2e/full/admin/attributes/custom-fields.e2e.js @@ -0,0 +1,123 @@ +var utils = require('../../../utils'); + +var adminAttributesHelper = require('../../../helpers').adminAttributes; + +var chai = require('chai'); +var chaiAsPromised = require('chai-as-promised'); + +chai.use(chaiAsPromised); +var expect = chai.expect; + +describe('attributes - custom fields', function() { + before(async function(){ + browser.get('http://localhost:9001/project/project-0/admin/project-values/custom-fields'); + + await utils.common.waitLoader(); + + utils.common.takeScreenshot('attributes', 'custom-fields'); + }); + + it('new', async function() { + let section = adminAttributesHelper.getSection(0); + let rows = section.rows(); + let count = await rows.count(); + + let formWrapper = section.openNew(); + + let form = adminAttributesHelper.getCustomFieldsForm(formWrapper); + + await form.name().sendKeys('test test'); + + await form.save(); + + await browser.waitForAngular(); + + let newCount = await rows.count(); + + expect(newCount).to.be.equal(count + 1); + }); + + it('duplicate', async function() { + let section = adminAttributesHelper.getSection(0); + let rows = section.rows(); + let count = await rows.count(); + + let formWrapper = section.openNew(); + + let form = adminAttributesHelper.getCustomFieldsForm(formWrapper); + + await form.name().sendKeys('test test'); + + await form.save(); + + await browser.waitForAngular(); + + let newCount = await rows.count(); + + let errors = await form.errors().count(); + + utils.common.takeScreenshot('attributes', 'status-error'); + + expect(errors).to.be.equal(1); + expect(newCount).to.be.equal(count); + }); + + it('delete', async function() { + let section = adminAttributesHelper.getSection(0); + let rows = section.rows(); + + let count = await rows.count(); + + let row = rows.get(count - 1); + + section.delete(row); + + let el = $('.lightbox-generic-ask'); + + await utils.lightbox.open(el); + + utils.common.takeScreenshot('attributes', 'delete-custom-field'); + + el.$('.button-green').click(); + + await utils.lightbox.close(el); + + let newCount = await rows.count(); + + expect(newCount).to.be.equal(count - 1); + }); + + it('edit', async function() { + let section = adminAttributesHelper.getSection(0); + let rows = section.rows(); + let row = rows.get(0); + + await section.edit(row); + + let form = adminAttributesHelper.getCustomFieldsForm(row.$('form')); + + let newCfName = 'test test' + Date.now(); + await form.name().clear(); + await form.name().sendKeys(newCfName); + + await form.save(); + + await browser.waitForAngular(); + + let newCfs = await adminAttributesHelper.getCustomFieldsNames(section.el); + + expect(newCfs.indexOf(newCfName)).to.be.not.equal(-1); + }); + + it('drag', async function() { + let section = adminAttributesHelper.getSection(0); + let rows = section.rows(); + let cfs = await adminAttributesHelper.getCustomFieldsNames(section.el); + + await utils.common.drag(rows.get(0), rows.get(2)); + + let newCfs = await adminAttributesHelper.getCustomFieldsNames(section.el); + + expect(cfs[0]).to.be.equal(newCfs[1]); + }); +}); diff --git a/e2e/full/admin/attributes/points.e2e.js b/e2e/full/admin/attributes/points.e2e.js new file mode 100644 index 00000000..d926d8e5 --- /dev/null +++ b/e2e/full/admin/attributes/points.e2e.js @@ -0,0 +1,100 @@ +var utils = require('../../../utils'); + +var adminAttributesHelper = require('../../../helpers').adminAttributes; + +var chai = require('chai'); +var chaiAsPromised = require('chai-as-promised'); + +chai.use(chaiAsPromised); +var expect = chai.expect; + +describe('attributes - points', function() { + before(async function(){ + browser.get('http://localhost:9001/project/project-0/admin/project-values/points'); + + await utils.common.waitLoader(); + + utils.common.takeScreenshot('attributes', 'points'); + }); + + it('new', async function() { + let section = adminAttributesHelper.getSection(0); + let rows = section.rows(); + let count = await rows.count(); + + let formWrapper = section.openNew(); + + let form = adminAttributesHelper.getPointsForm(formWrapper); + + await form.name().sendKeys('test test'); + await form.value().sendKeys('2'); + + await form.save(); + + await browser.waitForAngular(); + + let newCount = await rows.count(); + + expect(newCount).to.be.equal(count + 1); + }); + + it('delete', async function() { + let section = adminAttributesHelper.getSection(0); + let rows = section.rows(); + + let count = await rows.count(); + + let row = rows.get(count - 1); + + section.delete(row); + + let el = $('.lightbox-ask-choice'); + + await utils.lightbox.open(el); + + utils.common.takeScreenshot('attributes', 'delete-point'); + + el.$('.button-green').click(); + + await utils.lightbox.close(el); + + let newCount = await rows.count(); + + expect(newCount).to.be.equal(count - 1); + }); + + it('edit', async function() { + let section = adminAttributesHelper.getSection(0); + let rows = section.rows(); + + let row = rows.get(0); + + await section.edit(row); + + let form = adminAttributesHelper.getPointsForm(row.$('form')); + + let newStatusName = 'test test' + Date.now(); + + await form.name().clear(); + await form.name().sendKeys(newStatusName); + await form.save(); + + await browser.waitForAngular(); + + let newStatuses = await adminAttributesHelper.getPointsNames(section.el); + + expect(newStatuses.indexOf(newStatusName)).to.be.not.equal(-1); + }); + + it('drag', async function() { + let section = adminAttributesHelper.getSection(0); + let rows = section.rows(); + let points = await adminAttributesHelper.getPointsNames(section.el); + + await utils.common.drag(rows.get(0), rows.get(2)); + + let newPoints = await adminAttributesHelper.getPointsNames(section.el); + + expect(points[0]).to.be.equal(newPoints[1]); + }); +}); diff --git a/e2e/full/admin/attributes/priorities.e2e.js b/e2e/full/admin/attributes/priorities.e2e.js new file mode 100644 index 00000000..fcf645ea --- /dev/null +++ b/e2e/full/admin/attributes/priorities.e2e.js @@ -0,0 +1,98 @@ +var utils = require('../../../utils'); + +var adminAttributesHelper = require('../../../helpers').adminAttributes; + +var chai = require('chai'); +var chaiAsPromised = require('chai-as-promised'); + +chai.use(chaiAsPromised); +var expect = chai.expect; + +describe('attributes - priorities', function() { + before(async function(){ + browser.get('http://localhost:9001/project/project-0/admin/project-values/priorities'); + + await utils.common.waitLoader(); + + utils.common.takeScreenshot('attributes', 'priorities'); + }); + + it('new priority', async function() { + let section = adminAttributesHelper.getSection(0); + let rows = section.rows(); + let count = await rows.count(); + + let formWrapper = section.openNew(); + + let form = adminAttributesHelper.getPrioritiesForm(formWrapper); + + await form.name().sendKeys('test test'); + + await form.save(); + + await browser.waitForAngular(); + + let newCount = await rows.count(); + + expect(newCount).to.be.equal(count + 1); + }); + + it('delete', async function() { + let section = adminAttributesHelper.getSection(0); + let rows = section.rows(); + + let count = await rows.count(); + + let row = rows.get(count - 1); + + section.delete(row); + + let el = $('.lightbox-ask-choice'); + + await utils.lightbox.open(el); + + utils.common.takeScreenshot('attributes', 'delete-priority'); + + el.$('.button-green').click(); + + await utils.lightbox.close(el); + + let newCount = await rows.count(); + + expect(newCount).to.be.equal(count - 1); + }); + + it('edit', async function() { + let section = adminAttributesHelper.getSection(0); + let rows = section.rows(); + let row = rows.get(0); + + await section.edit(row); + + let form = adminAttributesHelper.getPrioritiesForm(row.$('form')); + + let newPriorityName = 'test test' + Date.now(); + await form.name().clear(); + await form.name().sendKeys(newPriorityName); + + await form.save(); + + await browser.waitForAngular(); + + let newPriorities = await adminAttributesHelper.getPrioritiesNames(section.el); + + expect(newPriorities.indexOf(newPriorityName)).to.be.not.equal(-1); + }); + + it('drag', async function() { + let section = adminAttributesHelper.getSection(0); + let rows = section.rows(); + let priorities = await adminAttributesHelper.getPrioritiesNames(section.el); + + await utils.common.drag(rows.get(0), rows.get(2)); + + let newPriorities = await adminAttributesHelper.getPrioritiesNames(section.el); + + expect(priorities[0]).to.be.equal(newPriorities[1]); + }); +}); diff --git a/e2e/full/admin/attributes/status.e2e.js b/e2e/full/admin/attributes/status.e2e.js new file mode 100644 index 00000000..31b2744c --- /dev/null +++ b/e2e/full/admin/attributes/status.e2e.js @@ -0,0 +1,124 @@ +var utils = require('../../../utils'); + +var adminAttributesHelper = require('../../../helpers').adminAttributes; + +var chai = require('chai'); +var chaiAsPromised = require('chai-as-promised'); + +chai.use(chaiAsPromised); +var expect = chai.expect; + +describe('attributes - status', function() { + before(async function(){ + browser.get('http://localhost:9001/project/project-0/admin/project-values/status'); + + await utils.common.waitLoader(); + + utils.common.takeScreenshot('attributes', 'status'); + }); + + it('new status', async function() { + let section = adminAttributesHelper.getSection(0); + let rows = section.rows(); + let count = await rows.count(); + + let formWrapper = section.openNew(); + + let form = adminAttributesHelper.getStatusForm(formWrapper); + + await form.status().sendKeys('test test'); + + await form.save(); + + await browser.waitForAngular(); + + let newCount = await rows.count(); + + expect(newCount).to.be.equal(count + 1); + }); + + it('duplicate status', async function() { + let section = adminAttributesHelper.getSection(0); + let rows = section.rows(); + let count = await rows.count(); + + let formWrapper = section.openNew(); + + let form = adminAttributesHelper.getStatusForm(formWrapper); + + await form.status().sendKeys('test test'); + + await form.save(); + + await browser.waitForAngular(); + + let newCount = await rows.count(); + + let errors = await form.errors().count(); + + utils.common.takeScreenshot('attributes', 'status-error'); + + expect(errors).to.be.equal(1); + expect(newCount).to.be.equal(count); + }); + + it('delete', async function() { + let section = adminAttributesHelper.getSection(0); + let rows = section.rows(); + + let count = await rows.count(); + + let row = rows.get(count - 1); + + section.delete(row); + + let el = $('.lightbox-ask-choice'); + + await utils.lightbox.open(el); + + utils.common.takeScreenshot('attributes', 'delete-status'); + + el.$('.button-green').click(); + + await browser.waitForAngular(); + + let newCount = await rows.count(); + + expect(newCount).to.be.equal(count - 1); + }); + + it('edit', async function() { + let section = adminAttributesHelper.getSection(0); + let rows = section.rows(); + + let row = rows.get(0); + + await section.edit(row); + + let form = adminAttributesHelper.getStatusForm(row.$('form')); + + let newStatusName = 'test test' + Date.now(); + + await form.status().clear(); + await form.status().sendKeys(newStatusName); + await form.save(); + + await browser.waitForAngular(); + + let newStatuses = await adminAttributesHelper.getStatusNames(section.el); + + expect(newStatuses.indexOf(newStatusName)).to.be.not.equal(-1); + }); + + it('drag', async function() { + let section = adminAttributesHelper.getSection(0); + let rows = section.rows(); + let statuses = await adminAttributesHelper.getStatusNames(section.el); + + await utils.common.drag(rows.get(0), rows.get(2)); + + let newStatuses = await adminAttributesHelper.getStatusNames(section.el); + + expect(statuses[0]).to.be.equal(newStatuses[1]); + }); +}); diff --git a/e2e/helpers/admin-attributes-helper.js b/e2e/helpers/admin-attributes-helper.js new file mode 100644 index 00000000..19c3be84 --- /dev/null +++ b/e2e/helpers/admin-attributes-helper.js @@ -0,0 +1,116 @@ +var utils = require('../utils'); + +var helper = module.exports; + +helper.getSection = function(item) { + let section = $$('.admin-attributes-section').get(item); + + return { + el: section, + openNew: function() { + section.$('.show-add-new').click(); + + return section.$$('form').last(); + }, + rows: function() { + return section.$$('.ui-sortable > div'); + }, + delete: function(row) { + let deleteButton = row.$$('.icon-delete').first(); + + return browser.actions() + .mouseMove(deleteButton) + .click() + .perform(); + }, + edit: async function(row) { + let editButton = row.$('.icon-edit'); + + return browser.actions() + .mouseMove(editButton) + .click() + .perform(); + } + }; +}; + +helper.getStatusNames = function(section) { + return section.$$('.status-name span').getText(); +}; + +helper.getForm = function(form) { + return { + save: function() { + let saveButton = form.$('.icon-floppy'); + + browser.actions() + .mouseMove(saveButton) + .click() + .perform(); + + // debounce + return browser.sleep(2000); + }, + errors: function() { + return form.$$('.checksley-error-list li'); + } + }; +}; + +helper.getStatusForm = function(form) { + let obj = Object.create(helper.getForm(form)); + + obj.form = form; + + obj.status = function() { + return this.form.$('.status-name input'); + }; + + return obj; +}; + +helper.getPointsNames = function(section) { + return section.$$('.project-values-body .project-values-name span').getText(); +}; + +helper.getPointsForm = function(form) { + let obj = Object.create(helper.getForm(form)); + + obj.name = function() { + return form.$('.project-values-name input'); + }; + + obj.value = function() { + return form.$('.project-values-value input'); + }; + + return obj; +}; + +helper.getPrioritiesForm = function(form) { + let obj = Object.create(helper.getForm(form)); + + obj.name = function() { + return form.$('.status-name input'); + }; + + return obj; +}; + +helper.getPrioritiesNames = function(section) { + return section.$$('.status-name span').getText(); +}; + +helper.getCustomFieldsForm = function(form) { + let obj = Object.create(helper.getForm(form)); + + obj.name = function() { + return form.$('.custom-name input'); + }; + + return obj; +}; + +helper.getCustomFieldsNames = function(section) { + return section.$$('.table-body .custom-name span').getText(); +}; diff --git a/e2e/helpers/index.js b/e2e/helpers/index.js index 2f95adf9..5cddd93f 100644 --- a/e2e/helpers/index.js +++ b/e2e/helpers/index.js @@ -6,3 +6,4 @@ module.exports.wiki = require("./wiki-helper"); module.exports.detail = require("./detail-helper"); module.exports.usDetail = require("./us-detail-helper"); module.exports.taskDetail = require("./task-detail-helper"); +module.exports.adminAttributes = require("./admin-attributes-helper"); diff --git a/e2e/utils/common.js b/e2e/utils/common.js index b95366a1..ed0f8c29 100644 --- a/e2e/utils/common.js +++ b/e2e/utils/common.js @@ -101,14 +101,58 @@ common.dragEnd = function(elm) { }, 1000); }; -common.drag = function(elm, location) { - return browser - .actions() - .dragAndDrop(elm, location) - .perform() - .then(function() { - return common.dragEnd(); - }); +common.drag = function(elm, elm2, duration=500) { + return new Promise(async function(resolve) { + let init = await elm.getLocation(); + let dest = await elm2.getLocation(); + + let startTime = new Date().getTime(); + let fromX = init.x; + let toX = dest.x; + + let fromY = init.y; + let toY = dest.y; + + let deltaX = toX - fromX; + let deltaY = toY - fromY; + + let lastPos = {x: fromX, y: fromY}; + + browser.actions() + .mouseMove(elm) + .mouseDown() + .perform(); + + let interval = setInterval(() => { + let elapsed = new Date().getTime() - startTime; + let factor = Math.min(elapsed / duration, 1); + + let newX = parseInt(fromX + deltaX * factor, 10); + let newY = parseInt(fromY + deltaY * factor, 10); + + let pos = {}; + pos.x = newX - lastPos.x; + pos.y = newY - lastPos.y; + + lastPos.x = newX; + lastPos.y = newY; + + if (lastPos.x === toX && lastPos.y === toY) { + clearInterval(interval); + + browser.actions() + .mouseMove(pos) + .mouseUp() + .perform() + .then(common.dragEnd) + .then(resolve); + } else { + browser.actions() + .mouseMove(pos) + .perform(); + } + }, 100); + }); }; common.transitionend = function(selector, property) { diff --git a/test.js b/test.js new file mode 100644 index 00000000..f7033dd5 --- /dev/null +++ b/test.js @@ -0,0 +1,17 @@ +var startTime = new Date().getTime(); +var duration = 500; +var from = 2; +var to = 10; +var delta = to - from; + +function next() { + var elapsed = new Date().getTime() - startTime; + var factor = Math.min(elapsed / duration, 1); + + console.log(from + delta * factor); +} + + +setInterval(function(){ + next(); +}, 50);