From e8417f8f2249bd4498bbdf3d315f39b1e4fd2a16 Mon Sep 17 00:00:00 2001 From: Jonathan Niles Date: Sun, 19 Feb 2017 13:55:12 +0100 Subject: [PATCH] fix(cash): bug in debtor $state transitions This commit fixes another bug caught in $state transitions due to modals being incorrectly $transitioned out of. This makes sure the end to end tests work correctly. --- client/src/partials/cash/cash.routes.js | 100 +++++++++--------- .../partials/cash/modals/invoices.modal.js | 43 ++++---- protractor.conf.js | 57 +++++----- 3 files changed, 97 insertions(+), 103 deletions(-) diff --git a/client/src/partials/cash/cash.routes.js b/client/src/partials/cash/cash.routes.js index 21ba90fe7c..1e3dd42eac 100644 --- a/client/src/partials/cash/cash.routes.js +++ b/client/src/partials/cash/cash.routes.js @@ -3,90 +3,90 @@ angular.module('bhima.routes') $stateProvider .state('cashRegistry', { - url : '/payments', - controller: 'CashPaymentRegistryController as CPRCtrl', - templateUrl: 'partials/cash/payments/registry.html', - params : { + url : '/payments', + controller : 'CashPaymentRegistryController as CPRCtrl', + templateUrl : 'partials/cash/payments/registry.html', + params : { filters : null, - display : null - } + display : null, + }, }) .state('cash', { - url : '/cash', - abstract: true, - controller: 'CashController as CashCtrl', - templateUrl: '/partials/cash/cash.html' + url : '/cash', + abstract : true, + controller : 'CashController as CashCtrl', + templateUrl : '/partials/cash/cash.html', }) .state('cash.select', { - url : '/selection', - params : { id : { value: null } }, - onEnter :['$uibModal', cashboxSelectionModal], - onExit : ['$uibModalStack', closeModal] + url : '/selection', + params : { id: { value: null } }, + onEnter : ['$uibModal', cashboxSelectionModal], + onExit : ['$uibModalStack', closeModal], }) .state('cash.window', { - url : '/:id?', - params : { id : { squash: true, value: null } }, - controller: 'CashController as CashCtrl', - templateUrl: '/partials/cash/cash.html' + url : '/:id?', + params : { id: { squash: true, value: null } }, + controller : 'CashController as CashCtrl', + templateUrl : '/partials/cash/cash.html', }) .state('cash.transfer', { - url : '/:id/transfer', - params : { id : { squash: true, value: null } }, - onEnter :['$state', '$uibModal', transferModal], - onExit : ['$uibModalStack', closeModal] + url : '/:id/transfer', + params : { id: { squash: true, value: null } }, + onEnter : ['$state', '$uibModal', transferModal], + onExit : ['$uibModalStack', closeModal], }) .state('cash.debtors', { - url : '/:id', + url : '/:id/debtors', params : { - id : { squash: true, value: null }, - debtor_uuid: { value: undefined }, - invoices: { value : [] } + id : { squash: true, value: null }, + debtor_uuid : { value: undefined }, + invoices : { value: [] }, }, - onEnter :['$state', '$uibModal', debtorInvoicesModal], - onExit : ['$uibModalStack', closeModal] + onEnter : ['$state', '$uibModal', debtorInvoicesModal], + onExit : ['$uibModalStack', closeModal], }) .state('cash.scan', { - url : '/:id/scan', - params : { id : { squash: true, value: null } }, - onEnter :['$state', '$uibModal', scanCashBarcodeModal], - onExit : ['$uibModalStack', closeModal] + url : '/:id/scan', + params : { id: { squash: true, value: null } }, + onEnter : ['$state', '$uibModal', scanCashBarcodeModal], + onExit : ['$uibModalStack', closeModal], }); }]); function cashboxSelectionModal(Modal) { Modal.open({ - templateUrl: 'partials/cash/modals/selectCashbox.modal.html', - controller: 'SelectCashboxModalController as $ctrl', - backdrop: 'static', - keyboard: false + templateUrl : 'partials/cash/modals/selectCashbox.modal.html', + controller : 'SelectCashboxModalController as $ctrl', + backdrop : 'static', + keyboard : false, }); } function transferModal($state, Modal) { Modal.open({ - controller: 'CashTransferModalController as TransferCtrl', - templateUrl: 'partials/cash/modals/transfer.modal.html', - backdrop: 'static', - keyboard: false + controller : 'CashTransferModalController as TransferCtrl', + templateUrl : 'partials/cash/modals/transfer.modal.html', + backdrop : 'static', + keyboard : false, }); } function scanCashBarcodeModal($state, Modal) { Modal.open({ - controller: 'CashBarcodeScannerModalController as BarcodeModalCtrl', - templateUrl: 'partials/cash/modals/scanBarcode.modal.html', - size : 'lg', - backdrop: 'static', - keyboard: true + controller : 'CashBarcodeScannerModalController as BarcodeModalCtrl', + templateUrl : 'partials/cash/modals/scanBarcode.modal.html', + size : 'lg', + backdrop : 'static', + keyboard : true, }).result.finally(function () { - $state.go('^.window', { id : $state.params.id }); + $state.go('^.window', { id: $state.params.id }); }); } @@ -94,11 +94,11 @@ function debtorInvoicesModal($state, Modal) { Modal.open({ templateUrl : 'partials/cash/modals/invoices.modal.html', controller : 'CashInvoiceModalController as CashInvoiceModalCtrl', - backdrop: 'static', - animation : false, - keyboard: true + backdrop : 'static', + animation : false, + keyboard : true, }).result.finally(function () { - $state.go('^.window', { id : $state.params.id }); + $state.go('^.window', { id: $state.params.id }); }); } diff --git a/client/src/partials/cash/modals/invoices.modal.js b/client/src/partials/cash/modals/invoices.modal.js index 7c9eeb1001..32a0ffde48 100644 --- a/client/src/partials/cash/modals/invoices.modal.js +++ b/client/src/partials/cash/modals/invoices.modal.js @@ -3,17 +3,17 @@ angular.module('bhima.controllers') CashInvoiceModalController.$inject = [ 'DebtorService', 'SessionService', '$timeout', 'NotifyService', '$state', - '$rootScope' + '$rootScope', '$uibModalInstance', ]; /** * @module cash/modals/CashInvoiceModalController * * @description - * This controller is responsible for retrieving a list of debtor invoices - * from the server, and allowing selection of any number of invoices. + * This controller is responsible for retrieving a list of debtor invoices from the server, + * and allowing selection of any number of invoices. */ -function CashInvoiceModalController(Debtors, Session, $timeout, Notify, $state, $rootScope) { +function CashInvoiceModalController(Debtors, Session, $timeout, Notify, $state, $rootScope, Instance) { var vm = this; var debtorId = $state.params.debtor_uuid; @@ -26,21 +26,21 @@ function CashInvoiceModalController(Debtors, Session, $timeout, Notify, $state, // bind methods vm.submit = submit; - vm.cancel = dismiss; + vm.cancel = Instance.dismiss; vm.gridOptions = { - appScopeProvider : vm, - multiSelect: true, - fastWatch: true, - flatEntityAccess: true, - onRegisterApi : onRegisterApi, - enableColumnMenus: false, - columnDefs : [ - { name : 'reference' }, - { name : 'balance', cellFilter: 'currency:' + Session.enterprise.currencyId}, - { name : 'date', cellFilter: 'date' } + appScopeProvider : vm, + multiSelect : true, + fastWatch : true, + flatEntityAccess : true, + onRegisterApi : onRegisterApi, + enableColumnMenus : false, + columnDefs : [ + { name: 'reference' }, + { name: 'balance', cellFilter: 'currency:' + Session.enterprise.currencyId}, + { name: 'date', cellFilter: 'date' }, ], - minRowsToShow : 10 + minRowsToShow : 10, }; function selectionChangeCallback() { @@ -107,21 +107,18 @@ function CashInvoiceModalController(Debtors, Session, $timeout, Notify, $state, // resolve the modal with the selected invoices to add to the cash payment bills function submit() { + var invoices; // we start in a neutral state vm.loading = false; vm.hasError = false; // retrieve the outstanding patient invoices from the ui grid - var invoices = vm.getSelectedRows(); + invoices = vm.getSelectedRows(); - $rootScope.$broadcast('cash:configure', { invoices : invoices }); + $rootScope.$broadcast('cash:configure', { invoices: invoices }); - $state.go('^.window', $state.params); - } - - function dismiss() { - $state.go('^.window', $state.params); + return Instance.close(); } // start up the module diff --git a/protractor.conf.js b/protractor.conf.js index ce6301889c..60341c2f57 100644 --- a/protractor.conf.js +++ b/protractor.conf.js @@ -1,6 +1,4 @@ /* global by,browser, element */ -'use strict'; - const q = require('q'); // we want to make sure we run tests locally, but TravisCI @@ -11,35 +9,35 @@ const q = require('q'); const config = { - specs: ['test/end-to-end/**/*.spec.js'], + specs : ['test/end-to-end/**/*.spec.js'], framework : 'mocha', - baseUrl : 'http://localhost:8080/', + baseUrl : 'http://localhost:8080/', mochaOpts : { - reporter: 'mochawesome-screenshots', - reporterOptions: { - reportDir: `${__dirname}/test/artifacts/`, - reportName: 'mochawesome-end-to-end', - reportTitle: 'Bhima End to End Tests', - takePassedScreenshot: false, - clearOldScreenshots: true, - jsonReport: false + reporter : 'mochawesome-screenshots', + reporterOptions : { + reportDir : `${__dirname}/test/artifacts/`, + reportName : 'mochawesome-end-to-end', + reportTitle : 'Bhima End to End Tests', + takePassedScreenshot : false, + clearOldScreenshots : true, + jsonReport : false, }, - timeout : 30000 + timeout : 30000, }, // default browsers to run - multiCapabilities: [{ - //'browserName': 'firefox', + multiCapabilities : [{ + // 'browserName': 'firefox', // }, { - 'browserName': 'chrome' + 'browserName': 'chrome', }], // this will log the user in to begin with onPrepare : function () { return q.fcall(function () { - browser.get('http://localhost:8080/#/login'); + browser.get('http://localhost:8080/#!/login'); element(by.model('LoginCtrl.credentials.username')).sendKeys('superuser'); element(by.model('LoginCtrl.credentials.password')).sendKeys('superuser'); @@ -48,12 +46,11 @@ const config = { // NOTE - you may need to play with the delay time to get this to work properly // Give this plenty of time to run }).delay(3100); - } + }, }; // configuration for running on SauceLabs via Travis if (process.env.TRAVIS_BUILD_NUMBER) { - // SauceLabs credentials config.sauceUser = process.env.SAUCE_USERNAME; config.sauceKey = process.env.SAUCE_ACCESS_KEY; @@ -64,22 +61,22 @@ if (process.env.TRAVIS_BUILD_NUMBER) { // 'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER, // 'build': process.env.TRAVIS_BUILD_NUMBER, // }, { - browserName: 'chrome', - 'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER, - build: process.env.TRAVIS_BUILD_NUMBER, + browserName : 'chrome', + 'tunnel-identifier' : process.env.TRAVIS_JOB_NUMBER, + build : process.env.TRAVIS_BUILD_NUMBER, }]; // make Travis take screenshots! config.mochaOpts = { - reporter: 'mochawesome-screenshots', - reporterOptions: { - reportDir: `${__dirname}/test/artifacts/`, - reportName: 'protractor-' + new Date().toDateString().replace(/\s/g,'-') + '-' + process.env.TRAVIS_BUILD_NUMBER, - reportTitle: 'Bhima End to End Tests', - takePassedScreenshot: false, - clearOldScreenshots: true + reporter : 'mochawesome-screenshots', + reporterOptions : { + reportDir : `${__dirname}/test/artifacts/`, + reportName : `protractor-${new Date().toDateString().replace(/\s/g,'-')}-${process.env.TRAVIS_BUILD_NUMBER}`, + reportTitle : 'Bhima End to End Tests', + takePassedScreenshot : false, + clearOldScreenshots : true, }, - timeout : 30000 + timeout : 30000, }; }