Skip to content

Commit

Permalink
test(Aggregate consumption)
Browse files Browse the repository at this point in the history
- Implement test E2E for aggregate consumption
  • Loading branch information
lomamech authored and jniles committed Mar 3, 2021
1 parent 68018c8 commit 65d8030
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 190 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<div class="row">
<div class="col-xs-12">
<div
id="LotsGrid"
id="lots-grid"
ui-grid="$ctrl.gridOptions"
ui-grid-auto-resize
ui-grid-resize-columns>
Expand All @@ -70,7 +70,7 @@
</div>
</div>

<div ng-if="$ctrl.errors.length > 0" class="alert alert-danger" style="margin-top: 10px;">
<div id="validation-error" ng-if="$ctrl.errors.length > 0" class="alert alert-danger" style="margin-top: 10px;">
<p ng-repeat="error in $ctrl.errors">
<b><i class="fa fa-warning"></i></b> <span translate>{{error}}</span>
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<input
ng-if="row.groupHeader"
name="days_stock_out"
id="row.treeNode.children[0].row.entity.inventory_uuid"
min="0"
max="31"
type="number"
class="form-control"
style="padding-left : 5px !important;text-align: right;"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div ng-if="!row.groupHeader" class="ui-grid-cell-contents">
<a ng-if="!row.entity.detailled && (row.entity.quantity_consumed || row.entity.quantity_consumed == 0)
<a id="aggregated_details" ng-if="!row.entity.detailled && (row.entity.quantity_consumed || row.entity.quantity_consumed == 0)
&& (row.entity.quantity_lost || row.entity.quantity_lost == 0)"
href ng-click="grid.appScope.setConsumptionByLots(row.entity)" data-lots>
<span ng-hide="row.entity.lots.length">
Expand All @@ -8,7 +8,7 @@
</span>
</a>

<a ng-if="row.entity.detailled" href ng-click="grid.appScope.setConsumptionByLots(row.entity)" data-lots>
<a id="aggregated_movements" ng-if="row.entity.detailled" href ng-click="grid.appScope.setConsumptionByLots(row.entity)" data-lots>
<span ng-hide="row.entity.lots.length">
<i class="fa fa-sign-out"></i>
<span translate>STOCK.AGGREGATED_STOCK_CONSUMPTION.AGGREGATED_MOVEMENTS</span>
Expand Down
13 changes: 13 additions & 0 deletions server/models/migrations/next/migrate.sql
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,16 @@ INSERT INTO `discharge_type` (`id`, `label`) VALUES
*/
CALL add_column_if_missing('depot', 'description', 'TEXT DEFAULT NULL AFTER `text`');
CALL add_column_if_missing('depot', 'dhis2_uid', 'VARCHAR(150) DEFAULT NULL AFTER `parent_uuid`');

/*
* @author: lomamech
* @date: 2021-01-12
* @subject : Allow users to record aggregate consumption information for a depot
*/

INSERT INTO unit VALUES
(293, 'Aggregated consumption','TREE.AGGREGATED_STOCK_CONSUMPTION','Aggregated consumption',160,'/stock/aggregated_consumption');

