Skip to content

Commit

Permalink
fix(depots): depots deleted by name
Browse files Browse the repository at this point in the history
This commit fixes the depots test to ensure that it only removes depots
by the correct name.  This is thought to contribute to #2110.

Closes #2110.
  • Loading branch information
jniles committed Sep 22, 2017
1 parent a5d31b4 commit c96d1e2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 27 deletions.
35 changes: 21 additions & 14 deletions test/end-to-end/depots/depots.page.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
/* global element, by, browser */
/* global element, by */

/**
* This class is represents a depot page in term of structure and
* behaviour so it is a depot page object
**/
*/

const chai = require('chai');

const helpers = require('../shared/helpers');

helpers.configure(chai);

/** loading grid actions **/
/* loading grid actions */
const GA = require('../shared/GridAction');
const GU = require('../shared/GridUtils');
const FU = require('../shared/FormUtils');
const components = require('../shared/components');

class DepotPage {

constructor() {
this.gridId = 'depot-grid';
this.depotGrid = element(by.id(this.gridId));
Expand Down Expand Up @@ -60,20 +59,28 @@ class DepotPage {
/**
* simulate a click on the edit link of a depot
*/
editDepot(n, name) {
GA.clickOnMethod(n, this.actionLinkColumn, 'edit', this.gridId);
FU.input('DepotModalCtrl.depot.text', name);
FU.buttons.submit();
components.notification.hasSuccess();
editDepot(text, newDepotText) {
GU.getGridIndexesMatchingText(this.gridId, text)
.then(indices => {
const { rowIndex } = indices;
GA.clickOnMethod(rowIndex, this.actionLinkColumn, 'edit', this.gridId);
FU.input('DepotModalCtrl.depot.text', newDepotText);
FU.buttons.submit();
components.notification.hasSuccess();
});
}

/**
* simulate a click on the delete link of a depot
*/
deleteDepot(n) {
GA.clickOnMethod(n, this.actionLinkColumn, 'delete', this.gridId);
components.modalAction.confirm();
components.notification.hasSuccess();
deleteDepot(text) {
GU.getGridIndexesMatchingText(this.gridId, text)
.then(indices => {
const { rowIndex } = indices;
GA.clickOnMethod(rowIndex, this.actionLinkColumn, 'delete', this.gridId);
components.modalAction.confirm();
components.notification.hasSuccess();
});
}

/**
Expand Down
11 changes: 2 additions & 9 deletions test/end-to-end/depots/depots.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/* global element, by, inject, browser */
const chai = require('chai');

const helpers = require('../shared/helpers');
const DepotPage = require('./depots.page');

helpers.configure(chai);

describe('Depots Management', () => {
// navigate to the page
before(() => helpers.navigate('#!/depots'));
Expand All @@ -22,21 +17,19 @@ describe('Depots Management', () => {
is_warehouse : 1,
};

const LAST_RECORD = 0; // based on alphabetical sort and position

it('successfully creates a new depot', () => {
Page.createDepot(depot.text, false);
});

it('successfully edits a depot', () => {
Page.editDepot(LAST_RECORD, updateDepot.text);
Page.editDepot(depot.text, updateDepot.text);
});

it('don\'t create when incorrect depot name', () => {
Page.errorOnCreateDepot();
});

it('successfully delete a depot', () => {
Page.deleteDepot(LAST_RECORD);
Page.deleteDepot(updateDepot.text);
});
});
33 changes: 29 additions & 4 deletions test/end-to-end/shared/GridUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const chai = require('chai');
const helpers = require('./helpers');

const expect = chai.expect;
const { expect } = chai;
helpers.configure(chai);

function getGrid(gridId) {
Expand Down Expand Up @@ -46,12 +46,36 @@ function expectRowCountAbove(gridId, number) {
expect(rows.count()).to.eventually.be.above(number);
}

// assert that the journal's column count is the number passed in
// assert that the grids's column count is the number passed in
function expectColumnCount(gridId, number) {
const columns = getColumns(gridId);
expect(columns.count()).to.eventually.equal(number);
}

// Provide a text in a cell and this will give the grid indexes for where to find that text
function getGridIndexesMatchingText(gridId, text) {
let rowIdx;
let colIdx;

console.warn('Warning: You called GU.getGridIndexesMatchingText() which is extremely inefficient.');

// loop through every single cell and check that the grid's value contains this provided value
return this.getGrid(gridId)
.element(by.css('.ui-grid-render-container-body'))
.all(by.repeater('(rowRenderIndex, row) in rowContainer.renderedRows track by $index'))
.each((row, rowIndex) =>
row.all(by.repeater('(colRenderIndex, col) in colContainer.renderedColumns track by col.uid'))
.each((column, columnIndex) =>
column.getText()
.then(elementText => {
if (elementText.includes(text)) {
rowIdx = rowIndex;
colIdx = columnIndex;
}
})))
.then(() => ({ rowIndex : rowIdx, columnIndex : colIdx }));
}

/**
* Helper function for returning a row.
*
Expand Down Expand Up @@ -82,8 +106,8 @@ function expectHeaderColumns(gridId, expectedColumns) {
headerColumns.count()
).to.eventually.equal(expectedColumns.length);

headerColumns.getText().then(columnTexts => {
columnTexts = columnTexts.map(function trimText(text) {
headerColumns.getText().then(colTexts => {
const columnTexts = colTexts.map(function trimText(text) {
return text.replace(/^\s+/, '').replace(/\s+$/, '');
});

Expand Down Expand Up @@ -138,6 +162,7 @@ exports.getRows = getRows;
exports.getRow = getRow;
exports.getColumns = getColumns;
exports.getCell = getCell;
exports.getGridIndexesMatchingText = getGridIndexesMatchingText;
exports.getCellName = getCellName;
exports.expectRowCount = expectRowCount;
exports.expectRowCountAbove = expectRowCountAbove;
Expand Down

0 comments on commit c96d1e2

Please sign in to comment.