Skip to content

Commit

Permalink
fix(test): Update test
Browse files Browse the repository at this point in the history
Update the end to end test to reflect the change made on our depot select inventory select
components and inventory select
  • Loading branch information
DedrickEnc committed Aug 9, 2017
1 parent e4a2210 commit 20a206c
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 54 deletions.
16 changes: 5 additions & 11 deletions client/src/js/components/bhDepotSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,32 @@ angular.module('bhima.components')
controller : DepotSelectController,
transclude : true,
bindings : {
depotId : '<',
disable : '<?',
depotUuid : '<',
onSelectCallback : '&',
name : '@?',
required : '<?',
},
});

DepotSelectController.$inject = [
'DepotService'
'DepotService', 'NotifyService'
];

/**
* Depot selection component
*/
function DepotSelectController(Depots) {
function DepotSelectController(Depots, Notify) {
var $ctrl = this;

$ctrl.$onInit = function onInit() {
// fired when a depot has been selected
$ctrl.onSelectCallback = $ctrl.onSelectCallback || angular.noop;

// default for form name
$ctrl.name = $ctrl.name || 'DepotForm';

// load all Depots
Depots.read()
.then(function (depots) {
$ctrl.depots = depots;
});

$ctrl.valid = true;
})
.catch(Notify.handleError);
};

// fires the onSelectCallback bound to the component boundary
Expand Down
16 changes: 5 additions & 11 deletions client/src/js/components/bhInventorySelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,32 @@ angular.module('bhima.components')
controller : InventorySelectController,
transclude : true,
bindings : {
inventoryId : '<',
disable : '<?',
inventoryUuid : '<',
onSelectCallback : '&',
name : '@?',
required : '<?',
},
});

InventorySelectController.$inject = [
'InventoryService'
'InventoryService', 'NotifyService'
];

/**
* Inventory selection component
*/
function InventorySelectController(Inventory) {
function InventorySelectController(Inventory, Notify) {
var $ctrl = this;

$ctrl.$onInit = function onInit() {
// fired when an inventory has been selected
$ctrl.onSelectCallback = $ctrl.onSelectCallback || angular.noop;

// default for form name
$ctrl.name = $ctrl.name || 'InventoryForm';

// load all inventories
Inventory.read()
.then(function (inventories) {
$ctrl.inventories = inventories;
});

$ctrl.valid = true;
})
.catch(Notify.handleError);
};

// fires the onSelectCallback bound to the component boundary
Expand Down
10 changes: 5 additions & 5 deletions client/src/modules/stock/lots/modals/search.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
<div class="tab-body">
<!-- depot -->
<bh-depot-select
depot-id="$ctrl.searchQueries.depot_uuid"
name="depot_id"
depot-uuid="$ctrl.searchQueries.depot_uuid"
required="false"
on-select-callback="$ctrl.onSelectDepot(depot)">
<bh-clear on-clear="$ctrl.clear('depot_uuid')"></bh-clear>
</bh-depot-select>

<!-- Inventaire -->
<bh-inventory-select
inventory-id="$ctrl.searchQueries.inventory_uuid"
name="inventory_id"
on-select-callback="$ctrl.onSelectInventory(inventory)">
inventory-uuid="$ctrl.searchQueries.inventory_uuid"
on-select-callback="$ctrl.onSelectInventory(inventory)"
required="false">
<bh-clear on-clear="$ctrl.clear('inventory_uuid')"></bh-clear>
</bh-inventory-select>

