Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for language slug in metadata feature #1637

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,15 @@ public EvaluateXPathResponseBean menuEvaluateXpath(@RequestBody EvaluateXPathMen
public EvaluateXPathResponseBean evaluateXpath(@RequestBody EvaluateXPathRequestBean evaluateXPathRequestBean,
@CookieValue(Constants.POSTGRES_DJANGO_SESSION_ID) String authToken) throws Exception {
SerializableFormSession serializableFormSession = formSessionService.getSessionById(evaluateXPathRequestBean.getSessionId());
FormSession formEntrySession = formSessionFactory.getFormSession(serializableFormSession, evaluateXPathRequestBean.getWindowWidth());
FormSession formEntrySession;
String locale = evaluateXPathRequestBean.getLocale();
if (locale != null && locale.equals("test-locale")) {
formEntrySession = formSessionFactory.getFormSessionForTest(serializableFormSession,
evaluateXPathRequestBean.getWindowWidth(), evaluateXPathRequestBean.getLocale());
} else {
formEntrySession = formSessionFactory.getFormSession(serializableFormSession, evaluateXPathRequestBean.getWindowWidth());
}

EvaluateXPathResponseBean evaluateXPathResponseBean = new EvaluateXPathResponseBean(
formEntrySession.getFormEntryModel().getForm().getEvaluationContext(),
evaluateXPathRequestBean.getXpath(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.commcare.formplayer.session.FormSession;
import org.commcare.session.CommCareSession;
import org.javarosa.core.model.actions.FormSendCalloutHandler;
import org.javarosa.core.services.locale.Localization;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
Expand Down Expand Up @@ -60,4 +61,13 @@ public FormSession getFormSession(SerializableFormSession serializableFormSessio
windowWidth
);
}

public FormSession getFormSessionForTest(SerializableFormSession serializableFormSession, String windowWidth, String locale) throws Exception {
CommCareSession commCareSession = commCareSessionFactory.getCommCareSession(serializableFormSession.getMenuSessionId());
if (locale != null) {
Localization.getGlobalLocalizerAdvanced().addAvailableLocale(locale);
Localization.setLocale(locale);
}
return getFormSession(serializableFormSession, commCareSession, windowWidth);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class AuthenticatedRequestBean {
private int timezoneOffsetMillis = -1;
private String timezoneFromBrowser = null;
private String windowWidth;
private String locale;

public String getUsername() {
return username;
Expand Down Expand Up @@ -111,4 +112,14 @@ public String getWindowWidth() {
public void setWindowWidth(String windowWidth) {
this.windowWidth = windowWidth;
}

@JsonGetter(value = "locale")
public String getLocale() {
return locale;
}

@JsonSetter(value = "locale")
public void setLocale(String locale) {
this.locale = locale;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class EvaluateXpathRequest(
private val sessionId: String,
private val xpath: String,
private val formSessionService: FormSessionService,
private val windowWidth: String?
private val windowWidth: String?,
private val locale: String?
) : MockRequest<EvaluateXPathRequestBean, EvaluateXPathResponseBean>(
mockMvc, Constants.URL_EVALUATE_XPATH, EvaluateXPathResponseBean::class.java
) {
Expand All @@ -30,6 +31,7 @@ class EvaluateXpathRequest(
bean.xpath = xpath
bean.debugOutputLevel = Constants.BASIC_NO_TRACE
bean.windowWidth = windowWidth
bean.locale = locale

populateFromSession(bean)
return requestWithBean(bean)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ FormEntryResponseBean deleteRepeatRequest(String sessionId, String repeatIndex)
}

EvaluateXPathResponseBean evaluateXPath(String sessionId, String xPath) throws Exception {
return new EvaluateXpathRequest(mockDebuggerController, sessionId, xPath, formSessionService, null)
return new EvaluateXpathRequest(mockDebuggerController, sessionId, xPath, formSessionService, null, null)
.request()
.bean();
}
Expand Down Expand Up @@ -676,7 +676,7 @@ EvaluateXPathResponseBean evaluateMenuXpath(String menuSessionId, String xpath)
*/
protected void checkXpath(String sessionId, String xpath, String expectedValue)
throws Exception {
new EvaluateXpathRequest(mockDebuggerController, sessionId, xpath, formSessionService, null)
new EvaluateXpathRequest(mockDebuggerController, sessionId, xpath, formSessionService, null, null)
.request()
.andExpectAll(
jsonPath("status", equalTo(Constants.ANSWER_RESPONSE_STATUS_POSITIVE)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,27 @@ public void testWindowWidthParam() throws Exception {
NewFormResponse.class);
EvaluateXPathResponseBean evaluateXpathResponseBean = new EvaluateXpathRequest(mockDebuggerController,
formResp.getSessionId(), "instance('commcaresession')/session/context/window_width",
formSessionService, "test-window-width")
formSessionService, "test-window-width", null)
.request()
.bean();

assertEquals(evaluateXpathResponseBean.getStatus(), Constants.ANSWER_RESPONSE_STATUS_POSITIVE);
assertThat(evaluateXpathResponseBean.getOutput(), hasXpath("/result", equalTo("test-window-width")));
}

@Test
public void testLocaleParam() throws Exception {
NewFormResponse newFormResponse = this.sessionNavigate(new String[]{"0", "0"}, APP, "test-locale", NewFormResponse.class);
EvaluateXPathResponseBean xpathBean = new EvaluateXpathRequest(mockDebuggerController,
newFormResponse.getSessionId(), "instance('commcaresession')/session/context/applanguage",
formSessionService, null, "test-locale")
.request()
.bean();

assertEquals(xpathBean.getStatus(), Constants.ANSWER_RESPONSE_STATUS_POSITIVE);
assertThat(xpathBean.getOutput(), hasXpath("/result", equalTo("test-locale")));
}

@Test
public void testConfirmedSelectionsForMultiSelectCaseList() {
String[] selections = new String[]{"0", "1", "use_selected_values"};
Expand Down
Loading