-- Stock Movement Flux
INSERT INTO `flux` VALUES
(16, 'STOCK_FLUX.AGGREGATE_CONSUMPTION');
4 changes: 2 additions & 2 deletions server/models/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,8 @@ CREATE TABLE `inventory_type` (
DROP TABLE IF EXISTS `inventory_unit`;
CREATE TABLE `inventory_unit` (
`id` SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT,
`abbr` VARCHAR(10) NOT NULL,
`text` VARCHAR(30) NOT NULL,
`abbr` VARCHAR(100) NOT NULL,
`text` VARCHAR(100) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `inventory_unit_1` (`text`),
UNIQUE KEY `inventory_unit_2` (`abbr`)
Expand Down
249 changes: 116 additions & 133 deletions test/end-to-end/stock/stock.aggregate_consumption.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* global */
const moment = require('moment');
const helpers = require('../shared/helpers');
const SearchModal = require('../shared/search.page');
const Page = require('./stock.aggregate_consumption.page');

function StockAggregateConsumptionTests() {
Expand All @@ -11,154 +12,136 @@ function StockAggregateConsumptionTests() {

function beforeEachActions() {
page = new Page();
// modal = new SearchModal('stock-aggregate-consumption-search');
helpers.navigate('#/stock/aggregated_consumption');
}

const DEPOT_TERTIAIRE = 'Depot Tertiaire';

const SERVICE = 'Test Service';
const REFERENCES = ['SREQ.TPA.5', 'SREQ.TPA.6', 'SREQ.TPA.7', 'SREQ.TPA.8'];
const NOT_REFERENCE = 'SREQ.ZERO';
it(`Should select the ${DEPOT_TERTIAIRE}`, async () => {
await page.changeDepot(DEPOT_TERTIAIRE);
});

it(`Prevent consumption greater than the quantity available on current depot ${DEPOT_TERTIAIRE}`, async () => {
const getMovementDate = moment(new Date(), 'YYYY-MM-DD').subtract(60, 'days');
const getMovementMonth = moment(getMovementDate).month();
const getMovementYear = moment(getMovementDate).year();

const month = ['Jan', 'Fév', 'Mars', 'Avr', 'Mai', 'Juin', 'Juill', 'Août', 'Sept', 'Oct', 'Nov', 'Déc'];

const fiscalYearLabel = `Fiscal Year ${getMovementYear}`;

await page.setFiscalPeriod(fiscalYearLabel, month[getMovementMonth]);
await page.setDescription(`Aggregate consumption from current depot ${DEPOT_TERTIAIRE}`);

await page.setHeaderValue(0, 7, 0);
await page.setQuantityConsumed(1, 5, 2000);
await page.setQuantityLost(1, 6, 1000);

await page.setQuantityConsumed(2, 5, 500);
await page.setQuantityLost(2, 6, 250);

await page.setHeaderValue(3, 7, 20);
await page.setQuantityConsumed(4, 5, 1500);
await page.setQuantityLost(4, 6, 3000);

await page.submitErrorQuantity();
});

it(`Should select the ${DEPOT_TERTIAIRE}`, async () => {
await page.changeDepot(DEPOT_TERTIAIRE);
});

it(`Create a new stock aggregate consumption on current depot ${DEPOT_TERTIAIRE}`, async () => {
await page.setPeriod(85);
const getMovementDate = moment(new Date(), 'YYYY-MM-DD').subtract(80, 'days');
const getMovementMonth = moment(getMovementDate).month();
const getMovementYear = moment(getMovementDate).year();

const month = ['Jan', 'Fév', 'Mars', 'Avr', 'Mai', 'Juin', 'Juill', 'Août', 'Sept', 'Oct', 'Nov', 'Déc'];

await page.setDescription(`Quick Requisition from current depot ${DEPOT_TERTIAIRE}`);
const fiscalYearLabel = `Fiscal Year ${getMovementYear}`;

// eslint-disable-next-line no-undef
// browser.sleep();
// await page.submit();
await page.setFiscalPeriod(fiscalYearLabel, month[getMovementMonth]);
await page.setDescription(`Aggregate consumption from current depot ${DEPOT_TERTIAIRE}`);

await page.setHeaderValue(0, 7, 0);
await page.setQuantityConsumed(1, 5, 250);
await page.setQuantityLost(1, 6, 0);

await page.setQuantityConsumed(2, 5, 250);
await page.setQuantityLost(2, 6, 0);

await page.setHeaderValue(3, 7, 0);
await page.setQuantityConsumed(4, 5, 150);
await page.setQuantityLost(4, 6, 250);

await page.submit();
});

// it(`Create a new stock requisition from scratch for a service`, async () => {
// await page.showCreateModal();
// await page.setRequestor(SERVICE, 'service');
// await page.setDepot(DEPOT_SECONDAIRE);
// await page.setRows(2);
// await page.addItem(0, 'Quinine', 20);
// await page.addItem(1, 'Vitamines', 20);
// await page.setDescription(`Requisition for ${SERVICE}`);
// await page.submit();
// });

// it(`Create a new stock requisition from scratch for a depot`, async () => {
// await page.showCreateModal();
// await page.setRequestor(DEPOT_SECONDAIRE, 'depot');
// await page.setDepot(DEPOT_PRINCIPAL);
// await page.setRows(2);
// await page.addItem(0, 'Quinine Bichlorhydrate, sirop, 100mg base/5ml, 100ml, flacon, Unité', 4);
// await page.addItem(1, 'Prednisolone, 0,5%, Solution, Flacon, Unité', 500);
// await page.setDescription(`Requisition for ${DEPOT_SECONDAIRE}`);
// await page.submit();
// });

// it(`Create a Cancelled requisition`, async () => {
// await page.showCreateModal();
// await page.setRequestor(DEPOT_TERTIAIRE, 'depot');
// await page.setDepot(DEPOT_SECONDAIRE);
// await page.setRows(3);
// await page.addItem(0, 'Bottes, couleur noire, caoutchouc, taille 44, Paire', 20);
// await page.addItem(1, 'Atazanavir + Ritonavir 30 mg + 100 mg, 30 comp, unité', 25);
// await page.addItem(2, 'Chlorhexidine sol concentrée à 5% 100 ml,flacon,unité', 35);
// await page.setDescription(`Requisition for ${DEPOT_SECONDAIRE}`);
// await page.submit();
// });

// it(`Create a requisition for other depot`, async () => {
// await page.showCreateModal();
// await page.setRequestor(DEPOT_TERTIAIRE, 'depot');
// await page.setDepot(DEPOT_SECONDAIRE);
// await page.setRows(2);
// await page.addItem(0, 'Quinine Bichlorhydrate, sirop, 100mg base/5ml, 100ml, flacon, Unité', 4);
// await page.addItem(1, 'Vitamines', 20);
// await page.setDescription(`Requisition for ${DEPOT_SECONDAIRE}`);
// await page.submit();
// });

// it('Search requisition by depot requestor', async () => {
// await SearchModal.open();
// await modal.reset();
// await modal.setRequestor(DEPOT_SECONDAIRE, 'depot');
// await modal.submit();
// await page.expectRowCount(2);

// await SearchModal.open();
// await modal.reset();
// await modal.setRequestor(DEPOT_PRINCIPAL, 'depot');
// await modal.submit();
// await page.expectRowCount(1);
// });

// it('Search requisition by service requestor', async () => {
// await SearchModal.open();
// await modal.reset();
// await modal.setRequestor(SERVICE, 'service');
// await modal.submit();
// await page.expectRowCount(2);
// });

// it('Search requisition by depot supplier', async () => {
// await SearchModal.open();
// await modal.reset();
// await modal.setDepot(DEPOT_SECONDAIRE);
// await modal.submit();
// await page.expectRowCount(7);

// await SearchModal.open();
// await modal.reset();
// await modal.setDepot(DEPOT_PRINCIPAL);
// await modal.submit();
// await page.expectRowCount(2);
// });

// it('Search requisition by reference', async () => {
// await SearchModal.open();
// await modal.reset();
// await modal.setReference(REFERENCES[0]);
// await modal.submit();
// await page.expectRowCount(1);

// await SearchModal.open();
// await modal.reset();
// await modal.setReference(REFERENCES[1]);
// await modal.submit();
// await page.expectRowCount(1);

// await SearchModal.open();
// await modal.reset();
// await modal.setReference(REFERENCES[2]);
// await modal.submit();
// await page.expectRowCount(1);

// await SearchModal.open();
// await modal.reset();
// await modal.setReference(NOT_REFERENCE);
// await modal.submit();
// await page.expectRowCount(0);
// });

// it('Remove stock requisition', async () => {
// await SearchModal.open();
// await modal.reset();
// await modal.setReference(REFERENCES[0]);
// await modal.submit();
// await page.removeRequisition(0);
// await page.expectRowCount(0);
// });

// it('Change the status of a requisition', async () => {
// await SearchModal.open();
// await modal.reset();
// await modal.setReference(REFERENCES[3]);
// await modal.submit();
// await page.changeStatus(0, 'cancelled');
// });
it(`Create a complexe aggregate consumption on current depot ${DEPOT_TERTIAIRE}`, async () => {
const getMovementDate = moment(new Date(), 'YYYY-MM-DD').subtract(60, 'days');
const getMovementMonth = moment(getMovementDate).month();
const getMovementYear = moment(getMovementDate).year();

const getLastDays = new Date(getMovementYear, getMovementMonth + 1, 0);

const month = ['Jan', 'Fév', 'Mars', 'Avr', 'Mai', 'Juin', 'Juill', 'Août', 'Sept', 'Oct', 'Nov', 'Déc'];

const fiscalYearLabel = `Fiscal Year ${getMovementYear}`;

await page.setFiscalPeriod(fiscalYearLabel, month[getMovementMonth]);
await page.setDescription(`Aggregate consumption from current depot ${DEPOT_TERTIAIRE}`);

await page.setHeaderValue(0, 7, 0);
await page.setQuantityConsumed(1, 5, 500);
await page.setQuantityLost(1, 6, 250);

const lots = [{
date : moment(new Date(getLastDays), 'YYYY-MM-DD').subtract(28, 'days'),
quantity_consumed : 0,
quantity_lost : 95,
}, {
date : moment(new Date(getLastDays), 'YYYY-MM-DD').subtract(20, 'days'),
quantity_consumed : 0,
quantity_lost : 155,
}, {
date : moment(new Date(getLastDays), 'YYYY-MM-DD').subtract(14, 'days'),
quantity_consumed : 225,
quantity_lost : 0,
}, {
date : moment(new Date(getLastDays), 'YYYY-MM-DD').subtract(8, 'days'),
quantity_consumed : 125,
quantity_lost : 0,
}, {
date : moment(new Date(getLastDays), 'YYYY-MM-DD').subtract(5, 'days'),
quantity_consumed : 150,
quantity_lost : 0,
}];

await page.setDetailled(1, 8);
await page.setLotsDetailled(lots);

await page.setQuantityConsumed(2, 5, 500);
await page.setQuantityLost(2, 6, 250);

const lots2 = [{
date : moment(new Date(getLastDays), 'YYYY-MM-DD').subtract(12, 'days'),
quantity_consumed : 125,
quantity_lost : 0,
}, {
date : moment(new Date(getLastDays), 'YYYY-MM-DD').subtract(4, 'days'),
quantity_consumed : 375,
quantity_lost : 250,
}];

await page.setDetailled(2, 8);
await page.setLots2Detailled(lots2);

await page.setHeaderValue(3, 7, 20);
await page.setQuantityConsumed(4, 5, 550);
await page.setQuantityLost(4, 6, 50);

await page.submit();
});
}

module.exports = StockAggregateConsumptionTests;
Loading

0 comments on commit 65d8030

Please sign in to comment.