Skip to content

Commit

Permalink
chore(#8692) flaky navigation hamburguer menu test (#8696)
Browse files Browse the repository at this point in the history
* Move the failing code out of the before to get a screenshot

* Move before each code to each test to get a screnshot

* Move goToReports to afterEach hook

* Change tests setup

* Change setup of default mobile specs

* Delete async from describe

* Remove oldLogout and oldCloseReloadModal since 4.4 is released

* Set shouldUpdate to true when using new CloseReloadModal

* Wait for page to load after cookie login

* Since not able to reproduce locally, only test upgrade to get a screenshot

* Add close reload modal after go to Abour. As per screenshot the reload modal is blocking the version

* Back to old close reload modal

* Add test id to about version element

* Revert "Add test id to about version element"

This reverts commit 359b7f3.

* Revert "Back to old close reload modal"

This reverts commit e0d37e1.

* Revert "Add close reload modal after go to Abour. As per screenshot the reload modal is blocking the version"

This reverts commit 7140b79.

* Revert "Since not able to reproduce locally, only test upgrade to get a screenshot"

This reverts commit d772113.

* Revert "Wait for page to load after cookie login"

This reverts commit 156e0a7.

* Use old close reload modal

* Change about version selector

* Add a test-id to retrieve about version element

* Reload app on about page

* Add go to base url before login

* Wait for page to Load

* remove a bunch more describe asyncs

* remove before function to get screenshot and better logging

* try a backwards compatible version selector

* Revert "try a backwards compatible version selector"

This reverts commit af76974.

* Add sync step

* Use new closeReloadModal after login

* Wait for page to load, close reload modal and, wait again for page to load

* Use old close reload modal

* Try to close old reload modal after going to about page

* Add new close reload modal

* Move afterEach from online Describe to first test

* Add after on second test also

* Restore changes before removing before function

* Get rid of breaks

* Add browser.refresh and sync to try to load the updated About Page

* wait for sw generation

* comment out slow running builds - revert before merging

* clarify found logs message

* refresh AFTER sync

* eslnit

* optimistically remove browser pause

* Revert "comment out slow running builds - revert before merging"

This reverts commit cf66af8.

* Delete unused function

---------

Co-authored-by: Maria Lorena Rodriguez Viruel <[email protected]>
Co-authored-by: Gareth Bowen <[email protected]>
  • Loading branch information
3 people authored and 1yuv committed Nov 16, 2023
1 parent d0c5003 commit 99c024d
Show file tree
Hide file tree
Showing 25 changed files with 55 additions and 73 deletions.
4 changes: 2 additions & 2 deletions api/tests/mocha/services/branding.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('branding service', () => {
sinon.restore();
});

describe('get', async() => {
describe('get', () => {

it('returns default when missing doc', async () => {
const get = sinon.stub(db, 'get').rejects({});
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('branding service', () => {

});

describe('getFavicon', async() => {
describe('getFavicon', () => {

it('returns default when missing doc', async () => {
const get = sinon.stub(db, 'get').rejects({});
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/default-mobile/reports/search.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const personFactory = require('@factories/cht/contacts/person');
const pregnancyFactory = require('@factories/cht/reports/pregnancy');
const smsPregnancyFactory = require('@factories/cht/reports/sms-pregnancy');

describe('Search Reports', async () => {
describe('Search Reports', () => {
const places = placeFactory.generateHierarchy();
const districtHospitalPatient = personFactory.build({ parent: places.get('district_hospital'), patient_id: '1a' });
const healthCenterPatient = personFactory.build({ parent: places.get('health_center'), patient_id: '2a' });
Expand Down
11 changes: 5 additions & 6 deletions tests/e2e/default-mobile/wdio.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ exports.config = Object.assign(wdioBaseConfig.config, {
suites: {
all: [
'./**/*.wdio-spec.js',
[
'../default/login/login-logout.wdio-spec.js',
'../default/navigation/navigation.wdio-spec.js',
'../default/navigation/hamburger-menu.wdio-spec.js',
],
]},
'../default/login/login-logout.wdio-spec.js',
'../default/navigation/navigation.wdio-spec.js',
'../default/navigation/hamburger-menu.wdio-spec.js',
]
},
beforeSuite: async () => {
// We tried the browser.emulateDevice('...') function but it's not stable enough,
// it looses the mobile view and switches back to desktop
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/default/about/about.wdio-spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/e2e/default/contacts/person-under-area.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const person2 = personFactory.build(

const docs = [...places.values(), healthCenter2, person1, person2];

describe('Create Person Under Area', async () => {
describe('Create Person Under Area', () => {
beforeEach(async () => {
await utils.saveDocs(docs);
await loginPage.cookieLogin();
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/default/contacts/search-contacts.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const potuPerson = personFactory.build(

const docs = [...places.values(), sittuHospital, sittuPerson, potuHospital, potuPerson];

describe('Test Contact Search Functionality', async () => {
describe('Test Contact Search Functionality', () => {
before(async () => {
await utils.saveDocs(docs);
await loginPage.cookieLogin();
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/default/login/renew-token.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const commonPage = require('@page-objects/default/common/common.wdio.page');
const moment = require('moment');
const utils = require('@utils');

describe('should renew token', async () => {
describe('should renew token', () => {

beforeEach(async () => {
await loginPage.cookieLogin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const smsReport = reportFactory
{ patient, submitter: offlineUser.contact, fields: { lmp_date: 'Feb 3, 2022', patient_id: patient._id }, },
);

describe('More Options Menu - Offline User', async () => {
describe('More Options Menu - Offline User', () => {
let xmlReportId;
let smsReportId;
before(async () => {
Expand All @@ -68,7 +68,7 @@ describe('More Options Menu - Offline User', async () => {

afterEach(async () => await commonPage.goToBase());

describe('all permissions enabled', async () => {
describe('all permissions enabled', () => {
it('- Message tab', async () => {
await commonPage.goToMessages();
await sms.sendSms('testing', contact.phone);
Expand Down Expand Up @@ -118,7 +118,7 @@ describe('More Options Menu - Offline User', async () => {
});
});

describe('all permissions disabled', async () => {
describe('all permissions disabled', () => {
before(async () => {
const allPermissions = ['can_edit', 'can_delete_contacts', 'can_export_all',
'can_export_contacts', 'can_export_messages',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const smsReport = reportFactory
{ patient, submitter: offlineUser.contact, fields: { lmp_date: 'Feb 3, 2022', patient_id: patient._id }, },
);

describe('- DELETE permissions disabled', async () => {
describe('- DELETE permissions disabled', () => {
let xmlReportId;
let smsReportId;
before(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const smsReport = reportFactory
{ patient, submitter: offlineUser.contact, fields: { lmp_date: 'Feb 3, 2022', patient_id: patient._id}, },
);

describe('- EDIT permissions disabled', async () => {
describe('- EDIT permissions disabled', () => {
let xmlReportId;
let smsReportId;
before(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const reports = [
reportFactory.report().build({ form: 'home_visit', content_type: 'xml' }, { patient, submitter: contact })
];

describe('- permissions disabled', async () => {
describe('- permissions disabled', () => {
before(async () => {
await utils.saveDocs([ ...places.values(), contact, patient, ...reports ]);
await sms.sendSms('testing', contact.phone);
Expand All @@ -53,7 +53,7 @@ describe('- permissions disabled', async () => {

after(async () => await utils.revertSettings(true));

describe('- export permissions disabled', async () => {
describe('- export permissions disabled', () => {
before(async () => {
const exportPermissions = ['can_export_all', 'can_export_contacts', 'can_export_messages'];
await utils.updatePermissions(onlineUser.roles, [], exportPermissions);
Expand Down Expand Up @@ -87,7 +87,7 @@ describe('- permissions disabled', async () => {
});
});

describe('- DELETE permissions disabled', async () => {
describe('- DELETE permissions disabled', () => {
before(async () => {
await utils.updatePermissions(onlineUser.roles, [], ['can_delete_contacts', 'can_delete_reports']);
await commonPage.closeReloadModal();
Expand All @@ -109,7 +109,7 @@ describe('- permissions disabled', async () => {
});
});

describe('- EDIT permissions disabled', async () => {
describe('- EDIT permissions disabled', () => {
before(async () => {
await utils.updatePermissions(onlineUser.roles, [], ['can_edit']);
await commonPage.closeReloadModal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ const smsReport = reportFactory
{ patient, submitter: contact, fields: { lmp_date: 'Dec 3, 2022', patient_id: patient._id}, },
);

describe('Online User', async () => {
describe('Online User', () => {

afterEach(async () => await commonPage.goToBase());

describe('Options disabled when no items - messages, contacts, people', async () => {
describe('Options disabled when no items - messages, contacts, people', () => {
before(async () => await loginPage.cookieLogin());

it('- Message tab', async () => {
Expand All @@ -80,7 +80,7 @@ describe('Online User', async () => {
});
});

describe(' - Contact tab - user has no contact ', async () => {
describe(' - Contact tab - user has no contact ', () => {
before(async () => await utils.saveDocs([ ...places.values(), contact, patient]));

it(' - no contact selected', async () => {
Expand All @@ -92,7 +92,7 @@ describe('Online User', async () => {
});
});

describe(' - Options enabled when there are items', async () => {
describe(' - Options enabled when there are items', () => {
let xmlReportId;
let smsReportId;

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/default/navigation/bfcache.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const loginPage = require('@page-objects/default/login/login.wdio.page');
const usersAdminPage = require('@page-objects/default/users/user.wdio.page');
const constants = require('@constants');

describe('bfcache', async () => {
describe('bfcache', () => {
beforeEach(async () => {
await loginPage.login({
username: constants.USERNAME,
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/default/navigation/hamburger-menu.wdio-spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const commonPage = require('@page-objects/default/common/common.wdio.page');
const loginPage = require('@page-objects/default/login/login.wdio.page');

describe('Hamburger Menu tests', async () => {
describe('Hamburger Menu tests', () => {
before(async () => {
await loginPage.cookieLogin();
});

beforeEach(async () => {
afterEach(async () => {
await commonPage.goToReports();
});

Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/default/navigation/navigation.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const userFactory = require('@factories/cht/users/users');
const placeFactory = require('@factories/cht/contacts/place');


describe('Navigation tests', async () => {
describe('Navigation functionality', async () => {
describe('Navigation tests', () => {
describe('Navigation functionality', () => {
before(async () => {
await loginPage.cookieLogin();
});
Expand Down Expand Up @@ -42,7 +42,7 @@ describe('Navigation tests', async () => {
});
});

describe('Navigation view', async () => {
describe('Navigation view', () => {
const places = placeFactory.generateHierarchy();
const districtHospital = places.get('district_hospital');
const user = userFactory.build({ place: districtHospital._id, roles: ['chw'] });
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/default/reports/search-reports.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const personFactory = require('@factories/cht/contacts/person');
const pregnancyFactory = require('@factories/cht/reports/pregnancy');
const smsPregnancyFactory = require('@factories/cht/reports/sms-pregnancy');

describe('Reports Search', async () => {
describe('Reports Search', () => {
const sittuHospital = placeFactory.place().build({ name: 'Sittu Hospital', type: 'district_hospital' });
const potuHospital = placeFactory.place().build({ name: 'Potu Hospital', type: 'district_hospital' });

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/standard/sms/registration-by-sms.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const userFactory = require('@factories/cht/users/users');
const gatewayApiUtils = require('@utils/gateway-api');
const reportsPage = require('@page-objects/default/reports/reports.wdio.page');

describe('Registration by SMS', async () => {
describe('Registration by SMS', () => {
const district_hospital = placeFactory.generateHierarchy(['district_hospital']).get('district_hospital');
const user = userFactory.build({ place: district_hospital._id });

Expand Down
34 changes: 4 additions & 30 deletions tests/e2e/upgrade/upgrade.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,13 @@ const deleteUpgradeLogs = async () => {
await utils.logsDb.bulkDocs(logs);
};

// ToDo: Remove once 4.4 is released. Because it needs selectors targeting the previous cht version.
const oldLogout = async () => {
await commonPage.openHamburgerMenu();
await (await commonPage.logoutButton()).waitForClickable();
await (await commonPage.logoutButton()).click();
$('.modal-dialog .modal-body').waitForDisplayed();
const submitBtn = $('.modal-dialog a.btn.submit');
await (await submitBtn).waitForClickable();
await (await submitBtn).click();
await browser.pause(100); // Wait for login page js to execute
};

// ToDo: Remove once 4.4 is released. Because it needs selectors targeting the previous cht version.
const oldCloseReloadModal = async () => {
try {
const reloadModalUpdate = $('#update-available [test-id="Update"]');
await browser.waitUntil(async () => await (await reloadModalUpdate).waitForExist({ timeout: 5000 }));
// Wait for the animation to complete
await browser.pause(500);
await (await reloadModalUpdate).click();
await browser.pause(500);
return true;
} catch (err) {
console.error('Reload modal not showed up');
return false;
}
};

describe('Performing an upgrade', () => {
before(async () => {
await utils.saveDocs([...docs.places, ...docs.clinics, ...docs.persons, ...docs.reports]);
await utils.createUsers([docs.user]);

await loginPage.login(docs.user);
await oldLogout;
await commonPage.logout();

await loginPage.cookieLogin({
username: constants.USERNAME,
Expand Down Expand Up @@ -136,8 +108,10 @@ describe('Performing an upgrade', () => {

await adminPage.logout();
await loginPage.login(docs.user);
await oldCloseReloadModal();
await commonPage.sync(true);

await browser.refresh();
await commonPage.waitForPageLoaded();
await commonPage.goToAboutPage();
expect(await upgradePage.getCurrentVersion()).to.include(TAG ? TAG : `${BRANCH} (`);
await commonPage.logout();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const utils = require('@utils');

describe('Sentinel transition error log', async function() {
describe('Sentinel transition error log', function() {

after(async () => await utils.revertSettings(true));

Expand Down
9 changes: 9 additions & 0 deletions tests/page-objects/default/about/about.wdio.page.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const userName = () => $('dt=User name');
const partners = () => $('.partners');
const version = () => $('[test-id="about-version"]');
const RELOAD_BUTTON = '.about.page .mat-primary';

const getPartnerImage = async (name) => {
await (await partners()).waitForDisplayed();
Expand All @@ -9,8 +11,15 @@ const getPartnerImage = async (name) => {
return partnerImage.getAttribute('src');
};

const getVersion = async () => {
await (await version()).waitForDisplayed();
return await (await version()).getText();
};

module.exports = {
userName,
partners,
getPartnerImage,
getVersion,
RELOAD_BUTTON,
};
4 changes: 2 additions & 2 deletions tests/page-objects/default/common/common.wdio.page.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const modalPage = require('./modal.wdio.page');
const constants = require('@constants');
const aboutPage = require('@page-objects/default/about/about.wdio.page');

const hamburgerMenu = () => $('#header-dropdown-link');
const userSettingsMenuOption = () => $('[test-id="user-settings-menu-option"]');
Expand Down Expand Up @@ -44,7 +45,6 @@ const FEEDBACK_MENU = '#header-dropdown i.fa-bug';
const FEEDBACK = '#feedback';
//About menu
const ABOUT_MENU = '#header-dropdown i.fa-question';
const RELOAD_BUTTON = '.about.page .btn-primary';
//Configuration App
const CONFIGURATION_APP_MENU = '#header-dropdown i.fa-cog';

Expand Down Expand Up @@ -360,7 +360,7 @@ const closeReportBug = async () => {
const openAboutMenu = async () => {
await (await $(ABOUT_MENU)).waitForClickable();
await (await $(ABOUT_MENU)).click();
await (await $(RELOAD_BUTTON)).waitForDisplayed();
await (await $(aboutPage.RELOAD_BUTTON)).waitForDisplayed();
};

const openUserSettings = async () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ const waitForDockerLogs = (container, ...regex) => {

const promise = new Promise((resolve, reject) => {
timeout = setTimeout(() => {
console.log('Found logs', logs, 'watched for', ...regex);
console.log('Found logs', logs, 'did not match expected regex:', ...regex);
reject(new Error('Timed out looking for details in logs.'));
killSpawnedProcess(proc);
}, 20000);
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/ts/modules/about/about.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h3>{{'reload.app' | translate}}</h3>
<h3 (click)="secretDoor()">{{'about' | translate}}</h3>
<dl class="horizontal">
<dt>{{'version' | translate}}</dt>
<dd>{{version}}</dd>
<dd test-id="about-version">{{version}}</dd>
<span>
<dt>{{'debug.supported_browser' | translate}}</dt>
<dd *ngIf="browserSupport.isUsingSupportedEnvironment; else unsupportedBrowser">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('Add Read Status Service', () => {
});
});

describe('updateMessages()', async () => {
describe('updateMessages()', () => {
it('should return given when no models', async () => {
const result = await service.updateMessages([]);

Expand Down
Loading

0 comments on commit 99c024d

Please sign in to comment.