Skip to content

Commit

Permalink
Add user modal e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ngaruko authored and garethbowen committed Aug 31, 2017
1 parent ef15624 commit ab87b1c
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 54 deletions.
1 change: 1 addition & 0 deletions tests/protractor/e2e/common/common.specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('Navigation tests : ', () => {
expect(browser.getCurrentUrl()).toEqual(commonElements.getBaseUrl() + 'analytics');

});

it('should open Configuration tab', () => {
commonElements.goToConfiguration();
expect(browser.getCurrentUrl()).toEqual(commonElements.getBaseUrl() + 'configuration');
Expand Down
6 changes: 3 additions & 3 deletions tests/protractor/e2e/contacts/add-new-person.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const commonElements = require('../../page-objects/common/common.po.js'),
contactPage = require('../../page-objects/contacts/contacts.po.js'),
helper = require('../../helper'),
utils = require('../../utils');
contactPage = require('../../page-objects/contacts/contacts.po.js'),
helper = require('../../helper'),
utils = require('../../utils');

describe('Add new person tests : ', () => {
afterEach(done => {
Expand Down
97 changes: 79 additions & 18 deletions tests/protractor/e2e/users/add-user.specs.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,81 @@
const utils = require('../../utils'),
usersPage = require('../../page-objects/users/users.po.js'),
common = require('../../page-objects/common/common.po.js'),
helper = require('../../helper'),
addUserModal = require('../../page-objects/users/add-user-modal.po.js');

const addedUser = 'bedetester2020',
fullName = 'Bede Ngaruko';

describe('Add user test : ', () => {
it('should open add user modal', () => {
common.goToConfiguration();
browser.get(utils.getBaseUrl() + '/_design/medic/_rewrite/#/configuration/users');
usersPage.openAddUserModal();
addUserModal.fillForm(addedUser, fullName);
addUserModal.submit();
expect(helper.isTextDisplayed(addedUser));
expect(helper.isTextDisplayed(fullName));
});
usersPage = require('../../page-objects/users/users.po.js'),
helper = require('../../helper'),
addUserModal = require('../../page-objects/users/add-user-modal.po.js');

const addedUser = 'fulltester' + new Date().getTime(),
fullName = 'Bede Ngaruko',
errorMessagePassword = element.all(by.css('span.help-block.ng-binding')).get(3);

describe('Add user : ', () => {
afterEach(done => {
utils.resetBrowser();
done();
});

afterAll(utils.afterEach);

it('should add user with valid password', () => {
usersPage.openAddUserModal();
addUserModal.fillForm(addedUser, fullName, 'StrongP@ssword1');
addUserModal.submit();
browser.wait(() => {
return element(by.css('#edit-user-profile')).isDisplayed()
.then(isDisplayed => {
return !isDisplayed;
})
.catch(() => {
return true;
});
}, 2000);
expect(helper.isTextDisplayed(addedUser));
expect(helper.isTextDisplayed(fullName));
});

it('should reject passwords shorter than 8 characters', () => {
usersPage.openAddUserModal();
addUserModal.fillForm('user0', 'Not Saved', 'short');
addUserModal.submit();
expect(errorMessagePassword.getText()).toBe('The password must be at least 8 characters long.');
});

it('should reject weak passwords', () => {
usersPage.openAddUserModal();
addUserModal.fillForm('user0', 'Not Saved', 'weakPassword');
addUserModal.submit();
expect(errorMessagePassword.getText()).toBe('The password is too easy to guess. Include a range of types of characters to increase the score.');
});

it('should reject non-matching passwords', () => {
usersPage.openAddUserModal();
addUserModal.fillForm('user0', 'Not Saved', '%4wbbygxkgdwvdwT65');
element(by.id('password-confirm')).sendKeys('abc');
addUserModal.submit();
expect(errorMessagePassword.getText()).toBe('Passwords must match.');
});

it('should require password', () => {
usersPage.openAddUserModal();
addUserModal.fillForm('user0', 'Not Saved', '');
addUserModal.submit();
expect(errorMessagePassword.getText()).toBe('Password is a required field.');
});

it('should require username', () => {
usersPage.openAddUserModal();
addUserModal.fillForm('', 'Not Saved', '%4wbbygxkgdwvdwT65');
addUserModal.submit();
const errorMessageUserName = element.all(by.css('span.help-block.ng-binding')).get(0);
helper.waitUntilReady(errorMessageUserName);
expect(errorMessageUserName.getText()).toBe('User name is a required field.');
});

it('should require place and contact for restricted user', () => {
usersPage.openAddUserModal();
addUserModal.fillForm('restricted', 'Not Saved', '%4wbbygxkgdwvdwT65');
helper.selectDropdownByText(element(by.id('type')), 'Restricted to their place');
addUserModal.submit();
expect(element.all(by.css('span.help-block.ng-binding')).get(1).getText()).toBe('Place is a required field.');
expect(element.all(by.css('span.help-block.ng-binding')).get(2).getText()).toBe('Associated contact is a required field.');
});
});
2 changes: 1 addition & 1 deletion tests/protractor/page-objects/common/common.po.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const messagesLink = element(by.id('messages-tab'));
const tasksLink = element(by.id('tasks-tab'));
const contactsLink = element(by.id('contacts-tab'));
const analyticsLink = element(by.id('analytics-tab'));
//const reportsLink = element(by.id('reports-tab'));
const configurationLink = element(by.css('[ui-sref=configuration]'));
const hamburgerMenu = element(by.className('dropdown options'));
const logoutButton = $('[ng-click=logout]');
Expand Down Expand Up @@ -63,6 +62,7 @@ module.exports = {
helper.waitUntilReady(medicLogo);
return element(by.id(list)).isPresent();
},

logout: () => {
hamburgerMenu.click();
helper.waitElementToBeVisisble(logoutButton);
Expand Down
38 changes: 19 additions & 19 deletions tests/protractor/page-objects/contacts/contacts.po.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
const helper = require('../../helper');

const searchBox = element.all(by.css('#freetext'));
const seachButton = element.all(by.css('#search'));
const refreshButton = element.all(by.css('.fa fa-undo'));
const newDistrictButton = element.all(by.css('a[href="#/contacts//add/district_hospital"]'));
const newPlaceForm = element.all(by.css('#district_hospital'));
const newPlaceName = element.all(by.css('[name="/data/district_hospital/name"]'));
const newPersonButton = element.all(by.css('a.btn.btn-link.add-new'));
const externalId = element.all(by.css('[name="/data/district_hospital/external_id"]'));
const notesTextArea = element.all(by.css('[name="/data/district_hospital/notes"]'));
const nextButton = element.all(by.css('button.btn.btn-primary.next-page.ng-scope'));
const newPersonTextBox = element.all(by.css('[name="/data/contact/name"]'));
const datePicker = element.all(by.css('[placeholder="yyyy-mm-dd"]'));
const phoneNumbers = element.all(by.css(':not([style="display: none;"])[type="tel"]'));
const phoneNumber = phoneNumbers.first();
const alternativePhoneNumber = phoneNumbers.get(1);
const personNotes = element.all(by.css('[name="/data/contact/notes"]'));
const submitButton = element(by.css('.btn.submit.btn-primary.ng-scope'));
const searchBox = element.all(by.css('#freetext')),
seachButton = element.all(by.css('#search')),
refreshButton = element.all(by.css('.fa fa-undo')),
newDistrictButton = element.all(by.css('a[href="#/contacts//add/district_hospital"]')),
newPlaceForm = element.all(by.css('#district_hospital')),
newPlaceName = element.all(by.css('[name="/data/district_hospital/name"]')),
newPersonButton = element.all(by.css('a.btn.btn-link.add-new')),
externalId = element.all(by.css('[name="/data/district_hospital/external_id"]')),
notesTextArea = element.all(by.css('[name="/data/district_hospital/notes"]')),
nextButton = element.all(by.css('button.btn.btn-primary.next-page.ng-scope')),
newPersonTextBox = element.all(by.css('[name="/data/contact/name"]')),
datePicker = element.all(by.css('[placeholder="yyyy-mm-dd"]')),
phoneNumbers = element.all(by.css(':not([style="display: none;"])[type="tel"]')),
phoneNumber = phoneNumbers.first(),
alternativePhoneNumber = phoneNumbers.get(1),
personNotes = element.all(by.css('[name="/data/contact/notes"]')),
submitButton = element(by.css('.btn.submit.btn-primary.ng-scope'));

module.exports = {

getSubmitButton: () => {
return submitButton;
},
Expand All @@ -36,7 +37,6 @@ module.exports = {

completeNewPersonForm: name => {
helper.waitUntilReady(newPersonTextBox);
//complete form
newPersonTextBox.sendKeys(name);
datePicker.sendKeys('22-03-2016');
datePicker.sendKeys(protractor.Key.ENTER);
Expand All @@ -50,8 +50,8 @@ module.exports = {
refresh: () => {
refreshButton.click();
},
search: query => {

search: query => {
searchBox.sendKeys(query);
seachButton.click();
},
Expand Down
22 changes: 13 additions & 9 deletions tests/protractor/page-objects/forms/new-pregnancy-form.po.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ module.exports = {
element(by.css('.btn submit btn-primary')).click();
},

//patient page
getPatientPageTitle: () => {
return element(by.css('span[data-itext-id=/delivery/inputs:label]'));
},

selectPatientName: () => {
getPatientNameDropDown().click();
},
//LMP page

selectLMPYesButton: () => {
element(by.css('[value="calendar"]')).click();
},
Expand All @@ -38,77 +37,82 @@ module.exports = {
setLastCycleDate: (lmpDate) => {
const datePicker = element(by.css('[placeholder="yyyy-mm-dd"]'));
datePicker.click();
//type date in the text box as '2017-04-23'
datePicker.sendKeys(lmpDate);

},

reset: () => {
element(by.css('.icon.icon-refresh')).click();
},

getEstimatedDeliveryDate: () => {
return element(by.css('[data-value=" /pregnancy/group_lmp/g_edd "]')).getText();
},

//Risk factor page
checkFirstPregnancyCheckBox: () => {
element(by.css('[value="r1"]')).click();
},

checkMoreThanFourChildrenCheckBox: () => {
element(by.css('[value="r2"]')).click();
},

checkMastBabyYearBeforeCheckBox: () => {
element(by.css('[value="r3"]')).click();
},

checkPreviousMiscarriagesCheckBox: () => {
element(by.css('[value="r4"]')).click();
},

checkConditionsCheckBox: () => {
element(by.css('[value="r5"]')).click();
},

checkHIVPisotiveCheckBox: () => {
element(by.css('[value="r6"]')).click();
},

//Danger signs page
checkPainCheckBox: () => {
element(by.css('[value="d1"]')).click();
},

checkBleedingCheckBox: () => {
element(by.css('[value="d2"]')).click();
},

checkNauseaCheckBox: () => {
element(by.css('[value="d3"]')).click();
},

checkFeverCheckBox: () => {
element(by.css('[value="d4"]')).click();
},

checkHeadacheCheckBox: () => {
element(by.css('[value="d5"]')).click();
},

checkWeightGainCheckBox: () => {
element(by.css('[value="d6"]')).click();
},

checkLessMovementCheckBox: () => {
element(by.css('[value="d7"]')).click();
},

checkBloodCheckBox: () => {
element(by.css('[value="d8"]')).click();
},

checkDiarrheaCheckBox: () => {
element(by.css('[value="d9"]')).click();
},

//note to CHW
getTextArea: () => {
return element(by.name('/pregnancy/group_note/chw_note'));
},

//summary page
getId: () => {
getId: () => {
return element(by.css('[data-value=" /pregnancy/group_review/r_patient_id "]'));
},

Expand Down
6 changes: 3 additions & 3 deletions tests/protractor/page-objects/users/add-user-modal.po.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,16 @@ module.exports = {
getCancelButton().click();
},

fillForm: (username, fullName) => {
fillForm: (username, fullName, password) => {
helper.waitUntilReady(getSubmitButton()); // wait for form to load
getUsernameField().sendKeys(username);
getFullNameField().sendKeys(fullName);
getEmailField().sendKeys('[email protected]');
getPhoneField().sendKeys('0064212134566');
helper.selectDropdownByText(getLanguageField(), 'English', 2);
helper.selectDropdownByText(getUserTypeField(), 'Full access');
getPasswordField().sendKeys('pass');
getConfirmPasswordField().sendKeys('pass');
getPasswordField().sendKeys(password);
getConfirmPasswordField().sendKeys(password);
}
};

4 changes: 3 additions & 1 deletion tests/protractor/page-objects/users/users.po.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const helper = require('../../helper');
const helper = require('../../helper'),
utils = require('../../utils');

const getAddUserButton = () => {
return element(by.id('add-user'));
Expand All @@ -24,6 +25,7 @@ module.exports = {
},

openAddUserModal: () => {
browser.get(utils.getBaseUrl() + '/_design/medic/_rewrite/#/configuration/users');
helper.waitElementToBeClickable(getAddUserButton());
getAddUserButton().click();
},
Expand Down

0 comments on commit ab87b1c

Please sign in to comment.