Skip to content

Commit

Permalink
fix(test): update tests to standards + ng 1.6.x
Browse files Browse the repository at this point in the history
This commit upgrades our tests to use ES6 for many of the tests, plus
use the new hashbang routing of angular 1.6.x.  It also includes the
stateEvents.js file while we migrate to the new ui-router transitions
onEnter and onExit states.

One failing test to go!
  • Loading branch information
Jonathan Niles authored and jniles committed Feb 19, 2017
1 parent a0c49e9 commit 08d9eb9
Show file tree
Hide file tree
Showing 44 changed files with 425 additions and 486 deletions.
2 changes: 1 addition & 1 deletion client/src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@
"SIZE_PB" : "Po",
"SOLD" : "Solde",
"SPOUSE" : "Nom de l'époux(se)",
"SPOUSE_EMPLOYER" : "Employeur(époux(se))",
"SPOUSE_EMPLOYER" : "Employeur (époux(se))",
"SPOUSE_PROFESSION" : "Profession (époux(se))",
"START" : "Début",
"STATUS" : "Etat",
Expand Down
6 changes: 4 additions & 2 deletions client/src/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var bhima = angular.module('bhima', [
'ui.grid.edit', 'ui.grid.grouping', 'ui.grid.treeView', 'ui.grid.cellNav',
'ui.grid.pagination', 'ui.grid.moveColumns', 'angularMoment', 'ngMessages',
'growlNotifications', 'ngAnimate', 'ngSanitize', 'ui.select', 'ngTouch',
'ui.router.state.events',
]);