Expand Down
3 changes: 0 additions & 3 deletions client/src/modules/stock/lots/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ function StockLotsController(Stock, Notify,
var cacheKey = 'lot-grid';
var gridColumns;
var state;
var FILTER_BAR_HEIGHT = bhConstants.grid.FILTER_BAR_HEIGHT;

// grouping box
vm.groupingBox = [
Expand All @@ -33,8 +32,6 @@ function StockLotsController(Stock, Notify,
vm.clearGridState = clearGridState;
vm.filters = { lang: Languages.key };
vm.formatedFilters = [];
vm.gridApi = {};
vm.gridOptions = {};

// grid columns
var columns = [
Expand Down
18 changes: 11 additions & 7 deletions client/src/modules/templates/bhDepotSelect.tmpl.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
<div ng-form="{{ $ctrl.name }}" bh-depot-select ng-model-options="{ updateOn: 'default' }">
<div ng-form="DepotForm" bh-depot-select ng-model-options="{ updateOn: 'default' }">
<div
class="form-group"
ng-class="{ 'has-error' : DepotForm.$$parent.$submitted && DepotForm.depot_id.$invalid }">
ng-class="{ 'has-error' : DepotForm.$$parent.$submitted && DepotForm.depot_uuid.$invalid }">

<label class="control-label" translate>
STOCK.DEPOT
</label>

<ng-transclude></ng-transclude>
<ui-select name="depot_id"
ng-model="$ctrl.depotId"
on-select="$ctrl.onSelect($item, $model)">
<ui-select-match placeholder="{{ 'FORM.SELECT.DEPOT' | translate }}">{{$select.selected.text}}</span></ui-select-match>
<ui-select
name="depot_uuid"
ng-model="$ctrl.depotUuid"
on-select="$ctrl.onSelect($item, $model)"
ng-required="$ctrl.required">
<ui-select-match placeholder="{{ 'FORM.SELECT.DEPOT' | translate }}">
<span>{{$select.selected.text}}</span>
</ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="depot.uuid as depot in $ctrl.depots | filter: { 'text': $select.search }">
<span ng-bind-html="depot.text | highlight:$select.search"></span>
</ui-select-choices>
</ui-select>

<div class="help-block" ng-messages="DepotForm.depot_id.$error" ng-show="DepotForm.$$parent.$submitted">
<div class="help-block" ng-messages="DepotForm.depot_uuid.$error" ng-show="DepotForm.$$parent.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>
Expand Down
15 changes: 9 additions & 6 deletions client/src/modules/templates/bhInventorySelect.tmpl.html
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
<div ng-form="{{ $ctrl.name }}" bh-inventory-select ng-model-options="{ updateOn: 'default' }">
<div ng-form="InventoryForm" bh-inventory-select ng-model-options="{ updateOn: 'default' }">
<div
class="form-group"
ng-class="{ 'has-error' : InventoryForm.$$parent.$submitted && InventoryForm.inventory_id.$invalid }">
ng-class="{ 'has-error' : InventoryForm.$$parent.$submitted && InventoryForm.inventory_uuid.$invalid }">

<label class="control-label" translate>
FORM.LABELS.INVENTORY
</label>

<ng-transclude></ng-transclude>
<ui-select name="inventory_id"
ng-model="$ctrl.inventoryId"
<ui-select
name="inventory_uuid"
ng-model="$ctrl.inventoryUuid"
on-select="$ctrl.onSelect($item, $model)">
<ui-select-match placeholder="{{ 'FORM.SELECT.INVENTORY' | translate }}">{{$select.selected.label}}</span></ui-select-match>
<ui-select-match placeholder="{{ 'FORM.SELECT.INVENTORY' | translate }}">
<span>{{$select.selected.label}}</span>
</ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="inventory.uuid as inventory in $ctrl.inventories | filter: { 'label': $select.search }">
<span ng-bind-html="inventory.label | highlight:$select.search"></span>
</ui-select-choices>
</ui-select>

<div class="help-block" ng-messages="InventoryForm.inventory_id.$error" ng-show="InventoryForm.$$parent.$submitted">
<div class="help-block" ng-messages="InventoryForm.inventory_uuid.$error" ng-show="InventoryForm.$$parent.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion server/controllers/stock/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ function getLots(sqlQuery, parameters, finalClauseParameter) {

filters.dateFrom('dateFrom', 'date', 'm');
filters.dateTo('dateTo', 'date', 'm');

// If finalClause is an empty string, filterParser will not group, it will be an empty string
filters.setGroup(finalClause || '');

let query = filters.applyQuery(sql);
const query = filters.applyQuery(sql);
const queryParameters = filters.parameters();
return db.exec(query, queryParameters);
}
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/shared/components/bhDepotSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ module.exports = {

target.click();

FU.uiSelect('$ctrl.depotId', depot, target);
FU.uiSelect('$ctrl.depotUuid', depot, target);
},
};
2 changes: 1 addition & 1 deletion test/end-to-end/shared/components/bhInventorySelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ module.exports = {

target.click();

FU.uiSelect('$ctrl.inventoryId', inventory, target);
FU.uiSelect('$ctrl.inventoryUuid', inventory, target);
},
};
15 changes: 8 additions & 7 deletions test/end-to-end/stock/stock.lots.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,33 @@ function StockLotsRegistryTests() {
const gridId = 'stock-lots-grid';

const depotGroupingRow = 1;
const LOT_FOR_ALLTIME = 16;
const LOT_FOR_TODAY = 10;
const LOT_FOR_LAST_YEAR = 16;


it('finds ten lot for today', () => {
const LOT_FOR_TODAY = 10;
it(`finds ${LOT_FOR_TODAY} lot for today`, () => {
modal.switchToDefaultFilterTab();
modal.setPeriod('today');
modal.submit();
GU.expectRowCount(gridId, LOT_FOR_TODAY);
});

it('finds ten lot for this last year', () => {
const LOT_FOR_LAST_YEAR = 16;
it(`finds ${LOT_FOR_LAST_YEAR} lot for this last year`, () => {
modal.switchToDefaultFilterTab();
modal.setPeriod('year');
modal.submit();
GU.expectRowCount(gridId, LOT_FOR_LAST_YEAR);
});

it('finds ten lot for all time', () => {
const LOT_FOR_ALLTIME = 16;
it(`finds ${LOT_FOR_ALLTIME} lot for all time`, () => {
modal.switchToDefaultFilterTab();
modal.setPeriod('allTime');
modal.submit();
GU.expectRowCount(gridId, LOT_FOR_ALLTIME);
});

it('find lots by in depot principal', () => {
it('find lots in depot principal', () => {
modal.setDepot('Depot Principal');
modal.submit();
GU.expectRowCount(gridId, 8 + depotGroupingRow);
Expand Down
2 changes: 1 addition & 1 deletion test/end-to-end/stock/stock.movements.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function StockMovementsRegistryTests() {
FU.buttons.search();
FU.uiSelect('$ctrl.bundle.flux_id', 'Commande d\'achat');
FU.modal.submit();
GU.expectRowCount(gridId, 23 + depotGroupingRow);
GU.expectRowCount(gridId, 2 + depotGroupingRow);

// to patient
FU.buttons.search();
Expand Down

0 comments on commit 20a206c

Please sign in to comment.