Skip to content

Commit

Permalink
e2e tests for the opening balance
Browse files Browse the repository at this point in the history
  • Loading branch information
mbayopanda authored and jniles committed Sep 28, 2016
1 parent c788c20 commit b1177db
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 20 deletions.
4 changes: 2 additions & 2 deletions client/src/partials/fiscal/fiscal.manage.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@
<p><strong>{{ "FORM.INFO.OTHER_ACTIONS" | translate }}</strong></p>
<p>
<!-- close the fiscal year -->
<a class="btn btn-default" href>
<a class="btn btn-default" data-action="closing-fiscal-year" href>
<i class="fa fa-lock"></i>
{{ "FORM.INFO.CLOSE_FISCAL_YEAR" | translate }}
</a>

<!-- opening balance -->
<a class="btn btn-default" ui-sref="fiscal.openingBalance" href>
<a class="btn btn-default" data-action="opening-balance" ui-sref="fiscal.openingBalance" href>
<i class="fa fa-balance-scale"></i>
{{ "FORM.INFO.VIEW_BEGINNING_BALACE" | translate}}
</a>
Expand Down
12 changes: 6 additions & 6 deletions client/src/partials/fiscal/fiscal.openingBalance.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{{ 'FORM.BUTTONS.SEARCH' | translate }} <i class="fa fa-search"></i>
</span>

<span class="text-action" ng-show="!FiscalOBCtrl.previousFiscalYearExist" style="margin-left: 15px;" ng-click="FiscalOBCtrl.toggleEditBalance()">
<span class="text-action" data-action="edit-opening-balance" ng-show="!FiscalOBCtrl.previousFiscalYearExist" style="margin-left: 15px;" ng-click="FiscalOBCtrl.toggleEditBalance()">
{{ 'FORM.BUTTONS.EDIT' | translate }} <i class="fa fa-edit"></i>
</span>
</div>
Expand All @@ -27,7 +27,7 @@
<section>

<div
id="account-grid"
id="account-balance-grid"
style="height : 600px;"
ui-grid="FiscalOBCtrl.gridOptions">
</div>
Expand All @@ -39,13 +39,13 @@
<div ng-class="{'text-success': FiscalOBCtrl.balanced, 'text-danger': !FiscalOBCtrl.balanced}">
<span ng-show="OpeningAccountForm.$submitted" >
<i class="fa" ng-class="{'fa-check': FiscalOBCtrl.balanced, 'fa-warning': !FiscalOBCtrl.balanced}"></i>
<span ng-show="FiscalOBCtrl.balanced">{{ 'ACCOUNT.BALANCED' | translate }}</span>
<span ng-show="!FiscalOBCtrl.balanced && FiscalOBCtrl.hasPositive">{{ 'ACCOUNT.NOT_BALANCED' | translate }}</span>
<span ng-show="!FiscalOBCtrl.balanced && !FiscalOBCtrl.hasPositive">{{ 'ACCOUNT.NOT_POSITIVE' | translate }}</span>
<span data-status="balanced" ng-show="FiscalOBCtrl.balanced">{{ 'ACCOUNT.BALANCED' | translate }}</span>
<span data-status="not-balanced" ng-show="!FiscalOBCtrl.balanced && FiscalOBCtrl.hasPositive">{{ 'ACCOUNT.NOT_BALANCED' | translate }}</span>
<span data-status="not-positive" ng-show="!FiscalOBCtrl.balanced && !FiscalOBCtrl.hasPositive">{{ 'ACCOUNT.NOT_POSITIVE' | translate }}</span>
</span>
</div>