function bhimaConfig($stateProvider, $urlMatcherFactoryProvider) {
Expand Down Expand Up @@ -245,7 +246,8 @@ function startupConfig($rootScope, $state, $uibModalStack, SessionService, amMom
// trigger a $state.go() to the login state, it will not be stopped - the
// $locationChangeStart event will only prevent the URL from changing ... not
// the actual state transition! So, we need this to stop $stateChange events.
$rootScope.$on('$stateChangeStart', (event, next) => {
// TODO - migrate this to $transitions.on()
$rootScope.$on('$stateChangeStart', function (event, next) {
var isLoggedIn = !!SessionService.user;
var isLoginState = next.name.indexOf('login') !== -1;

Expand Down Expand Up @@ -313,7 +315,7 @@ function constantConfig() {
TITLE : 4,
},
purchase : {
GRID_HEIGHT : 200,
GRID_HEIGHT: 200,
},
settings : {
CONTACT_EMAIL : 'developers@imaworldhealth.org',
Expand Down
53 changes: 26 additions & 27 deletions client/src/partials/fiscal/fiscal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ angular.module('bhima.controllers')
.controller('FiscalController', FiscalController);

FiscalController.$inject = [
'$state', 'FiscalService', 'ModalService', 'NotifyService', '$window'
'$state', 'FiscalService', 'ModalService', 'NotifyService', '$window',
];

function FiscalController($state, fiscalService, ModalService, Notify, $window) {
function FiscalController($state, Fiscal, ModalService, Notify, $window) {
var vm = this;
var today = new Date();

Expand All @@ -27,21 +27,20 @@ function FiscalController($state, fiscalService, ModalService, Notify, $window)

// refresh Fiscal Year
function refreshFiscalYear() {
return fiscalService.read(null,{ detailed : 1 })
.then(function (fiscalYears) {

vm.fiscalYears = fiscalYears;
});
return Fiscal.read(null,{ detailed: 1 })
.then(function (fiscalYears) {
vm.fiscalYears = fiscalYears;
});
}

// Get the fiscal Year By Date
fiscalService.fiscalYearDate({date : today})
.then(function (current) {
vm.current = current;
vm.currentFiscalYearId = vm.current[0].fiscal_year_id;
vm.previousFiscalYearId = vm.current[0].previous_fiscal_year_id;
})
.catch(Notify.handleError);
Fiscal.fiscalYearDate({ date: today })
.then(function (current) {
vm.current = current;
vm.currentFiscalYearId = vm.current[0].fiscal_year_id;
vm.previousFiscalYearId = vm.current[0].previous_fiscal_year_id;
})
.catch(Notify.handleError);

// switch to delete warning mode
function del(fiscal) {
Expand All @@ -50,14 +49,14 @@ function FiscalController($state, fiscalService, ModalService, Notify, $window)
// if the user clicked cancel, reset the view and return
if (!bool) { return; }

fiscalService.delete(fiscal.id)
.then(function () {
Notify.success('FORM.INFO.DELETE_SUCCESS');
return refreshFiscalYear();
})
.catch(function (error) {
Notify.danger('FISCAL.CAN_NOT_DELETE_FY');
});
Fiscal.delete(fiscal.id)
.then(function () {
Notify.success('FORM.INFO.DELETE_SUCCESS');
return refreshFiscalYear();
})
.catch(function (error) {
Notify.danger('FISCAL.CAN_NOT_DELETE_FY');
});
});
}

Expand Down Expand Up @@ -93,11 +92,11 @@ function FiscalController($state, fiscalService, ModalService, Notify, $window)
vm.nbMonthDesc = 'down';
}

fiscalService.read(null, option)
.then(function (fiscalYears) {
vm.fiscalYears = fiscalYears;
})
.catch(Notify.handleError);
Fiscal.read(null, option)
.then(function (fiscalYears) {
vm.fiscalYears = fiscalYears;
})
.catch(Notify.handleError);
}

refreshFiscalYear();
Expand Down
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 @@ -74,10 +74,10 @@
</a>

<!-- opening balance -->
<a class="btn btn-default" data-action="opening-balance" ui-sref="fiscal.openingBalance" href>
<button type="button" class="btn btn-default" data-action="opening-balance" ui-sref="fiscal.openingBalance({ id: FiscalManageCtrl.fiscal.id })">
<i class="fa fa-balance-scale"></i>
{{ "FORM.INFO.VIEW_BEGINNING_BALACE" | translate}}
</a>
</button>
</p>
</div>
</div>
Expand Down
23 changes: 9 additions & 14 deletions client/src/partials/fiscal/fiscal.manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ angular.module('bhima.controllers')
.controller('FiscalManagementController', FiscalManagementController);

FiscalManagementController.$inject = [
'$state', 'FiscalService', 'NotifyService', 'ModalService', 'util', 'moment'
'$state', 'FiscalService', 'NotifyService', 'ModalService', 'util', 'moment',
];

/**
Expand Down Expand Up @@ -35,7 +35,6 @@ function FiscalManagementController($state, Fiscal, Notify, Modal, util, moment)
* @description init data for the module
*/
function init() {

if (id && vm.isUpdateState) {
// concerned fiscal year
Fiscal.read(id)
Expand All @@ -58,7 +57,6 @@ function FiscalManagementController($state, Fiscal, Notify, Modal, util, moment)
.concat(moment(fy.end_date).format('DD MMM YYYY').toString(), ')');
return fy;
});

})
.catch(Notify.handleError);
}
Expand All @@ -68,16 +66,13 @@ function FiscalManagementController($state, Fiscal, Notify, Modal, util, moment)
* @description launch the modal for closing a fiscal year
*/
function closingFiscalYear() {

if (!vm.isUpdateState) { return; }

Modal.openClosingFiscalYear(vm.fiscal)
.then(function (res) {
if (!res) { return; }

$state.go('fiscal.list', null, { reload: true });
});

.then(function (res) {
if (!res) { return; }
$state.go('fiscal.list', null, { reload: true });
});
}

/**
Expand All @@ -100,7 +95,7 @@ function FiscalManagementController($state, Fiscal, Notify, Modal, util, moment)

// ensure all Angular form validation checks have passed
if (form.$invalid) {
Notify.danger('FORM.ERRORS.RECORD_ERROR');
Notify.danger('FORM.ERRORS.RECORD_ERROR');
return;
}

Expand All @@ -109,16 +104,16 @@ function FiscalManagementController($state, Fiscal, Notify, Modal, util, moment)

var promise = isUpdate ? Fiscal.update(id, vm.fiscal) : Fiscal.create(vm.fiscal);

return promise.then(function () {
return promise
.then(function () {
Notify.success(isUpdate ? 'FORM.INFO.UPDATE_SUCCESS' : 'FORM.INFO.CREATE_SUCCESS');

// navigate back to list view
$state.go('fiscal.list', null, {reload : true});
$state.go('fiscal.list', null, { reload: true });
})
.catch(Notify.handleError);
}

// excecute
init();

}
42 changes: 22 additions & 20 deletions client/src/partials/fiscal/fiscal.routes.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
angular.module('bhima.routes')
.config([ '$stateProvider', function ($stateProvider) {

.config(['$stateProvider', function ($stateProvider) {
$stateProvider
.state('fiscal', {
url : '/fiscal',
abstract : true,
params : {
id : { squash : true, value : null }
},
controller: 'FiscalController as FiscalCtrl',
templateUrl: 'partials/fiscal/fiscal.html'
url : '/fiscal',
abstract : true,
controller : 'FiscalController as FiscalCtrl',
templateUrl : 'partials/fiscal/fiscal.html',
})
.state('fiscal.create', {
url : '/create',
controller : 'FiscalManagementController as FiscalManageCtrl',
templateUrl : 'partials/fiscal/fiscal.manage.html'
url : '/create',
controller : 'FiscalManagementController as FiscalManageCtrl',
templateUrl : 'partials/fiscal/fiscal.manage.html',
})
.state('fiscal.list', {
url : '',
templateUrl : 'partials/fiscal/fiscal.list.html'
url : '',
templateUrl : 'partials/fiscal/fiscal.list.html',
})
.state('fiscal.update', {
url : '/:id/update',
controller : 'FiscalManagementController as FiscalManageCtrl',
url : '/:id/update',
controller : 'FiscalManagementController as FiscalManageCtrl',
templateUrl : 'partials/fiscal/fiscal.manage.html',
data : { label : null }
data : { label: null },
params : {
id : { squash: true, value: null },
},
})
.state('fiscal.openingBalance', {
url : '/:id/opening_balance',
controller : 'FiscalOpeningBalanceController as FiscalOBCtrl',
templateUrl : 'partials/fiscal/fiscal.openingBalance.html'
url : '/:id/opening_balance',
controller : 'FiscalOpeningBalanceController as FiscalOBCtrl',
templateUrl : 'partials/fiscal/fiscal.openingBalance.html',
params : {
id : { squash: true, value: null },
},
});
}]);
4 changes: 4 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ const paths = {

// Angular UI
'client/vendor/angular-ui-router/release/angular-ui-router.min.js',

// @TODO - rm this
'client/vendor/angular-ui-router/release/stateEvents.min.js',

'client/vendor/angular-bootstrap/ui-bootstrap-tpls.js',
'client/vendor/angular-ui-grid/ui-grid.min.js',

Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/IncomeExpense/IncomeExpense.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ helpers.configure(chai);
describe.skip('Income Expense report generator', () => {
'use strict';

before(() => helpers.navigate('#/finance/reports/incomeExpense'));
before(() => helpers.navigate('#!/finance/reports/incomeExpense'));

it('GET /finance/incomeExpense return incomeExpense report at the client', () => {

Expand Down
9 changes: 3 additions & 6 deletions test/end-to-end/agedDebtors/agedDebtors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@ const GU = require('../shared/GridUtils');
helpers.configure(chai);

describe('Aged Debtors Report', () => {
'use strict';

function getInvoiceNumber(gridId) {
return GU.getRows(gridId).count();
}
const numReports = 1;

before(() => helpers.navigate('#/reports/agedDebtors'));
before(() => helpers.navigate('#!/reports/agedDebtors'));

// TODO client side report removed, required update for server PDF success
it('GET /reports/agedDebtors Create a new Report of Aged Debtors', () => {

let date = new Date('12-31-2016');
const date = new Date('12-31-2016');
element(by.id('create-report')).click();

FU.input('ReportConfigCtrl.label', 'Report Debts of December 31, 2016');
Expand All @@ -33,4 +30,4 @@ describe('Aged Debtors Report', () => {
FU.modal.submit();
expect(getInvoiceNumber('report-grid')).to.eventually.equal(numReports);
});
});
});
Loading

0 comments on commit 08d9eb9

Please sign in to comment.