Skip to content

Commit

Permalink
test(utils): introduce FU.select(model, option)
Browse files Browse the repository at this point in the history
This commit replaces the original FormUtils.select() function with a new
version that takes in two parameters - the ng-model associated with the
select element and the text of the option value to select.  This allows
_much_ stricter tests.

All tests have been migrated to this syntax.
  • Loading branch information
jniles committed May 30, 2016
1 parent a1ad53d commit 5c0053c
Show file tree
Hide file tree
Showing 26 changed files with 212 additions and 471 deletions.
64 changes: 23 additions & 41 deletions client/test/e2e/accounts/accounts.spec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
/* global element, by, browser */

/*
* @todo - this should have it's own Accounts Page Object. It is complex enough.
*/

const chai = require('chai');
const expect = chai.expect;

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

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

describe('Accounts Module', function () {
'use strict';

describe('Accounts', function () {
const path = '#/accounts';
before(() => helpers.navigate(path));

Expand All @@ -21,7 +23,7 @@ describe('Accounts Module', function () {
number : '4503500'
};

const accountIncomeExpence = {
const accountIncomeExpense = {
label : 'Compte Income Expence',
type : 'income/expense',
is_charge : 0,
Expand All @@ -30,20 +32,14 @@ describe('Accounts Module', function () {

const accountRank = 7;

it('successfully creates a new account type balance', function () {

// switch to the create form
it('creates a new account type balance', function () {
FU.buttons.create();

FU.input('AccountsCtrl.account.label', accountBalance.label);
element(by.model('AccountsCtrl.account.type')).element(by.cssContainingText('option', accountBalance.type)).click();
FU.select('AccountsCtrl.account.type', accountBalance.type);
FU.radio('AccountsCtrl.account.is_asset', accountBalance.is_asset);
FU.input('AccountsCtrl.account.number', accountBalance.number);

// select a Reference
FU.select('AccountsCtrl.account.reference_id')
.enabled()
.first()
.click();
FU.select('AccountsCtrl.account.reference_id', 'Reference bilan 1');

// submit the page to the server
FU.buttons.submit();
Expand All @@ -52,21 +48,20 @@ describe('Accounts Module', function () {
FU.exists(by.id('create_success'), true);
});

it('successfully edits an account', function () {
it('edits an account', function () {
element(by.id('account-upd-' + accountRank )).click();

// modify the account name
FU.input('AccountsCtrl.account.label', ' Updated');


element(by.id('locked')).click();
element(by.id('change_account')).click();

// make sure the success message appears
FU.exists(by.id('update_success'), true);
});

it('successfully unlock an account', function () {
it('unlock an account', function () {
element(by.id('account-upd-' + accountRank )).click();
element(by.id('locked')).click();
element(by.id('change_account')).click();
Expand All @@ -75,26 +70,15 @@ describe('Accounts Module', function () {
FU.exists(by.id('update_success'), true);
});

it('successfully creates a new account type income expense', function () {

// swtich to the create form
it('creates a new account type income expense', function () {
FU.buttons.create();
FU.input('AccountsCtrl.account.label', accountIncomeExpence.label);
element(by.model('AccountsCtrl.account.type')).element(by.cssContainingText('option', accountIncomeExpence.type)).click();
FU.input('AccountsCtrl.account.number', accountIncomeExpence.number);
FU.radio('AccountsCtrl.account.is_charge', accountIncomeExpence.is_charge);

// select a Profit Center
FU.select('AccountsCtrl.account.cc_id')
.enabled()
.first()
.click();

// select a Reference
FU.select('AccountsCtrl.account.reference_id')
.enabled()
.first()
.click();

FU.input('AccountsCtrl.account.label', accountIncomeExpense.label);
FU.select('AccountsCtrl.account.type', accountIncomeExpense.type);
FU.input('AccountsCtrl.account.number', accountIncomeExpense.number);
FU.radio('AccountsCtrl.account.is_charge', accountIncomeExpense.is_charge);
FU.select('AccountsCtrl.account.cc_id', 'cost center 1');
FU.select('AccountsCtrl.account.reference_id', 'Reference bilan 1');

// submit the page to the server
FU.buttons.submit();
Expand All @@ -103,12 +87,10 @@ describe('Accounts Module', function () {
FU.exists(by.id('create_success'), true);
});


it('correctly blocks invalid form submission with relevant error classes', function () {
// switch to the create form
it('blocks invalid form submission with relevant error classes', function () {
FU.buttons.create();

// verify form has not been successfully submitted
// verify form has not been submitted
expect(helpers.getCurrentPath()).to.eventually.equal(path);

element(by.id('submit-account')).click();
Expand Down
42 changes: 10 additions & 32 deletions client/test/e2e/cashboxes/cashboxes.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* global element, by, browser */
const chai = require('chai');
const expect = chai.expect;

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

Expand All @@ -13,30 +12,26 @@ describe('Cashbox Module', function () {
before(() => helpers.navigate('#/cashboxes'));

const cashbox = {
label: 'Test Principal Cashbox',
type: 1,
project: 1
label: 'Test Principal Cashbox',
type: 1,
project: 'Test Project A'
};

// clicks the 'update' button on the cashbox at $index n in the table
function update(n) {
return element(by.repeater('box in CashCtrl.cashboxes track by box.id').row(n))
.$$('a')
.click();
}

it('successfully creates a new cashbox', function () {
it('creates a new cashbox', function () {

// switch to the create form
FU.buttons.create();

FU.input('CashCtrl.box.label', cashbox.label);
FU.radio('CashCtrl.box.type', cashbox.type);

// select the first non-disabled option
FU.select('CashCtrl.box.project_id')
.enabled()
.first()
.click();
FU.select('CashCtrl.box.project_id', 'Test Project A');

// submit the page to the server
FU.buttons.submit();
Expand Down Expand Up @@ -81,17 +76,8 @@ describe('Cashbox Module', function () {
FU.exists(by.css('[uib-modal-window]'), true);
FU.exists(by.name('CashboxModalForm'), true);

// choose a random cash account
FU.select('CashboxModalCtrl.data.account_id')
.enabled()
.last()
.click();

// choose a random transfer account
FU.select('CashboxModalCtrl.data.transfer_account_id')
.enabled()
.last()
.click();
FU.select('CashboxModalCtrl.data.account_id', 'Test Gain Account');
FU.select('CashboxModalCtrl.data.transfer_account_id', 'Test Loss Account');

// submit the modal
FU.modal.submit();
Expand All @@ -113,11 +99,7 @@ describe('Cashbox Module', function () {
// confirm that the modal appears
FU.exists(by.css('[uib-modal-window]'), true);

// choose a random cash account
FU.select('CashboxModalCtrl.data.account_id')
.enabled()
.first()
.click();
FU.select('CashboxModalCtrl.data.account_id', 'Test Item Account');

// submit the modal
FU.modal.submit();
Expand All @@ -130,11 +112,7 @@ describe('Cashbox Module', function () {
FU.validation.ok('CashboxModalCtrl.data.account_id');
FU.validation.error('CashboxModalCtrl.data.transfer_account_id');

// choose a random transfer account
FU.select('CashboxModalCtrl.data.transfer_account_id')
.enabled()
.first()
.click();
FU.select('CashboxModalCtrl.data.transfer_account_id', 'Test Expense Accounts');

// submit the modal
FU.modal.submit();
Expand Down
2 changes: 1 addition & 1 deletion client/test/e2e/debtor_groups/debtorGroups.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ helpers.configure(chai);
const FormUtils = require('../shared/FormUtils');
const components = require('../shared/components');

describe('Debtor Groups', function () {
describe.skip('Debtor Groups', function () {
'use strict';

before(() => helpers.navigate('#/debtor_groups'));
Expand Down
31 changes: 11 additions & 20 deletions client/test/e2e/debtors/debtorgroups.spec.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
/* global browser, element, by, protractor */
var chai = require('chai');
var expect = chai.expect;

var helpers = require('../shared/helpers');
/* global browser, element, by */
const chai = require('chai');
const expect = chai.expect;
const helpers = require('../shared/helpers');
helpers.configure(chai);

var components = require('../shared/components');
var FU = require('../shared/FormUtils');
const components = require('../shared/components');
const FU = require('../shared/FormUtils');

describe('Debtor Groups Management', function () {
'use strict';

let initialGroups = 3;
let initialGroups = 2;

/** @const */
var root = '#/debtors/groups';
before(function () { helpers.navigate(root); });
const root = '#/debtors/groups';
before(() => helpers.navigate(root));

it('lists base test debtor groups', function () {
expect(element.all(by.css('[data-group-entry]')).count()).to.eventually.equal(initialGroups);
Expand All @@ -24,21 +22,14 @@ describe('Debtor Groups Management', function () {
it('creates a debtor group', function () {
FU.buttons.create();

// Account selection
/** @todo Suggested helper AccountSelect.selectFirst('setInput') */
var groupAccount = element(by.css('[data-component-find-account]'));
var input = groupAccount.element(by.model('GroupEditCtrl.group.account_id'));
input.sendKeys('47001');
var option = groupAccount.all(by.repeater('match in matches track by $index')).first();
option.click();

FU.typeahead('GroupEditCtrl.group.account_id', '47001');
FU.input('GroupEditCtrl.group.name', 'E2E Debtor Group');
FU.input('GroupEditCtrl.group.max_credit', '1200');
FU.input('GroupEditCtrl.group.note', 'This debtor group was created by an automated end to end test.');
FU.input('GroupEditCtrl.group.phone', '+243 834 443');
FU.input('GroupEditCtrl.group.email', 'e2e@email.com');

var select = FU.select('GroupEditCtrl.group.price_list_uuid').enabled().first().click();
FU.select('GroupEditCtrl.group.price_list_uuid', 'Test Price List');

FU.buttons.submit();

Expand Down
Loading

0 comments on commit 5c0053c

Please sign in to comment.