<button type="submit" ng-disabled="!FiscalOBCtrl.editBalanceEnabled && !FiscalOBCtrl.previousFiscalYearExist" class="btn btn-primary">
<button type="submit" data-method="submit" ng-disabled="!FiscalOBCtrl.editBalanceEnabled && !FiscalOBCtrl.previousFiscalYearExist" class="btn btn-primary">
<span ng-show="!FiscalOBCtrl.previousFiscalYearExist">{{ 'FORM.BUTTONS.SUBMIT' | translate }}</span>
<span ng-show="FiscalOBCtrl.previousFiscalYearExist">{{ 'FORM.BUTTONS.IMPORT' | translate }}</span>
</button>
Expand Down
8 changes: 7 additions & 1 deletion client/src/partials/fiscal/fiscal.openingBalance.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ function FiscalOpeningBalanceController($state, Accounts, AccountStore, Fiscal,
function submit(form) {
vm.balanced = hasBalancedAccount();

if (!vm.balanced) { return ; }
if (!vm.balanced && vm.hasPositive) {
Notify.danger('ACCOUNT.NOT_BALANCED');
return;
} else if (!vm.balanced && !vm.hasPositive) {
Notify.danger('ACCOUNT.NOT_POSITIVE');
return;
}

// set the fiscal year opening balance
Fiscal.setOpeningBalance({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
ng-hide="row.entity.type === 'title'"
ng-disabled="!grid.appScope.editBalanceEnabled || grid.appScope.previousFiscalYearExist"
ng-model="row.entity.credit"
data-credit-account="{{row.entity.id}}"
class="form-control text-right"
type="number">
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
ng-hide="row.entity.type === 'title'"
ng-disabled="!grid.appScope.editBalanceEnabled || grid.appScope.previousFiscalYearExist"
ng-model="row.entity.debit"
data-debit-account="{{row.entity.id}}"
class="form-control text-right"
type="number">
</div>
2 changes: 1 addition & 1 deletion server/controllers/finance/fiscal.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ function setOpeningBalance(req, res, next) {
.then(hasPrevious => {

if (hasPrevious) {
// load from the period N+1 into period 0
// load from the period N+1 of the year N-1 into period 0 of the year N
return loadOpeningBalance(fiscalYear);

} else {
Expand Down
20 changes: 10 additions & 10 deletions server/models/test/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -421,17 +421,17 @@ INSERT INTO cash (uuid, project_id, reference, date, debtor_uuid, currency_id, a
(@cash_payment, 1, 1, '2016-01-09 14:33:13', HUID('3be232f9-a4b9-4af6-984c-5d3f87d5c107'), 1, 100, 1, 2, "Some cool description", 1);

INSERT INTO `posting_journal` VALUES
(HUID(UUID()),1,1,1,'TRANS1','2016-01-09 14:35:55',@first_invoice, 'description x',3631,75.0000,0.0000,75.0000,0.0000,2,HUID('3be232f9-a4b9-4af6-984c-5d3f87d5c107'),'D',NULL,NULL,1,2,1,NULL),
(HUID(UUID()),1,1,1,'TRANS1','2016-01-09 14:35:55',@first_invoice,'description x',3638,0.0000,75.0000,0.0000,75.0000,2,NULL,NULL,NULL,NULL,1,2,1,NULL),
(HUID(UUID()),1,1,1,'TRANS2','2016-01-09 17:04:27',@second_invoice,'description x',3631,25.0000,0.0000,25.0000,0.0000,2,HUID('3be232f9-a4b9-4af6-984c-5d3f87d5c107'),'D',NULL,NULL,1,2,1,NULL),
(HUID(UUID()),1,1,1,'TRANS2','2016-01-09 17:04:27',@second_invoice,'description x',3638,0.0000,25.0000,0.0000,25.0000,2,NULL,NULL,NULL,NULL,1,2,1,NULL),
(HUID(UUID()),1,1,16,'TRANS1','2016-01-09 14:35:55',@first_invoice, 'description x',3631,75.0000,0.0000,75.0000,0.0000,2,HUID('3be232f9-a4b9-4af6-984c-5d3f87d5c107'),'D',NULL,NULL,1,2,1,NULL),
(HUID(UUID()),1,1,16,'TRANS1','2016-01-09 14:35:55',@first_invoice,'description x',3638,0.0000,75.0000,0.0000,75.0000,2,NULL,NULL,NULL,NULL,1,2,1,NULL),
(HUID(UUID()),1,1,16,'TRANS2','2016-01-09 17:04:27',@second_invoice,'description x',3631,25.0000,0.0000,25.0000,0.0000,2,HUID('3be232f9-a4b9-4af6-984c-5d3f87d5c107'),'D',NULL,NULL,1,2,1,NULL),
(HUID(UUID()),1,1,16,'TRANS2','2016-01-09 17:04:27',@second_invoice,'description x',3638,0.0000,25.0000,0.0000,25.0000,2,NULL,NULL,NULL,NULL,1,2,1,NULL),
-- vouchers data
(HUID(UUID()),1,1,1,'TRANS3','2016-01-09 17:04:27',@first_voucher,'description x',3627,100.0000,0.0000,100.0000,0.0000,2,NULL,NULL,NULL,'Sample voucher data one',1,2,1,NULL),
(HUID(UUID()),1,1,1,'TRANS3','2016-01-09 17:04:27',@first_voucher,'description x',3628,0.0000,100.0000,0.0000,100.0000,2,NULL,NULL,NULL,'Sample voucher data one',1,2,1,NULL),
(HUID(UUID()),1,1,1,'TRANS4','2016-01-09 17:04:27',@second_voucher,'description x',3627,200.0000,0.0000,200.0000,0.0000,2,NULL,NULL,NULL,'Sample voucher data two',1,2,1,NULL),
(HUID(UUID()),1,1,1,'TRANS4','2016-01-09 17:04:27',@second_voucher,'description x',3628,0.0000,200.0000,0.0000,200.0000,2,NULL,NULL,NULL,'Sample voucher data two',1,2,1,NULL),
(HUID(UUID()),1,1,1,'TRANS5','2016-01-09 17:04:27',@third_voucher,'description x',3627,300.0000,0.0000,300.0000,0.0000,2,NULL,'D',NULL,'Sample voucher data three',1,2,1,NULL),
(HUID(UUID()),1,1,1,'TRANS5','2016-02-09 17:04:27',@third_voucher,'description x',3628,0.0000,300.0000,0.0000,300.0000,2,NULL,NULL,NULL,'Sample voucher data three',1,2,1,NULL);
(HUID(UUID()),1,1,16,'TRANS3','2016-01-09 17:04:27',@first_voucher,'description x',3627,100.0000,0.0000,100.0000,0.0000,2,NULL,NULL,NULL,'Sample voucher data one',1,2,1,NULL),
(HUID(UUID()),1,1,16,'TRANS3','2016-01-09 17:04:27',@first_voucher,'description x',3628,0.0000,100.0000,0.0000,100.0000,2,NULL,NULL,NULL,'Sample voucher data one',1,2,1,NULL),
(HUID(UUID()),1,1,16,'TRANS4','2016-01-09 17:04:27',@second_voucher,'description x',3627,200.0000,0.0000,200.0000,0.0000,2,NULL,NULL,NULL,'Sample voucher data two',1,2,1,NULL),
(HUID(UUID()),1,1,16,'TRANS4','2016-01-09 17:04:27',@second_voucher,'description x',3628,0.0000,200.0000,0.0000,200.0000,2,NULL,NULL,NULL,'Sample voucher data two',1,2,1,NULL),
(HUID(UUID()),1,1,16,'TRANS5','2016-01-09 17:04:27',@third_voucher,'description x',3627,300.0000,0.0000,300.0000,0.0000,2,NULL,'D',NULL,'Sample voucher data three',1,2,1,NULL),
(HUID(UUID()),1,1,16,'TRANS5','2016-02-09 17:04:27',@third_voucher,'description x',3628,0.0000,300.0000,0.0000,300.0000,2,NULL,NULL,NULL,'Sample voucher data three',1,2,1,NULL);

-- zones des santes SNIS
INSERT INTO `mod_snis_zs` VALUES
Expand Down
84 changes: 84 additions & 0 deletions test/end-to-end/fiscalYears/fiscalYears.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,88 @@ describe('Fiscal Year', function () {
components.modalAction.confirm();
components.notification.hasSuccess();
});

it('set the opening balance for the first fiscal year', () => {
helpers.navigate(path);

// the last in the list is the oldest
var updateButton = element.all(by.css('[data-fiscal-entry]'));
updateButton.all(by.css('[data-method="update"]')).last().click();

// click on the opening balance button
element(by.css('[data-action="opening-balance"]')).click();

// activate the edition of the opening balance
element(by.css('[data-action="edit-opening-balance"]')).click();

// actions in the grid
let account1 = 3627;
let account2 = 3628;
let account3 = 3630;

element(by.css(`[data-debit-account="${account1}"]`)).clear().sendKeys(150);
element(by.css(`[data-debit-account="${account2}"]`)).clear().sendKeys(150);
element(by.css(`[data-credit-account="${account3}"]`)).clear().sendKeys(300);

FU.buttons.submit();
components.notification.hasSuccess();

});

it('forbid not balanced submission', () => {
helpers.navigate(path);

// the last in the list is the oldest
var updateButton = element.all(by.css('[data-fiscal-entry]'));
updateButton.all(by.css('[data-method="update"]')).last().click();

// click on the opening balance button
element(by.css('[data-action="opening-balance"]')).click();

// activate the edition of the opening balance
element(by.css('[data-action="edit-opening-balance"]')).click();

// actions in the grid
let account1 = 3627;
let account2 = 3628;
let account3 = 3630;

element(by.css(`[data-debit-account="${account1}"]`)).clear().sendKeys(150);
element(by.css(`[data-debit-account="${account2}"]`)).clear().sendKeys(150);
element(by.css(`[data-credit-account="${account3}"]`)).clear().sendKeys(200);

FU.buttons.submit();
components.notification.hasDanger();
expect(element(by.css('[data-status="not-balanced"]')).isPresent()).to.eventually.equal(true);

});

it('forbid negative value for total debit or total credit', () => {
helpers.navigate(path);

// the last in the list is the oldest
var updateButton = element.all(by.css('[data-fiscal-entry]'));
updateButton.all(by.css('[data-method="update"]')).last().click();

// click on the opening balance button
element(by.css('[data-action="opening-balance"]')).click();

// activate the edition of the opening balance
element(by.css('[data-action="edit-opening-balance"]')).click();

// actions in the grid
let account1 = 3627;
let account2 = 3628;
let account3 = 3630;

element(by.css(`[data-debit-account="${account1}"]`)).clear().sendKeys(150);
element(by.css(`[data-debit-account="${account2}"]`)).clear().sendKeys(150);
element(by.css(`[data-credit-account="${account3}"]`)).clear().sendKeys(-200);

FU.buttons.submit();
components.notification.hasDanger();
expect(element(by.css('[data-status="not-positive"]')).isPresent()).to.eventually.equal(true);

});

});

0 comments on commit b1177db

Please sign in to comment.