Skip to content

Commit

Permalink
fix(tests): remove all e2e test warnings
Browse files Browse the repository at this point in the history
This commit cleans up the e2e tests so that they specify the exact
elements they click.  It removes the "more than one element matching
selector" errors.

The following tests are affected:
 1. Accounts Management
 2. Inventory Management
 3. Invoice Registry/Search

The following utilities have been adjusted:
 1. Grid Utils
 2. Form Utils
  • Loading branch information
Jonathan Niles committed Sep 8, 2016
1 parent 4c69266 commit 51af694
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</div>

<div class="modal-footer">
<button type="button" class="btn btn-default btn-sm" ng-click="ReceiptCtrl.close()" data-action="close">
<button type="button" class="btn btn-default btn-sm" ng-click="ReceiptCtrl.close()" data-action="close" data-method="close">
{{ "FORM.BUTTONS.CLOSE" | translate }}
</button>
<button class="btn btn-primary btn-sm" ng-click="ReceiptCtrl.print()" data-action="print">
Expand Down
2 changes: 1 addition & 1 deletion client/src/partials/inventory/list/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function InventoryListController ($translate, Inventory, Notify, uiGridConstants
];

/** button Print */
vm.buttonPrint = {
vm.buttonPrint = {
pdfUrl: '/inventory/reports/metadata'
};

Expand Down
2 changes: 1 addition & 1 deletion client/src/partials/patient_invoice/registry/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function InvoiceRegistryController(Invoices, bhConstants, Notify, Session, util,

var invoiceActionsTemplate =
'<div class="ui-grid-cell-contents">' +
'<a href ng-click="grid.appScope.openReceiptModal(row.entity.uuid)">' +
'<a href ng-click="grid.appScope.openReceiptModal(row.entity.uuid)" data-method="receipt">' +
'<span class="fa fa-file-pdf-o"></span> {{ "TABLE.COLUMNS.RECEIPT" | translate }}' +
'</a>' +
'&nbsp;&nbsp;' +
Expand Down
16 changes: 3 additions & 13 deletions test/end-to-end/accounts/accounts.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,14 @@ const expect = chai.expect;
const helpers = require('../shared/helpers');
helpers.configure(chai);

const GU = require('../shared/gridTestUtils.spec.js');
const GU = require('../shared/GridUtils.js');

function AccountsPage() {
const page = this;

const gridId = 'account-grid';
const grid = GU.getGrid(gridId);

page.getRowCount = getRowCount;

function getRowCount() {
var rows = grid.element(by.css('.ui-grid-render-container-body'))
.all(by.repeater('(rowRenderIndex, row) in rowContainer.renderedRows track by $index')).count();
return rows;
}

page.expectGridRows = function expectGridRows(rows) {
expect(getRowCount()).to.eventually.equal(rows);
page.expectGridRows = function expectGridRows(numRows) {
GU.expectRowCount(gridId, numRows);
};

page.toggleTitleRow = function toggleTitleRow(accountId) {
Expand Down
17 changes: 9 additions & 8 deletions test/end-to-end/accounts/accounts.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ describe('Account Management', function () {
const path = '#/accounts';
before(() => helpers.navigate(path));


const INITIAL_ACCOUNTS = 14;
let addedAccounts = 0;

Expand Down Expand Up @@ -63,7 +62,7 @@ describe('Account Management', function () {

// relies on french translation
FU.select('AccountEditCtrl.account.type_id', 'Titre').click();
FU.buttons.submit();
FU.modal.submit();
addedAccounts += 1;

components.notification.hasSuccess();
Expand All @@ -79,16 +78,16 @@ describe('Account Management', function () {
it('updates an account title and parent', function () {
FU.input('AccountEditCtrl.account.label', 'Updated inventory accounts');
FU.uiSelect('AccountEditCtrl.account.parent', 'Test Income');
FU.buttons.submit();
FU.modal.submit();

components.notification.hasSuccess();
});

const numberOfAccounts = 3;

it('creates multiple accounts with the batch option selected', function () {
var parentNumber = 70000;
var mockAccount = {
const parentNumber = 70000;
const mockAccount = {
number : parentNumber,
label : 'End to End Test: '
};
Expand All @@ -106,11 +105,12 @@ describe('Account Management', function () {

select.element(by.css('[data-key="ACCOUNT.TYPES.TITLE"]')).click();

FU.buttons.submit();
FU.modal.submit();
addedAccounts += 1;

// set to this parent
FU.uiSelect('AccountEditCtrl.account.parent', parentNumber);

// set to income
select.element(by.css('[data-key="ACCOUNT.TYPES.INCOME"]')).click();

Expand All @@ -128,13 +128,14 @@ describe('Account Management', function () {

it('displays all created accounts with model refresh', function () {
browser.refresh();
expect(page.getRowCount()).to.eventually.equal(INITIAL_ACCOUNTS + addedAccounts);
page.expectGridRows(INITIAL_ACCOUNTS + addedAccounts);
});

// generic function to create an account in the modal
function createAccount(account, index) {
FU.input('AccountEditCtrl.account.number', account.number);
FU.input('AccountEditCtrl.account.label', account.label.concat(index));
FU.buttons.submit();
FU.modal.submit();
addedAccounts += 1;
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const components = require('../shared/components');

helpers.configure(chai);

describe('Inventory Configuration ::', () => {
describe('Inventory Configuration', () => {

// navigate to the page
before(() => helpers.navigate('#/inventory/configuration'));
Expand Down Expand Up @@ -39,7 +39,7 @@ describe('Inventory Configuration ::', () => {
const unit = { text : '[E2E] Inventory Unit' };
const updateUnit = { text : '[E2E] Inventory Unit updated' };

describe('Groups ::', () => {
describe('Groups', () => {
// navigate to the page
before(() => helpers.navigate('#/inventory/configuration'));

Expand Down Expand Up @@ -68,7 +68,7 @@ describe('Inventory Configuration ::', () => {
});

// test inventory type
describe('Types ::', () => {
describe('Types', () => {
// navigate to the page
before(() => helpers.navigate('#/inventory/configuration'));

Expand All @@ -89,7 +89,7 @@ describe('Inventory Configuration ::', () => {
});

// test inventory unit
describe('Units ::', () => {
describe('Units', () => {
// navigate to the page
before(() => helpers.navigate('#/inventory/configuration'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const components = require('../shared/components');

helpers.configure(chai);

describe('Inventory List ::', () => {
describe('Inventory List', () => {

// navigate to the page
before(() => helpers.navigate('#/inventory/list'));
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('Inventory List ::', () => {
unit_volume : 7
};

it('Successfully creates a new inventory item (metadata)', () => {
it('successfully creates a new inventory item (metadata)', () => {
FU.buttons.create();
FU.input('$ctrl.session.label', metadata.text);
FU.input('$ctrl.session.code', metadata.code);
Expand All @@ -53,16 +53,16 @@ describe('Inventory List ::', () => {
FU.select('$ctrl.session.unit', metadata.unit);
FU.input('$ctrl.session.unit_weight', metadata.unit_weight);
FU.input('$ctrl.session.unit_volume', metadata.unit_volume);
FU.buttons.submit();
FU.modal.submit();
components.notification.hasSuccess();
});

it('Dont creates a new inventory item (metadata) for invalid data', () => {
it('dont creates a new inventory item (metadata) for invalid data', () => {
FU.buttons.create();
FU.input('$ctrl.session.label', metadata.text);
FU.input('$ctrl.session.unit_weight', metadata.unit_weight);
FU.input('$ctrl.session.unit_volume', metadata.unit_volume);
FU.buttons.submit();
FU.modal.submit();

// check validations
FU.validation.ok('$ctrl.session.label');
Expand All @@ -74,15 +74,13 @@ describe('Inventory List ::', () => {
FU.validation.error('$ctrl.session.type');
FU.validation.error('$ctrl.session.unit');

// be sure not success
expect(element(by.css('[data-notification-type="notification-success"]')).isPresent())
.to.eventually.equal(false);
//components.notification.hasDanger();

FU.buttons.cancel();
});

it('Successfully updates an existing inventory item (metadata)', () => {
element(by.css('[data-edit-metadata="' + metadata.code + '"]')).click();
it('successfully updates an existing inventory item (metadata)', () => {
element(by.css(`[data-edit-metadata="${metadata.code}"]`)).click();
FU.input('$ctrl.session.label', metadataUpdate.text);
FU.input('$ctrl.session.code', metadataUpdate.code);
element(by.model('$ctrl.session.consumable')).click();
Expand All @@ -92,8 +90,8 @@ describe('Inventory List ::', () => {
FU.select('$ctrl.session.unit', metadataUpdate.unit);
FU.input('$ctrl.session.unit_weight', metadataUpdate.unit_weight);
FU.input('$ctrl.session.unit_volume', metadataUpdate.unit_volume);
FU.buttons.submit();

FU.modal.submit();
components.notification.hasSuccess();
});

});
13 changes: 5 additions & 8 deletions test/end-to-end/patient/invoice/registry.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,28 @@
/* global element, by, browser */

const FU = require('../../shared/FormUtils');
const GU = require('../../shared/GridUtils');

function InvoiceRegistryPage() {
const page = this;

//
const grid = element(by.id('invoice-registry'));
const gridRows = grid
.element(by.css('.ui-grid-render-container-body'))
.all( by.repeater('(rowRenderIndex, row) in rowContainer.renderedRows track by $index'));
const gridId = 'invoice-registry';

function getInvoiceNumber() {
return gridRows.count();
return GU.getRows(gridId).count();
}

function showInvoiceProof(n) {
const receiptColumnNumber = 6;

const row = grid
const row = GU.getGrid(gridId)
.$('.ui-grid-render-container-body')
.element(by.repeater('(rowRenderIndex, row) in rowContainer.renderedRows track by $index').row(n));

// click the <a> tag within the cell
row
.element(by.repeater('(colRenderIndex, col) in colContainer.renderedColumns track by col.uid').row(receiptColumnNumber))
.element(by.tagName('a'))
.element(by.css('[data-method="receipt"]'))
.click();
}

Expand Down
16 changes: 5 additions & 11 deletions test/end-to-end/patient/invoice/registry.search.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function InvoiceRegistrySearch() {
'use strict';

const params = {
initialBillNumber : 4,
monthBillNumber : 0,
referenceValue : 'TPA2',
serviceValue : 'Test Service',
Expand All @@ -38,17 +37,12 @@ function InvoiceRegistrySearch() {
).to.eventually.equal(number);
}

it('displays all invoices loaded from database', () => {
expectNumberOfGridRows(params.initialBillNumber);
expectNumberOfFilters(0);
});

it('filters invoices by clicking on date buttons', () => {

// set the filters to month
FU.buttons.search();
$('[data-date-range="month"]').click();
FU.buttons.submit();
FU.modal.submit();

expectNumberOfGridRows(params.monthBillNumber);
expectNumberOfFilters(2);
Expand All @@ -62,7 +56,7 @@ function InvoiceRegistrySearch() {
// set the date inputs manually
FU.buttons.search();
FU.input('ModalCtrl.params.billingDateTo', '2015-01-30');
FU.buttons.submit();
FU.modal.submit();

expectNumberOfGridRows(0);
expectNumberOfFilters(1);
Expand All @@ -74,7 +68,7 @@ function InvoiceRegistrySearch() {
it('filters by radio buttons', () => {
FU.buttons.search();
element(by.id('no')).click();
FU.buttons.submit();
FU.modal.submit();

expectNumberOfGridRows(0);
expectNumberOfFilters(1);
Expand All @@ -86,7 +80,7 @@ function InvoiceRegistrySearch() {
it('filters by reference should return a single result', () => {
FU.buttons.search();
FU.input('ModalCtrl.params.reference', 'TPA2');
FU.buttons.submit();
FU.modal.submit();

expectNumberOfGridRows(1);
expectNumberOfFilters(1);
Expand All @@ -99,7 +93,7 @@ function InvoiceRegistrySearch() {
FU.buttons.search();
FU.select('ModalCtrl.params.service_id', 'Test Service');
FU.select('ModalCtrl.params.user_id', 'Super User');
FU.buttons.submit();
FU.modal.submit();

expectNumberOfGridRows(4);
expectNumberOfFilters(2);
Expand Down
7 changes: 2 additions & 5 deletions test/end-to-end/patient/invoice/registry.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,15 @@ describe('Invoice Registry', () => {
it('shows the proof of the invoice correctly', () => {
page.showInvoiceProof(0);
FU.exists(by.css('[data-modal="receipt"]'), true);

// close the modal
$('[data-action="close"]').click();
FU.modal.close();
});

describe('Searching', Search);

it('Credit Note for reverse any transaction in the posting_journal', () => {
element(by.id('TPA1')).click();
FU.input('ModalCtrl.creditNote.description', 'Credit Note Error');
FU.buttons.submit();
FU.modal.submit();
components.notification.hasSuccess();
});

});
9 changes: 4 additions & 5 deletions test/end-to-end/shared/FormUtils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global browser, by, element, protractor */
/* global browser, by, element */
'use strict';

const chai = require('chai');
Expand All @@ -22,23 +22,23 @@ const buttons = {

// This methods are for easily working with modals. Works with the same custom
// data tags used in form buttons.
var modal = {
const modal = {
submit: function submit() { return $('[uib-modal-window] [data-method="submit"]').click(); },
cancel: function cancel() { return $('[uib-modal-window] [data-method="cancel"]').click(); },
close: function close() { return $('[uib-modal-window] [data-method="close"]').click(); },
print: function print() { return $('[uib-modal-window] [data-method="print"]').click(); }
};

// convenience methods to see if the form contains feedback text. Returns locators.
var feedback = {
const feedback = {
success: function success() { return by.css('[data-role="feedback"] > .text-success'); },
error: function error() { return by.css('[data-role="feedback"] > .text-danger'); },
warning: function warning() { return by.css('[data-role="feedback"] > .text-warning'); },
info: function info() { return by.css('[data-role="feedback"] > .text-info'); }
};

// convenience methods to check form element validation states
var validation = {
const validation = {

// an error state is present
error : function error(model) {
Expand Down Expand Up @@ -206,7 +206,6 @@ module.exports = {
).to.eventually.equal(text);
},


// bind commonly used form buttons These require specific data tags to be
// leveraged effectively.
buttons: buttons,
Expand Down
Loading

0 comments on commit 51af694

Please sign in to comment.