Skip to content

Commit

Permalink
chore: update e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Benmuiruri committed Nov 18, 2024
1 parent 87170ff commit c23d3e2
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 42 deletions.
3 changes: 3 additions & 0 deletions tests/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const USERNAME = 'admin';
const PASSWORD = 'pass';
const API_HOST = `localhost${process.env.NGINX_HTTPS_PORT ? `:${process.env.NGINX_HTTPS_PORT}` : ''}`;
const PROTOCOL = 'https://';
const NEW_PASSWORD = 'Pa33word';

module.exports = {
IS_CI: !!process.env.CI,
Expand Down Expand Up @@ -34,4 +35,6 @@ module.exports = {

USERNAME,
PASSWORD,
// After first login, the user's password is updated to this NEW_PASSWORD
NEW_PASSWORD,
};
8 changes: 7 additions & 1 deletion tests/e2e/default/db/initial-replication.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,13 @@ describe('initial-replication', () => {
});

it('should support "disconnects"', async () => {
await loginPage.login({ ...userAllowedDocs.user, loadPage: false, resetPassword: false });
const newPassword = loginPage.NEW_PASSWORD;
await loginPage.login({
username: userAllowedDocs.user.username,
password: newPassword,
loadPage: false,
resetPassword: false
});
setTimeout(() => browser.refresh(), 1000);
setTimeout(() => browser.refresh(), 3000);
setTimeout(() => browser.refresh(), 5000);
Expand Down
29 changes: 25 additions & 4 deletions tests/e2e/default/enketo/repeat.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const genericForm = require('@page-objects/default/enketo/generic-form.wdio.page

describe('RepeatForm', () => {
const hierarchy = hierarchyFactory.createHierarchy({ name: 'test', user: true, nbrClinics: 1, nbrPersons: 1 });
const newPassword = loginPage.NEW_PASSWORD;

const assertLabels = async ({ selector, count, labelText }) => {
const labels = await $$(selector);
Expand Down Expand Up @@ -64,7 +65,12 @@ describe('RepeatForm', () => {
it('should display the initial form and its repeated content in English', async () => {
const enUserName = 'User name';
await loginPage.changeLanguage('en', enUserName);
await loginPage.login({ username: hierarchy.user.username, password: hierarchy.user.password, locale: 'en' });
await loginPage.login({
username: hierarchy.user.username,
password: newPassword,
locale: 'en',
resetPassword: false
});
await openRepeatForm('repeat-translation-count');

expect(await commonEnketoPage.isElementDisplayed('span', 'Select a state:')).to.be.true;
Expand All @@ -91,7 +97,12 @@ describe('RepeatForm', () => {
await browser.url('/');
const swUserName = 'Jina la mtumizi';
await loginPage.changeLanguage('sw', swUserName);
await loginPage.login({ username: hierarchy.user.username, password: hierarchy.user.password, locale: 'sw' });
await loginPage.login({
username: hierarchy.user.username,
password: newPassword,
locale: 'sw',
resetPassword: false
});
await openRepeatForm('repeat-translation-button');

expect(await commonEnketoPage.isElementDisplayed('span', 'Select a state: - SV')).to.be.true;
Expand All @@ -109,7 +120,12 @@ describe('RepeatForm', () => {
it('should display the initial form and its repeated content in English', async () => {
const enUserName = 'User name';
await loginPage.changeLanguage('en', enUserName);
await loginPage.login({ username: hierarchy.user.username, password: hierarchy.user.password, locale: 'en' });
await loginPage.login({
username: hierarchy.user.username,
password: newPassword,
locale: 'en',
resetPassword: false
});
await openRepeatForm('repeat-translation-button');

expect(await commonEnketoPage.isElementDisplayed('span', 'Select a state:')).to.be.true;
Expand All @@ -131,7 +147,12 @@ describe('RepeatForm', () => {
await browser.url('/');
const swUserName = 'Jina la mtumizi';
await loginPage.changeLanguage('sw', swUserName);
await loginPage.login({ username: hierarchy.user.username, password: hierarchy.user.password, locale: 'sw' });
await loginPage.login({
username: hierarchy.user.username,
password: newPassword,
locale: 'sw',
resetPassword: false
});
await openRepeatForm('repeat-translation-select');

expect(await commonEnketoPage.isElementDisplayed('label', 'Washington')).to.be.true;
Expand Down
8 changes: 1 addition & 7 deletions tests/e2e/default/login/login-logout.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ describe('Login page functionality tests', () => {
await loginPage.setPasswordValue(user.password);
await loginPage.setUsernameValue(user.username);
await (await loginPage.loginButton()).click();
await loginPage.getPasswordResetTranslations();
await loginPage.setPasswordValue('');
await loginPage.setConfirmPasswordValue('');
await (await loginPage.updatePasswordButton()).click();
Expand All @@ -211,7 +210,6 @@ describe('Login page functionality tests', () => {
await loginPage.setPasswordValue(user.password);
await loginPage.setUsernameValue(user.username);
await (await loginPage.loginButton()).click();
await loginPage.getPasswordResetTranslations();
await loginPage.setPasswordValue(user.password);
await loginPage.setConfirmPasswordValue('');
await (await loginPage.updatePasswordButton()).click();
Expand All @@ -223,19 +221,17 @@ describe('Login page functionality tests', () => {
await loginPage.setPasswordValue(user.password);
await loginPage.setUsernameValue(user.username);
await (await loginPage.loginButton()).click();
await loginPage.getPasswordResetTranslations();
await loginPage.setPasswordValue('12345678');
await loginPage.setConfirmPasswordValue('12345678');
await (await loginPage.updatePasswordButton()).click();
expect(await loginPage.getPasswordResetErrorMessage('password-weak')).to.equal(PASSWORD_WEAK);
});

it('should try to reset password and verify current password is correct', async () => {
it('should try to reset password and verify current password is not correct', async () => {
await browser.url('/');
await loginPage.setPasswordValue(user.password);
await loginPage.setUsernameValue(user.username);
await (await loginPage.loginButton()).click();
await loginPage.getPasswordResetTranslations();
await loginPage.setCurrentPasswordValue('12');
await loginPage.setPasswordValue(user.password);
await loginPage.setConfirmPasswordValue(user.password);
Expand All @@ -250,7 +246,6 @@ describe('Login page functionality tests', () => {
await loginPage.setPasswordValue(user.password);
await loginPage.setUsernameValue(user.username);
await (await loginPage.loginButton()).click();
await loginPage.getPasswordResetTranslations();
await loginPage.setCurrentPasswordValue(user.password);
await loginPage.setPasswordValue(user.password);
await loginPage.setConfirmPasswordValue(user.password);
Expand All @@ -263,7 +258,6 @@ describe('Login page functionality tests', () => {
await loginPage.setPasswordValue(user.password);
await loginPage.setUsernameValue(user.username);
await (await loginPage.loginButton()).click();
await loginPage.getPasswordResetTranslations();
await loginPage.passwordReset(user.password, NEW_PASSWORD, NEW_PASSWORD);
await (await loginPage.updatePasswordButton()).click();
await commonPage.waitForPageLoaded();
Expand Down
13 changes: 11 additions & 2 deletions tests/e2e/default/service-worker/service-worker.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,17 @@ describe('Service worker cache', () => {

const district = placeFactory.generateHierarchy(['district_hospital']).get('district_hospital');
const chw = userFactory.build({ place: district._id });
const newPassword = loginPage.NEW_PASSWORD;
let passwordChangeRequired = true;

const login = async () => {
await browser.throttle('online');
await loginPage.login(chw);
const loginParams = passwordChangeRequired
? chw
: { ...chw, password: newPassword, resetPassword: false };

passwordChangeRequired = false;
await loginPage.login(loginParams);
await commonPage.waitForPageLoaded();
};

Expand Down Expand Up @@ -100,7 +107,6 @@ describe('Service worker cache', () => {

it('confirm initial list of cached resources', async () => {
const cacheDetails = await getCachedRequests();

expect(cacheDetails.name.startsWith('cht-precache-v2-')).to.be.true;
expect(cacheDetails.urls.sort()).to.have.members([
'/',
Expand All @@ -123,15 +129,18 @@ describe('Service worker cache', () => {
'/img/icon.png',
'/img/icon-back.svg',
'/img/layers.png',
'/login/auth-utils.js',
'/login/images/hide-password.svg',
'/login/images/show-password.svg',
'/login/lib-bowser.js',
'/login/password-reset.js',
'/login/script.js',
'/login/style.css',
'/main.js',
'/manifest.json',
'/medic/_design/medic/_rewrite/',
'/medic/login',
'/medic/password-reset',
'/polyfills.js',
'/runtime.js',
'/scripts.js',
Expand Down
10 changes: 7 additions & 3 deletions tests/e2e/default/sms/messages-sender-data.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ describe('Message Tab - Sender Data', () => {
});

it('should not remove facility from breadcrumbs when offline user has many facilities associated', async () => {
await loginPage.login({ password: userWithManyPlacesPass, username: userWithManyPlaces.name });
await loginPage.login({
password: userWithManyPlacesPass,
username: userWithManyPlaces.name,
resetPassword: false
});
await commonElements.waitForPageLoaded();
await commonElements.goToMessages();
await messagesPage.sendMessageDesktop('Contact', patient.phone, patient.name);
Expand All @@ -105,7 +109,8 @@ describe('Message Tab - Sender Data', () => {
});

it('should display conversation with link and navigate to contact', async () => {
await loginPage.login(offlineUser);
const newPassword = loginPage.NEW_PASSWORD;
await loginPage.login({ password: newPassword, username: offlineUser.username, resetPassword: false });
await commonElements.waitForPageLoaded();
await commonElements.goToMessages();

Expand All @@ -118,5 +123,4 @@ describe('Message Tab - Sender Data', () => {
const title = await contactsPage.getContactInfoName();
expect(title).to.equal(patient.name);
});

});
18 changes: 13 additions & 5 deletions tests/e2e/default/targets/target-aggregates.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('Target aggregates', () => {
});

describe('User with one or more places assigned', () => {
const newPassword = loginPage.NEW_PASSWORD;
const CURRENT_PERIOD = 'This month';
const NAMES_DH1 = ['Clarissa', 'Prometheus', 'Alabama', 'Jasmine', 'Danielle'];
const NAMES_DH2 = ['Viviana', 'Ximena', 'Esteban', 'Luis', 'Marta'];
Expand Down Expand Up @@ -123,12 +124,9 @@ describe('Target aggregates', () => {
});

describe('Online user with one place associated', () => {
beforeEach(async () => {
it('should display no data when no targets are uploaded', async () => {
await loginPage.login(onlineUser);
await commonPage.waitForPageLoaded();
});

it('should display no data when no targets are uploaded', async () => {
await helperFunctions.updateAggregateTargetsSettings(
targetAggregatesConfig.TARGETS_CONFIG_WITH_AND_WITHOUT_AGGREGATES, onlineUser
);
Expand All @@ -155,6 +153,8 @@ describe('Target aggregates', () => {
});

it('should display correct data', async () => {
await loginPage.login({ username: onlineUser.username, password: newPassword, resetPassword: false});
await commonPage.waitForPageLoaded();
const expectedTargets = targetAggregatesConfig.EXPECTED_DEFAULTS_TARGETS;

await utils.saveDocs(targetDocs);
Expand Down Expand Up @@ -195,6 +195,8 @@ describe('Target aggregates', () => {
});

it('should route to contact-detail on list item click and display contact summary target card', async () => {
await loginPage.login({ username: onlineUser.username, password: newPassword, resetPassword: false});
await commonPage.waitForPageLoaded();
const targetsConfig = [
{ id: 'a_target', type: 'count', title: { en: 'what a target!' }, aggregate: true },
{ id: 'b_target', type: 'percent', title: { en: 'the most target' }, aggregate: true },
Expand Down Expand Up @@ -287,6 +289,8 @@ describe('Target aggregates', () => {
});

it('should display targets of current user on home place', async () => {
await loginPage.login({ username: onlineUser.username, password: newPassword, resetPassword: false});
await commonPage.waitForPageLoaded();
const targetsConfig = [
{ id: 'a_target', type: 'count', title: { en: 'what a target!' }, aggregate: true },
{ id: 'b_target', type: 'percent', title: { en: 'the most target' }, aggregate: true },
Expand Down Expand Up @@ -347,7 +351,11 @@ describe('Target aggregates', () => {

describe('Offline user with multiple places associated', () => {
beforeEach(async () => {
await loginPage.login({ password: userWithManyPlacesPass, username: userWithManyPlaces.name });
await loginPage.login({
password: userWithManyPlacesPass,
username: userWithManyPlaces.name,
resetPassword: false
});
await commonPage.waitForPageLoaded();
});

Expand Down
15 changes: 9 additions & 6 deletions tests/e2e/default/tasks/tasks.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const commonPage = require('@page-objects/default/common/common.wdio.page');
const chtDbUtils = require('@utils/cht-db');

describe('Tasks', () => {

const newPassword = loginPage.NEW_PASSWORD;
const places = placeFactory.generateHierarchy();
const clinic = places.get('clinic');
const healthCenter1 = places.get('health_center');
Expand Down Expand Up @@ -59,11 +59,6 @@ describe('Tasks', () => {
await chtConfUtils.compileAndUploadAppForms(formsPath);
});

beforeEach(async () => {
await loginPage.login(chw);
await commonPage.waitForPageLoaded();
});

afterEach(async () => {
await commonPage.logout();
await utils.revertSettings(true);
Expand All @@ -77,6 +72,8 @@ describe('Tasks', () => {
});

it('should remove task from list when CHW completes a task successfully', async () => {
await loginPage.login(chw);
await commonPage.waitForPageLoaded();
await tasksPage.compileTasks('tasks-breadcrumbs-config.js', true);

await commonPage.goToTasks();
Expand All @@ -93,6 +90,8 @@ describe('Tasks', () => {
});

it('should add a task when CHW completes a task successfully, and that task creates another task', async () => {
await loginPage.login({ username: chw.username, password: newPassword, resetPassword: false });
await commonPage.waitForPageLoaded();
await tasksPage.compileTasks('tasks-breadcrumbs-config.js', false);

await commonPage.goToTasks();
Expand All @@ -111,6 +110,8 @@ describe('Tasks', () => {
});

it('should load multiple pages of tasks on infinite scrolling', async () => {
await loginPage.login({ username: chw.username, password: newPassword, resetPassword: false });
await commonPage.waitForPageLoaded();
await tasksPage.compileTasks('tasks-multiple-config.js', true);

await commonPage.goToTasks();
Expand Down Expand Up @@ -140,6 +141,8 @@ describe('Tasks', () => {
});

it('Should show error message for bad config', async () => {
await loginPage.login({ username: chw.username, password: newPassword, resetPassword: false });
await commonPage.waitForPageLoaded();
await tasksPage.compileTasks('tasks-error-config.js', true);
await commonPage.goToTasks();

Expand Down
6 changes: 4 additions & 2 deletions tests/e2e/default/telemetry/telemetry.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ describe('Telemetry', () => {
await commonPage.sync();

const clientDdoc = await utils.getDoc('_design/medic-client');

const options = { auth: { username: user.username, password: user.password }, userName: user.username };

// After first login, the user's password is updated, we use the newPassword
const newPassword = loginPage.NEW_PASSWORD;
const options = { auth: { username: user.username, password: newPassword }, userName: user.username };
const metaDocs = await utils.requestOnTestMetaDb({ ...options, path: '/_all_docs?include_docs=true' });

const telemetryEntry = metaDocs.rows.find(row => row.id.startsWith(TELEMETRY_PREFIX));
Expand Down
4 changes: 3 additions & 1 deletion tests/e2e/default/users/create-meta-db.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ describe('Create user meta db : ', () => {
const FULL_NAME = 'Roger Milla';
const PASSWORD = 'StrongP@ssword1';

// After first login, the user's password is updated, we use the newPassword
const newPassword = loginPage.NEW_PASSWORD;
const OPTIONS = {
auth: { username: USERNAME, password: PASSWORD },
auth: { username: USERNAME, password: newPassword },
method: 'GET',
userName: USERNAME
};
Expand Down
Loading

0 comments on commit c23d3e2

Please sign in to comment.