Skip to content

Commit

Permalink
Backport repeat translation fix to 3.14.x (#7544)
Browse files Browse the repository at this point in the history
  • Loading branch information
m5r authored Mar 2, 2022
1 parent 6df7203 commit f79abb8
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 78 deletions.
172 changes: 125 additions & 47 deletions tests/e2e/forms/repeat-form.wdio-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,8 @@ const loginPage = require('../../page-objects/login/login.wdio.page');
const commonPage = require('../../page-objects/common/common.wdio.page');
const reportsPage = require('../../page-objects/reports/reports.wdio.page');

const xml = fs.readFileSync(`${__dirname}/../../forms/repeat-translation.xml`, 'utf8');
const formDocument = {
_id: 'form:repeat-translation',
internalId: 'repeat-translation',
title: 'Repeat',
type: 'form',
_attachments: {
xml: {
content_type: 'application/octet-stream',
data: Buffer.from(xml).toString('base64')
}
}
};
const countFormDocument = readFormDocument('repeat-translation-count');
const buttonFormDocument = readFormDocument('repeat-translation-button');
const userContactDoc = {
_id: constants.USER_CONTACT_ID,
name: 'Jack',
Expand All @@ -36,7 +25,7 @@ const userContactDoc = {

describe('RepeatForm', () => {
before(async () => {
await utils.seedTestData(userContactDoc, [formDocument]);
await utils.seedTestData(userContactDoc, [countFormDocument, buttonFormDocument]);
});

afterEach(async () => {
Expand All @@ -45,49 +34,138 @@ describe('RepeatForm', () => {
});

const selectorPrefix = '#report-form .active';
const stateLabelPath = `${selectorPrefix}.question-label[data-itext-id="/repeat-translation/basic/state_1:label"]`;
const cityLabelPath = `${selectorPrefix}.question-label[data-itext-id="/repeat-translation/basic/rep/city_1:label"]`;
const melbourneLabelPath = `${selectorPrefix}[data-itext-id="/repeat-translation/basic/rep/city_1/melbourne:label"]`;
const stateLabelPath = `${selectorPrefix}.question-label[data-itext-id="/repeat_translation/basic/state_1:label"]`;
const cityLabelPath = `${selectorPrefix}.question-label[data-itext-id="/repeat_translation/basic/rep/city_1:label"]`;
const melbourneLabelPath = `${selectorPrefix}[data-itext-id="/repeat_translation/basic/rep/city_1/melbourne:label"]`;

it('should display the initial form and its repeated content in Swahili', async () => {
const swUserName = 'Jina la mtumizi';
await loginPage.changeLanguage('sw', swUserName);
await loginPage.login({ username: auth.username, password: auth.password, createUser: true });
await commonPage.goToBase();
await commonPage.goToReports();
await (await reportsPage.submitReportButton()).click();
await (await reportsPage.formActionsLink(formDocument.internalId)).click();
describe('Repeat form with count input', () => {
const inputCountPath = `${selectorPrefix}[data-itext-id="/repeat_translation/basic/count:label"] ~ input`;

it('should display the initial form and its repeated content in Nepali', async () => {
const neUserName = 'प्रयोगकर्ताको नाम';
await loginPage.changeLanguage('ne', neUserName);
await login();
await openRepeatForm(countFormDocument.internalId);

const stateLabel = await $(stateLabelPath);
expect(await stateLabel.getText()).to.equal('Select a state: - NE');
const inputCount = await $(inputCountPath);
expect(await inputCount.getValue()).to.equal('1');
await assertLabels({ selector: cityLabelPath, count: 1, labelText: 'Select a city: - NE' });
await assertLabels({ selector: melbourneLabelPath, count: 1, labelText: 'ML (NE)' });

const stateLabel = await $(stateLabelPath);
expect(await stateLabel.getText()).to.equal('Select a state: - SV');
await repeatForm(3);

await reportsPage.repeatForm();
await assertLabels({ selector: cityLabelPath, count: 3, labelText: 'Select a city: - NE' });
await assertLabels({ selector: melbourneLabelPath, count: 3, labelText: 'ML (NE)' });
});

const cityLabel = await $(cityLabelPath);
expect(await cityLabel.getText()).to.equal('Select a city: - SV');
it('should display the initial form and its repeated content in English', async () => {
const enUserName = 'User name';
await loginPage.changeLanguage('en', enUserName);
await login();
await openRepeatForm(countFormDocument.internalId);

const melbourneLabel = await $(melbourneLabelPath);
expect(await melbourneLabel.getText()).to.equal('ML');
const stateLabel = await $(stateLabelPath);
expect(await stateLabel.getText()).to.equal('Select a state:');
const inputCount = await $(inputCountPath);
expect(await inputCount.getValue()).to.equal('1');
await assertLabels({ selector: cityLabelPath, count: 1, labelText: 'Select a city:' });
await assertLabels({ selector: melbourneLabelPath, count: 1, labelText: 'Melbourne' });

await repeatForm(3);

await assertLabels({ selector: cityLabelPath, count: 3, labelText: 'Select a city:' });
await assertLabels({ selector: melbourneLabelPath, count: 3, labelText: 'Melbourne' });
});

async function repeatForm(count) {
const inputCount = await $(inputCountPath);
await inputCount.setValue(count);
const stateLabel = await $(stateLabelPath);
await stateLabel.click(); // trigger a blur event to trigger the enketo form change listener
expect(await inputCount.getValue()).to.equal(count.toString());
}
});

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: auth.username, password: auth.password, createUser: true });
await commonPage.goToBase();
await commonPage.goToReports();
await (await reportsPage.submitReportButton()).click();
await (await reportsPage.formActionsLink(formDocument.internalId)).click();
describe('Repeat form with repeat button', () => {
it('should display the initial form and its repeated content in Swahili', async () => {
const swUserName = 'Jina la mtumizi';
await loginPage.changeLanguage('sw', swUserName);
await login();
await openRepeatForm(buttonFormDocument.internalId);

const stateLabel = await $(stateLabelPath);
expect(await stateLabel.getText()).to.equal('Select a state:');
const stateLabel = await $(stateLabelPath);
expect(await stateLabel.getText()).to.equal('Select a state: - SV');
await assertLabels({ selector: cityLabelPath, count: 0, labelText: 'Select a city: - SV' });
await assertLabels({ selector: melbourneLabelPath, count: 0, labelText: 'ML (SV)' });

await reportsPage.repeatForm();
await repeatForm();
await repeatForm();
await repeatForm();

const cityLabel = await $(cityLabelPath);
expect(await cityLabel.getText()).to.equal('Select a city:');
await assertLabels({ selector: cityLabelPath, count: 3, labelText: 'Select a city: - SV' });
await assertLabels({ selector: melbourneLabelPath, count: 3, labelText: 'ML (SV)' });
});

const melbourneLabel = await $(melbourneLabelPath);
expect(await melbourneLabel.getText()).to.equal('Melbourne');
it('should display the initial form and its repeated content in English', async () => {
const enUserName = 'User name';
await loginPage.changeLanguage('en', enUserName);
await login();
await openRepeatForm(buttonFormDocument.internalId);

const stateLabel = await $(stateLabelPath);
expect(await stateLabel.getText()).to.equal('Select a state:');
await assertLabels({ selector: cityLabelPath, count: 0, labelText: 'Select a city:' });
await assertLabels({ selector: melbourneLabelPath, count: 0, labelText: 'Melbourne' });

await repeatForm();
await repeatForm();
await repeatForm();

await assertLabels({ selector: cityLabelPath, count: 3, labelText: 'Select a city:' });
await assertLabels({ selector: melbourneLabelPath, count: 3, labelText: 'Melbourne' });
});

async function repeatForm() {
const addRepeatButton = await $('.btn.btn-default.add-repeat-btn');
await addRepeatButton.click();
}
});

async function assertLabels({ selector, count, labelText }) {
const labels = await $$(selector);
expect(labels.length).to.equal(count);
await Promise.all(labels.map(
async label => expect(await label.getText()).to.equal(labelText),
));
}

async function login() {
await loginPage.login({ username: auth.username, password: auth.password, createUser: true });
await commonPage.goToBase();
}

async function openRepeatForm(formInternalId) {
await commonPage.goToReports();
await (await reportsPage.submitReportButton()).click();
await (await reportsPage.formActionsLink(formInternalId)).click();
}
});

function readFormDocument(formId) {
const form = fs.readFileSync(`${__dirname}/../../forms/${formId}.xml`, 'utf8');
const formDocument = {
_id: `form:${formId}`,
internalId: formId,
title: `Form ${formId}`,
type: 'form',
_attachments: {
xml: {
content_type: 'application/octet-stream',
data: Buffer.from(form).toString('base64')
}
}
};
return formDocument;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,42 @@
<model>
<itext>
<translation lang="en">
<text id="/repeat-translation/basic/rep/city_1/melbourne:label">
<text id="/repeat_translation/basic/rep/city_1/melbourne:label">
<value>Melbourne</value>
</text>
<text id="/repeat-translation/basic/rep/city_1:label">
<text id="/repeat_translation/basic/rep/city_1:label">
<value>Select a city:</value>
</text>
<text id="/repeat-translation/basic/state_1/VIC:label">
<text id="/repeat_translation/basic/state_1/VIC:label">
<value>Victoria</value>
</text>
<text id="/repeat-translation/basic/state_1:label">
<text id="/repeat_translation/basic/state_1:label">
<value>Select a state:</value>
</text>
<text id="/repeat-translation/basic:label">
<text id="/repeat_translation/basic:label">
<value>Cascading Selects:</value>
</text>
</translation>
<translation lang="sw">
<text id="/repeat-translation/basic/rep/city_1/melbourne:label">
<value>ML</value>
<text id="/repeat_translation/basic/rep/city_1/melbourne:label">
<value>ML (SV)</value>
</text>
<text id="/repeat-translation/basic/rep/city_1:label">
<text id="/repeat_translation/basic/rep/city_1:label">
<value>Select a city: - SV</value>
</text>
<text id="/repeat-translation/basic/state_1/VIC:label">
<value>VIC</value>
<text id="/repeat_translation/basic/state_1/VIC:label">
<value>VIC (SV)</value>
</text>
<text id="/repeat-translation/basic/state_1:label">
<text id="/repeat_translation/basic/state_1:label">
<value>Select a state: - SV</value>
</text>
<text id="/repeat-translation/basic:label">
<text id="/repeat_translation/basic:label">
<value>Cascading Selects: - SV</value>
</text>
</translation>
</itext>
<instance>
<repeat id="repeat-translation" prefix="J1!repeat-translation!" delimiter="#" version="2019-08-09">
<repeat id="repeat_translation" prefix="J1!repeat_translation!" delimiter="#" version="2019-08-09">
<basic>
<state_1/>
<rep jr:template="">
Expand All @@ -53,28 +53,28 @@
</repeat>
</instance>
<instance id="contact-summary"/>
<bind nodeset="/repeat-translation/basic/state_1" type="select1"/>
<bind nodeset="/repeat-translation/basic/rep/city_1" type="select1"/>
<bind nodeset="/repeat-translation/meta/instanceID" type="string" readonly="true()" calculate="concat('uuid:', uuid())"/>
<bind nodeset="/repeat_translation/basic/state_1" type="select1"/>
<bind nodeset="/repeat_translation/basic/rep/city_1" type="select1"/>
<bind nodeset="/repeat_translation/meta/instanceID" type="string" readonly="true()" calculate="concat('uuid:', uuid())"/>
</model>
</h:head>
<h:body class="pages">
<group appearance="field-list" ref="/repeat-translation/basic">
<label ref="jr:itext('/repeat-translation/basic:label')"/>
<select1 ref="/repeat-translation/basic/state_1">
<label ref="jr:itext('/repeat-translation/basic/state_1:label')"/>
<group appearance="field-list" ref="/repeat_translation/basic">
<label ref="jr:itext('/repeat_translation/basic:label')"/>
<select1 ref="/repeat_translation/basic/state_1">
<label ref="jr:itext('/repeat_translation/basic/state_1:label')"/>
<item>
<label ref="jr:itext('/repeat-translation/basic/state_1/VIC:label')"/>
<label ref="jr:itext('/repeat_translation/basic/state_1/VIC:label')"/>
<value>VIC</value>
</item>
</select1>
<group ref="/repeat-translation/basic/rep">
<group ref="/repeat_translation/basic/rep">
<label></label>
<repeat nodeset="/repeat-translation/basic/rep">
<select1 ref="/repeat-translation/basic/rep/city_1">
<label ref="jr:itext('/repeat-translation/basic/rep/city_1:label')"/>
<repeat nodeset="/repeat_translation/basic/rep">
<select1 ref="/repeat_translation/basic/rep/city_1">
<label ref="jr:itext('/repeat_translation/basic/rep/city_1:label')"/>
<item>
<label ref="jr:itext('/repeat-translation/basic/rep/city_1/melbourne:label')"/>
<label ref="jr:itext('/repeat_translation/basic/rep/city_1/melbourne:label')"/>
<value>melbourne</value>
</item>
</select1>
Expand Down
Loading

0 comments on commit f79abb8

Please sign in to comment.