Skip to content

Commit

Permalink
e2e test for donor management
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremielodi committed Aug 24, 2020
1 parent f396289 commit f220c39
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 8 deletions.
18 changes: 17 additions & 1 deletion client/src/modules/donor/donor.ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,23 @@ function DonorController($uibModal, Donor, Modal, Notify, uiGridConstants) {
field : 'display_name',
displayName : 'FORM.LABELS.NAME',
headerCellFilter : 'translate',
}, {
},
{
field : 'phone',
displayName : 'FORM.LABELS.PHONE',
headerCellFilter : 'translate',
},
{
field : 'email',
displayName : 'FORM.LABELS.EMAIL',
headerCellFilter : 'translate',
},
{
field : 'address',
displayName : 'FORM.LABELS.ADDRESS',
headerCellFilter : 'translate',
},
{
field : 'actions',
enableFiltering : false,
width : 100,
Expand Down
2 changes: 1 addition & 1 deletion client/src/modules/donor/donor.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<div class="flex-content">
<div class="container-fluid">
<div
id="roles-grid"
id="donor-grid"
class="grid-full-height"
ui-grid="DonorCtrl.gridOptions"
ui-grid-auto-resize
Expand Down
26 changes: 26 additions & 0 deletions client/src/modules/donor/modal/createUpdate.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,32 @@
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>

<div class="form-group" ng-class="{ 'has-error' : donorForm.phone.$invalid && donorForm.$submitted }">
<label class="control-label" translate>FORM.LABELS.PHONE</label>
<input type="tel" class="form-control col-md-9" name="phone" ng-model="DonorAddCtrl.donor.phone">
<div class="help-block" ng-messages="donorForm.phone.$error" ng-show="donorForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>


<div class="form-group" ng-class="{ 'has-error' : donorForm.email.$invalid && donorForm.$submitted }">
<label class="control-label" translate>FORM.LABELS.EMAIL</label>
<input type="email" class="form-control col-md-9" name="email" ng-model="DonorAddCtrl.donor.email">
<div class="help-block" ng-messages="donorForm.email.$error" ng-show="donorForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>


<div class="form-group" ng-class="{ 'has-error' : donorForm.address.$invalid && donorForm.$submitted }">
<label class="control-label" translate>FORM.LABELS.ADDRESS</label>
<input type="text" class="form-control col-md-9" name="address" ng-model="DonorAddCtrl.donor.address">
<div class="help-block" ng-messages="donorForm.address.$error" ng-show="donorForm.$submitted">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>
</div>
</div>

Expand Down
16 changes: 12 additions & 4 deletions client/src/modules/reports/generate/stock_entry/stock_entry.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,36 @@ <h3 translate>REPORT.STOCK.ENTRY_REPORT</h3>
<div ng-class="{'has-error': ConfigForm.$submitted && !ReportConfigCtrl.hasOneChecked}">
<div class="checkbox">
<label>
<input type="checkbox" ng-true-value="1" ng-false-value="0" ng-change="ReportConfigCtrl.onEntryTypeChange()" ng-model="ReportConfigCtrl.reportDetails.includePurchaseEntry">
<input type="checkbox" ng-true-value="1" ng-false-value="0"
ng-change="ReportConfigCtrl.onEntryTypeChange()"
ng-model="ReportConfigCtrl.reportDetails.includePurchaseEntry">
<span translate>REPORT.STOCK.INCLUDE_PURCHASE_ENTRY</span>
</label>
</div>

<div class="checkbox">
<label>
<input type="checkbox" ng-true-value="1" ng-false-value="0" ng-change="ReportConfigCtrl.onEntryTypeChange()" ng-model="ReportConfigCtrl.reportDetails.includeIntegrationEntry">
<input type="checkbox" ng-true-value="1" ng-false-value="0"
ng-change="ReportConfigCtrl.onEntryTypeChange()"
ng-model="ReportConfigCtrl.reportDetails.includeIntegrationEntry">
<span translate>REPORT.STOCK.INCLUDE_INTEGRATION_ENTRY</span>
</label>
</div>

<div class="checkbox">
<label>
<input type="checkbox" ng-true-value="1" ng-false-value="0" ng-change="ReportConfigCtrl.onEntryTypeChange()" ng-model="ReportConfigCtrl.reportDetails.includeDonationEntry">
<input type="checkbox" ng-true-value="1" ng-false-value="0"
ng-change="ReportConfigCtrl.onEntryTypeChange()"
ng-model="ReportConfigCtrl.reportDetails.includeDonationEntry">
<span translate>REPORT.STOCK.INCLUDE_DONATION_ENTRY</span>
</label>
</div>

<div class="checkbox">
<label>
<input type="checkbox" ng-true-value="1" ng-false-value="0" ng-change="ReportConfigCtrl.onEntryTypeChange()" ng-model="ReportConfigCtrl.reportDetails.includeTransferEntry">
<input type="checkbox" ng-true-value="1" ng-false-value="0"
ng-change="ReportConfigCtrl.onEntryTypeChange()"
ng-model="ReportConfigCtrl.reportDetails.includeTransferEntry">
<span translate>REPORT.STOCK.INCLUDE_TRANSFER_ENTRY</span>
</label>
</div>
Expand Down
4 changes: 2 additions & 2 deletions server/controllers/admin/donor.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ function update(req, res, next) {
}

function read(req, res, next) {
db.exec(`SELECT id, display_name FROM donor`).then(donors => {
db.exec(`SELECT id, display_name, email, phone, address FROM donor`).then(donors => {
res.status(200).json(donors);
}).catch(next);
}

function detail(req, res, next) {
const { id } = req.params;
db.one(`SELECT id, display_name FROM donor WHERE id=?`, id).then(donor => {
db.one(`SELECT id, display_name, email, phone, address FROM donor WHERE id=?`, id).then(donor => {
res.status(200).json(donor);
}).catch(next);
}
Expand Down
5 changes: 5 additions & 0 deletions server/models/migrations/next/migrate.sql
Original file line number Diff line number Diff line change
Expand Up @@ -715,3 +715,8 @@ CREATE TABLE `lot_tag` (
*/
INSERT INTO unit VALUES
(290,'Donors','TREE.DONOR','Donors management',1,'/donors');

ALTER TABLE `donor`
ADD COLUMN `email` VARCHAR(50) DEFAULT NULL,
ADD COLUMN `phone` VARCHAR(50) DEFAULT NULL,
ADD COLUMN `address` VARCHAR(150) DEFAULT NULL;
3 changes: 3 additions & 0 deletions server/models/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,9 @@ DROP TABLE IF EXISTS `donor`;
CREATE TABLE `donor` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`display_name` VARCHAR(191) NOT NULL,
`phone` VARCHAR(50) NULL,
`email` VARCHAR(50) NULL,
`address` VARCHAR(150) NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET = utf8mb4 DEFAULT COLLATE = utf8mb4_unicode_ci;

Expand Down
63 changes: 63 additions & 0 deletions test/end-to-end/donor/donor.page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* global element, by, browser */
const EC = require('protractor').ExpectedConditions;
const FU = require('../shared/FormUtils');
const GridRow = require('../shared/GridRow');

const { bhCheckboxTree } = require('../shared/components');

class DonorPage {
constructor() {
this.gridId = 'donor-grid';
this.donorName = element(by.model('DonorAddCtrl.donor.display_name'));
this.donorPhone = element(by.model('DonorAddCtrl.donor.phone'));
this.donorEmail = element(by.model('DonorAddCtrl.donor.email'));
this.donorAddress = element(by.model('DonorAddCtrl.donor.address'));
}

submit() {
return FU.modal.submit();
}

setName(txt) {
return this.donorName.clear().sendKeys(txt);
}

setPhone(txt) {
return this.donorPhone.clear().sendKeys(txt);
}

setEmail(txt) {
return this.donorEmail.clear().sendKeys(txt);
}

setAddress(txt) {
return this.donorAddress.clear().sendKeys(txt);
}

async openDropdownMenu(label) {
const row = new GridRow(label);
await row.dropdown().click();
return row;
}

async editDonor(displayName) {
const row = await this.openDropdownMenu(displayName);
await row.edit().click();
}

async deleteDonor(displayName) {
const row = await this.openDropdownMenu(displayName);
await row.remove().click();
}

async checkAllPermissions() {
await browser.wait(EC.presenceOf($(bhCheckboxTree.selector)), 1500);
await bhCheckboxTree.toggleAllCheckboxes();
}

openCreateModal() {
return FU.buttons.create();
}
}

module.exports = DonorPage;
47 changes: 47 additions & 0 deletions test/end-to-end/donor/donor.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const helpers = require('../shared/helpers');
const DonorsPage = require('./donor.page');
const components = require('../shared/components');

// the page object
const page = new DonorsPage();

function donorsManagementTests() {

// navigate to the page
before(() => helpers.navigate('#/donors'));

it('should add a new donor', async () => {
await page.openCreateModal();
await page.setName('DFD');
await page.setEmail('dfid@imaworld.com');
await page.setPhone('+100000202');
await page.setAddress('232 USA ..');
await page.submit();
await components.notification.hasSuccess();
});

it('should add a edit donor', async () => {
await page.editDonor('DFD');
await page.setName('DFID');
await page.submit();
await components.notification.hasSuccess();
});

it('should add a test donor', async () => {
await page.openCreateModal();
await page.setName('Test donor');
await page.submit();
await components.notification.hasSuccess();
});

it('should delete the test donor', async () => {
await page.deleteDonor('Test donor');
await page.submit();
await components.notification.hasSuccess();
});

}

describe('donor Management Tests', () => {
describe('donor Management', donorsManagementTests);
});
3 changes: 3 additions & 0 deletions test/integration/donor.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ describe('(/donors) The donros API endpoint', () => {
const newDonor = {
id : 2,
display_name : 'IMA',
email : 'ima@gmail.com',
phone : '+243810000001',
address : '289 Kinshasa, RDC',
};

const updatedDonor = {
Expand Down

0 comments on commit f220c39

Please sign in to comment.