Skip to content

Commit 2afbb8d

Browse files
committed
fix(#9732): address review feedback
1 parent c73bd10 commit 2afbb8d

4 files changed

Lines changed: 90 additions & 1 deletion

File tree

‎api/src/templates/privacy-policy/index.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<div>
3636
<h1>{{ translations.title }}</h1>
3737
</div>
38-
<div>
38+
<div id="privacy-policy-content">
3939
{{ policy }}
4040
</div>
4141
<div>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const utils = require('@utils');
2+
const commonPage = require('@page-objects/default/common/common.wdio.page.js');
3+
const loginPage = require('@page-objects/default/login/login.wdio.page');
4+
const privacyPolicyFactory = require('@factories/cht/settings/privacy-policy');
5+
const loginPrivacyPolicyPage = require('@page-objects/default/privacy-policy/login-privacy-policy.wdio.page');
6+
7+
describe('Privacy Policy Navigation for Unauthenticated Users', () => {
8+
const privacyPolicy = privacyPolicyFactory.privacyPolicy().build();
9+
10+
afterEach(async () => {
11+
await utils.deleteAllDocs();
12+
});
13+
14+
it('should not display privacy policy page when the privacy policy is not enabled', async () => {
15+
await commonPage.reloadSession();
16+
17+
// Assert: privacy policy link is not available on the login page
18+
const privacyPolicyLink = await loginPage.privacyPolicyPageLink();
19+
expect(await privacyPolicyLink.isDisplayed()).to.equal(false);
20+
});
21+
22+
it('should navigate back to the login page when using either back button', async () => {
23+
await utils.saveDocs([privacyPolicy]);
24+
await commonPage.reloadSession();
25+
26+
// Navigate to privacy policy page
27+
await loginPage.goToPrivacyPolicyPage();
28+
const privacyContent = await loginPrivacyPolicyPage.privacyContent();
29+
expect(await privacyContent.isDisplayed()).to.equal(true);
30+
31+
// Test navigation using both back buttons
32+
const testBackButton = async (backButtonType) => {
33+
let backButton;
34+
35+
if (backButtonType === 'top') {
36+
backButton = await loginPrivacyPolicyPage.topBackButton();
37+
} else if (backButtonType === 'bottom') {
38+
await loginPrivacyPolicyPage.scrollToBottom();
39+
backButton = await loginPrivacyPolicyPage.bottomBackButton();
40+
}
41+
42+
// Click the back button
43+
await loginPrivacyPolicyPage.goBackToLoginPage(backButton);
44+
45+
// Assert: back button redirects to the login page
46+
expect((await browser.getUrl()).includes('/medic/login')).to.be.true;
47+
48+
// Navigate back to the privacy policy page for the next iteration
49+
await loginPage.goToPrivacyPolicyPage();
50+
};
51+
52+
// Run tests for both buttons
53+
await testBackButton('top');
54+
await testBackButton('bottom');
55+
});
56+
});

‎tests/page-objects/default/login/login.wdio.page.js‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const labelForPassword = () => $('label[for="password"]');
1111
const errorMessageField = () => $('p.error.incorrect');
1212
const localeByName = (locale) => $(`.locale[name="${locale}"]`);
1313
const tokenLoginError = (reason) => $(`.error.${reason}`);
14+
const privacyPolicyPageLink = () => $('a[translate="privacy.policy"]');
1415

1516
const getErrorMessage = async () => {
1617
await (await errorMessageField()).waitForDisplayed();
@@ -133,6 +134,10 @@ const setPasswordValue = async (password) => {
133134
await (await passwordField()).setValue(password);
134135
};
135136

137+
const goToPrivacyPolicyPage = async () => {
138+
await (await privacyPolicyPageLink()).click();
139+
};
140+
136141
module.exports = {
137142
login,
138143
cookieLogin,
@@ -147,4 +152,6 @@ module.exports = {
147152
getErrorMessage,
148153
togglePassword,
149154
setPasswordValue,
155+
privacyPolicyPageLink,
156+
goToPrivacyPolicyPage
150157
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const privacyContent = () => $('#privacy-policy-content');
2+
const backButtons = () => $$('a.back-button');
3+
4+
const topBackButton = async () => {
5+
return (await backButtons())[0];
6+
};
7+
8+
const bottomBackButton = async () => {
9+
return (await backButtons())[1];
10+
};
11+
12+
const scrollToBottom = async () => {
13+
await (await bottomBackButton()).scrollIntoView();
14+
};
15+
16+
const goBackToLoginPage = async (backButton) => {
17+
await (backButton).click();
18+
};
19+
20+
module.exports = {
21+
privacyContent,
22+
topBackButton,
23+
bottomBackButton,
24+
scrollToBottom,
25+
goBackToLoginPage
26+
};

0 commit comments

Comments
 (0)