Skip to content

Commit 5157ee9

Browse files
authored
chore(#9660): update e2e sync function (#9659)
When the app syncs, and gets an update, the notification modal can appear before the sync status is updated to successful, and when it appears, it closes the sidebar menu. Try to close the modal quickly every time an update is expected and wdio interacts with the menu instead, of waiting for multiple seconds and then retrying. #9660
1 parent b5c91d9 commit 5157ee9

26 files changed

+117
-114
lines changed

Diff for: tests/e2e/default/admin/admin-access.wdio-spec.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ describe('Acessing the admin app', () => {
1010
const parent = placeFactory.place().build({ _id: 'dist1', type: 'district_hospital' });
1111

1212
afterEach(async () => {
13-
await browser.reloadSession();
14-
await browser.url('/');
13+
await common.reloadSession();
1514
});
1615

1716
it('should redirect to login when not logged in', async () => {

Diff for: tests/e2e/default/contacts/contact-details.wdio-spec.js

+3-7
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ describe('Contact details page.', () => {
8080
{ roles: settings.roles, permissions: settings.permissions },
8181
{ revert: true, ignoreReload: true }
8282
);
83-
8483
};
8584

8685
before(async () => {
@@ -91,7 +90,6 @@ describe('Contact details page.', () => {
9190
await utils.createUsers([user]);
9291

9392
await loginPage.login(user);
94-
await commonElements.waitForPageLoaded();
9593
});
9694

9795
after(async () => {
@@ -124,8 +122,7 @@ describe('Contact details page.', () => {
124122

125123
it('should not show reports when permission is disabled', async () => {
126124
await updatePermissions(ROLE, [], ['can_view_reports']);
127-
await commonElements.sync(true);
128-
await browser.refresh();
125+
await commonElements.sync({ expectReload: true, reload: true });
129126
await waitForContactLoaded(true);
130127

131128
expect(await (await contactPage.reportsCardSelectors.rhsReportListElement()).isDisplayed()).to.equal(false);
@@ -135,8 +132,7 @@ describe('Contact details page.', () => {
135132

136133
it('should not show tasks when permission is disabled', async () => {
137134
await updatePermissions(ROLE, ['can_view_reports'], ['can_view_tasks']);
138-
await commonElements.sync(true);
139-
await browser.refresh();
135+
await commonElements.sync({ reload: true, expectReload: true });
140136
await waitForContactLoaded(false);
141137

142138
expect(await (await contactPage.reportsCardSelectors.rhsReportListElement()).isDisplayed()).to.equal(true);
@@ -160,7 +156,7 @@ describe('Contact details page.', () => {
160156
const contactSummaryFile = path.join(__dirname, 'config/contact-summary-error-config.js');
161157

162158
const { contactSummary } = await chtConfUtils.compileNoolsConfig({ contactSummary: contactSummaryFile });
163-
await utils.updateSettings({ contact_summary: contactSummary }, true);
159+
await utils.updateSettings({ contact_summary: contactSummary }, { ignoreReload: true });
164160

165161
await utils.saveDocs([...places.values(), patient]);
166162
});

Diff for: tests/e2e/default/contacts/muting-contact-using-form.wdio-spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('Mute/Unmute contacts using a specific form - ', () => {
6868

6969
it('should show a popup when trying to submit a non-unmuting form against a muted contact', async () => {
7070
await utils.revertSettings(true);
71-
await commonPage.sync(true);
71+
await commonPage.sync({ expectReload: true });
7272
await commonPage.goToPeople(mutePerson._id);
7373

7474
const modalDetails = await contactPage.openFormWithWarning('death_report');

Diff for: tests/e2e/default/contacts/person-under-area.wdio-spec.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ describe('Create Person Under Area, ', () => {
3737
await usersAdminPage.inputAddUserFields(username, 'Jack', 'chw', healthCenter2.name, person2.name, password);
3838
await usersAdminPage.saveUser();
3939

40-
await browser.reloadSession();
41-
await browser.url('/');
42-
40+
await commonPage.reloadSession();
4341
await loginPage.login({ username, password });
4442

4543
await commonPage.goToPeople();

Diff for: tests/e2e/default/db/initial-replication.wdio-spec.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('initial-replication', () => {
5050
const localAllDocsPreSync = await chtDbUtils.getDocs();
5151
const docIdsPreSync = dataFactory.ids(localAllDocsPreSync);
5252

53-
await commonPage.sync(false, 7000);
53+
await commonPage.sync();
5454

5555
const localAllDocs = await chtDbUtils.getDocs();
5656
const localDocIds = dataFactory.ids(localAllDocs);
@@ -122,8 +122,7 @@ describe('initial-replication', () => {
122122
});
123123

124124
afterEach(async () => {
125-
await browser.reloadSession();
126-
await browser.url('/');
125+
await commonPage.reloadSession();
127126
});
128127

129128
it('should log user in', async () => {

Diff for: tests/e2e/default/db/ongoing-replication.wdio-spec.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('ongoing replication', function() {
4242
const isRevertingSettings = utils.revertSettings(true);
4343
if (isRevertingSettings) {
4444
await isRevertingSettings;
45-
await commonPage.sync(true, 30000);
45+
await commonPage.sync({ expectReload: true, timeout: 30000 });
4646
}
4747
});
4848

@@ -72,7 +72,7 @@ describe('ongoing replication', function() {
7272
await saveData(additionalDenied);
7373

7474
await browser.throttle('online');
75-
await commonPage.sync(false, 30000);
75+
await commonPage.sync({ expectReload: true, timeout: 30000 });
7676

7777
const localDocsPostSync = await chtDbUtils.getDocs();
7878
const localDocIds = dataFactory.ids(localDocsPostSync);
@@ -132,7 +132,7 @@ describe('ongoing replication', function() {
132132
await utils.addTranslations('rnd', {});
133133
await waitForServiceWorker.promise;
134134

135-
await commonPage.sync(true);
135+
await commonPage.sync({ expectReload: true });
136136
const [rnd] = await chtDbUtils.getDocs(['messages-rnd']);
137137
expect(rnd).to.include({
138138
type: 'translations',
@@ -144,7 +144,7 @@ describe('ongoing replication', function() {
144144
await utils.saveDoc(rnd);
145145
await waitForServiceWorker.promise;
146146

147-
await commonPage.sync(true);
147+
await commonPage.sync({ expectReload: true });
148148
const [updatedRnd] = await chtDbUtils.getDocs(['messages-rnd']);
149149
expect(updatedRnd.updated).to.equal(rnd.updated);
150150
});
@@ -161,7 +161,7 @@ describe('ongoing replication', function() {
161161
await utils.deleteDocs(docIdsToDelete);
162162
await waitForServiceWorker.promise;
163163

164-
await commonPage.sync(true);
164+
await commonPage.sync({ expectReload: true });
165165
const localDocsPostSync = await chtDbUtils.getDocs();
166166
const localDocIds = dataFactory.ids(localDocsPostSync);
167167

@@ -171,7 +171,7 @@ describe('ongoing replication', function() {
171171
it('should download settings updates', async () => {
172172
await commonPage.sync();
173173
await utils.updateSettings({ test: true }, { ignoreReload: 'api' });
174-
await commonPage.sync(true);
174+
await commonPage.sync({ expectReload: true });
175175
const [settings] = await chtDbUtils.getDocs(['settings']);
176176
expect(settings.settings.test).to.equal(true);
177177
});

Diff for: tests/e2e/default/enketo/extension-lib-form.wdio-spec.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ describe('Extension lib xpath function', () => {
1313

1414
const waitForServiceWorker = await utils.waitForApiLogs(utils.SW_SUCCESSFUL_REGEX);
1515
await waitForServiceWorker.promise;
16-
await browser.reloadSession();
17-
await browser.url('/');
16+
await commonPage.reloadSession();
1817
});
1918

2019
it('calculate average', async () => {

Diff for: tests/e2e/default/enketo/undo-death-report.wdio-spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('Submit an undo death report', () => {
2626
await commonPage.goToPeople(person._id);
2727
await commonPage.openFastActionReport('death_report');
2828
await deathReportForm.submitDeathReport();
29-
await commonPage.sync(true);
29+
await commonPage.sync({ expectReload: true });
3030
});
3131

3232
it('should submit an undo death report, ' +
@@ -43,7 +43,7 @@ describe('Submit an undo death report', () => {
4343
);
4444
await genericForm.submitForm();
4545
await commonPage.waitForPageLoaded();
46-
await commonPage.sync(true);
46+
await commonPage.sync({ expectReload: true });
4747

4848
expect(await (await contactPage.deathCardSelectors.deathCard()).isDisplayed()).to.be.false;
4949

Diff for: tests/e2e/default/login/login-logout.wdio-spec.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ describe('Login page funcionality tests', () => {
1111
};
1212

1313
afterEach(async () => {
14-
await browser.reloadSession();
15-
await browser.url('/');
14+
await commonPage.reloadSession();
1615
});
1716

1817
describe('Locale', () => {

Diff for: tests/e2e/default/more-options-menu/offline-user/all-permissions.wdio-spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ describe('More Options Menu - Offline User', () => {
128128
'can_export_contacts', 'can_export_messages',
129129
'can_delete_reports', 'can_update_reports'];
130130
await utils.updatePermissions(offlineUser.roles, [], allPermissions, true);
131-
await commonPage.sync(true);
131+
await commonPage.sync({ expectReload: true });
132132
});
133133

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

Diff for: tests/e2e/default/more-options-menu/offline-user/edit-permission-disabled.wdio-spec.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,8 @@ describe('More Options Menu - Offline User - Edit permissions disabled', () => {
5151
result = await utils.saveDoc(smsReport);
5252
smsReportId = result.id;
5353
await utils.createUsers([offlineUser]);
54+
await utils.updatePermissions(offlineUser.roles, [], ['can_edit'], true);
5455
await loginPage.login(offlineUser);
55-
await utils.updatePermissions(offlineUser.roles, [], ['can_edit']);
56-
await commonPage.closeReloadModal();
5756
});
5857

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

Diff for: tests/e2e/default/privacy-policy/privacy-policy.wdio-spec.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ describe('Privacy policy', () => {
2222
users.forEach((user) => {
2323
describe(`for an ${user.isOffline ? 'offline':'online'} user`, () => {
2424
before(async () => {
25-
await browser.reloadSession();
26-
await browser.url('/');
25+
await commonPage.reloadSession();
2726
await utils.saveDocs([parent, privacyPolicy]);
2827
await utils.createUsers([user]);
2928
await loginPage.login({ username: user.username, password: user.password, privacyPolicy: true });
@@ -51,16 +50,14 @@ describe('Privacy policy', () => {
5150
});
5251

5352
it('should not show on subsequent login', async () => {
54-
await browser.reloadSession();
55-
await browser.url('/');
53+
await commonPage.reloadSession();
5654
await loginPage.login({ username: user.username, password: user.password });
5755
await (await commonPage.tabsSelector.messagesTab()).waitForDisplayed();
5856
expect(await (await privacyPage.privacyWrapper()).isDisplayed()).to.not.be.true;
5957
});
6058

6159
it('should show french policy on secondary login', async () => {
62-
await browser.reloadSession();
63-
await browser.url('/');
60+
await commonPage.reloadSession();
6461
await loginPage.login({ username: user.username, password: user.password, locale: 'fr', privacyPolicy: true });
6562
await privacyPage.waitAndAcceptPolicy(await privacyPage.privacyWrapper(), frenchTexts);
6663
expect(await (await commonPage.tabsSelector.messagesTab()).isDisplayed()).to.be.true;
@@ -116,8 +113,7 @@ describe('Privacy policy', () => {
116113
before(async () => {
117114
await utils.saveDocs([parent, privacyPolicy]);
118115
await utils.createUsers([conflictUser]);
119-
await browser.reloadSession();
120-
await browser.url('/');
116+
await commonPage.reloadSession();
121117
await loginPage.login({ username: conflictUser.username, password: conflictUser.password, privacyPolicy: true });
122118
});
123119

Diff for: tests/e2e/default/purge/purge.wdio-spec.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ describe('purge', function() {
7979
await utils.deleteUsers([user]);
8080
await utils.revertDb([/^form:/], true);
8181

82-
await browser.reloadSession();
83-
await browser.url('/');
82+
await commonElements.reloadSession();
8483
});
8584

8685
it('purging runs on sync', async () => {
@@ -104,7 +103,7 @@ describe('purge', function() {
104103
await updatePurgeSettings(filterHomeVisitReports, true);
105104
await runPurging();
106105

107-
await commonElements.sync(true);
106+
await commonElements.sync({ expectReload: true });
108107

109108
allReports = await getAllReports();
110109
// this only works because the client didn't have to "purge" these docs and the revs didn't have

Diff for: tests/e2e/default/service-worker/service-worker.wdio-spec.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ describe('Service worker cache', () => {
6767
const chw = userFactory.build({ place: district._id });
6868

6969
const login = async () => {
70-
await browser.throttle('online');
7170
await loginPage.login(chw);
7271
await commonPage.waitForPageLoaded();
7372
};
@@ -78,6 +77,7 @@ describe('Service worker cache', () => {
7877
};
7978

8079
const loginIfNeeded = async () => {
80+
await browser.throttle('online');
8181
if (!await isLoggedIn()) {
8282
await login();
8383
}
@@ -93,6 +93,10 @@ describe('Service worker cache', () => {
9393
await loginIfNeeded();
9494
});
9595

96+
afterEach(async () => {
97+
await utils.revertSettings(true);
98+
});
99+
96100
after(async () => {
97101
await utils.deleteUsers([chw]);
98102
await utils.revertDb([/^form:/], true);
@@ -147,7 +151,7 @@ describe('Service worker cache', () => {
147151
await utils.saveDoc(branding);
148152
await waitForLogs.promise;
149153

150-
await commonPage.sync(true);
154+
await commonPage.sync({ expectReload: true, serviceWorkerUpdate: true });
151155
await browser.throttle('offline'); // make sure we load the login page from cache
152156
await commonPage.logout();
153157
expect(await browser.getTitle()).to.equal('Not Medic');
@@ -161,7 +165,7 @@ describe('Service worker cache', () => {
161165
});
162166
await waitForLogs.promise;
163167

164-
await commonPage.sync(true);
168+
await commonPage.sync({ expectReload: true, serviceWorkerUpdate: true });
165169
await browser.throttle('offline'); // make sure we load the login page from cache
166170
await commonPage.logout();
167171

@@ -172,7 +176,7 @@ describe('Service worker cache', () => {
172176
it('adding new languages triggers login page refresh', async () => {
173177
const languageCode = 'ro';
174178
await utils.enableLanguage(languageCode);
175-
await commonPage.sync(true);
179+
await commonPage.sync({ expectReload: true, serviceWorkerUpdate: true });
176180

177181
const waitForLogs = await utils.waitForApiLogs(utils.SW_SUCCESSFUL_REGEX);
178182
await utils.addTranslations(languageCode, {
@@ -183,20 +187,18 @@ describe('Service worker cache', () => {
183187
});
184188
await waitForLogs.promise;
185189

186-
await commonPage.sync(true);
190+
await commonPage.sync({ expectReload: true, serviceWorkerUpdate: true });
187191
await commonPage.logout();
188192

189193
await loginPage.changeLanguage(languageCode, 'Utilizator');
190194

191195
expect(await (await loginPage.labelForUser()).getText()).to.equal('Utilizator');
192196
expect(await (await loginPage.loginButton()).getText()).to.equal('Autentificare');
193197
expect(await (await loginPage.labelForPassword()).getText()).to.equal('Parola');
194-
195-
await utils.revertSettings(true);
196198
});
197199

198200
it('other translation updates do not trigger a login page refresh', async () => {
199-
await commonPage.sync(true);
201+
await commonPage.sync({ expectReload: true, serviceWorkerUpdate: true });
200202

201203
const cacheDetails = await getCachedRequests(true);
202204

@@ -207,7 +209,7 @@ describe('Service worker cache', () => {
207209
'some': 'thing',
208210
});
209211
await waitForLogs.promise;
210-
await commonPage.sync(true);
212+
await commonPage.sync({ expectReload: true, serviceWorkerUpdate: true });
211213

212214
const updatedCacheDetails = await getCachedRequests(true);
213215

0 commit comments

Comments
 (0)