diff --git a/app/src/androidTest/assets/quizzes/feedback_grade_boundaries.json b/app/src/androidTest/assets/quizzes/feedback_grade_boundaries.json index 9c9377c81..aca8c0bef 100644 --- a/app/src/androidTest/assets/quizzes/feedback_grade_boundaries.json +++ b/app/src/androidTest/assets/quizzes/feedback_grade_boundaries.json @@ -15,7 +15,7 @@ "availability":0, "showfeedback":2, "grade_boundaries": [ - {"0": "Quiz score is between 0% and 49%. MaxQuizScore: {{max_score}}; UserScore: {{user_score}}; QuizScore: {{score_percentage}}%"}, + {"20": "Quiz score is between 20% and 49%. MaxQuizScore: {{max_score}}; UserScore: {{user_score}}; QuizScore: {{score_percentage}}%"}, {"50": "Quiz score is between 50% and 99%. MaxQuizScore: {{max_score}}; UserScore: {{user_score}}; QuizScore: {{score_percentage}}%"}, {"100": "Quiz score is 100%. MaxQuizScore: {{max_score}}; UserScore: {{user_score}}; QuizScore: {{score_percentage}}%"} ] diff --git a/app/src/androidTest/assets/quizzes/feedback_multilang_grade_boundaries.json b/app/src/androidTest/assets/quizzes/feedback_multilang_grade_boundaries.json new file mode 100644 index 000000000..f17e0438e --- /dev/null +++ b/app/src/androidTest/assets/quizzes/feedback_multilang_grade_boundaries.json @@ -0,0 +1,229 @@ +{ + "id":3472, + "title":{ + "en":"Feedback Multilang Grade Boundaries" + }, + "description":{ + "en":"Feedback Multilang Grade Boundaries" + }, + "props":{ + "allowtryagain":1, + "courseversion":"20190521122247", + "maxattempts":0, + "digest":"b56d41a0bd7c93acdea034c50118414718295cr0s2a1p80a0m0", + "maxscore":8, + "availability":0, + "showfeedback":2, + "grade_boundaries": [ + {"0": "Quiz score is between 20% and 49%. MaxQuizScore: {{max_score}}; UserScore: {{user_score}}; QuizScore: {{score_percentage}}%"}, + {"50": "en=Quiz score is between 50% and 99%. MaxQuizScore: {{max_score}}; UserScore: {{user_score}}; QuizScore: {{score_percentage}}%\r\nes=La puntuación del quiz está entre 50% y 99%. PuntuaciónMáxima: {{max_score}}; PuntuaciónDelUsuario: {{user_score}}; PuntuaciónDelQuiz: {{score_percentage}}%"}, + {"100": "en=Quiz score is 100%. MaxQuizScore: {{max_score}}; UserScore: {{user_score}}; QuizScore: {{score_percentage}}%\r\nes=La puntuación del quiz es de 100%. PuntuaciónMáxima: {{max_score}}; PuntuaciónDelUsuario: {{user_score}}; PuntuaciónDelQuiz: {{score_percentage}}%"} + ] + }, + "questions":[ + { + "question":{ + "responses":[ + { + "title":{ + "en":"Response with score 2.0" + }, + "props":{ + "id":244 + }, + "order":1, + "score":"2.0000", + "id":103055 + }, + { + "title":{ + "en":"Response with score 1.0" + }, + "props":{ + "id":954 + }, + "order":2, + "score":"1.0000", + "id":103056 + }, + { + "title":{ + "en":"Response with score 0.0" + }, + "props":{ + "id":954 + }, + "order":2, + "score":"0.0000", + "id":103057 + } + ], + "props":{ + "maxscore":2, + "shuffleanswers":"1", + "required": false + }, + "type":"multichoice", + "id":36249, + "title":{ + "en":"Question 1" + } + }, + "order":1, + "id":36042 + }, + { + "question":{ + "responses":[ + { + "title":{ + "en":"Response with score 2.0" + }, + "props":{ + "id":244 + }, + "order":1, + "score":"2.0000", + "id":103058 + }, + { + "title":{ + "en":"Response with score 1.0" + }, + "props":{ + "id":954 + }, + "order":2, + "score":"1.0000", + "id":103059 + }, + { + "title":{ + "en":"Response with score 0.0" + }, + "props":{ + "id":954 + }, + "order":2, + "score":"0.0000", + "id":103060 + } + ], + "props":{ + "maxscore":2, + "shuffleanswers":"1", + "required": false + }, + "type":"multichoice", + "id":36250, + "title":{ + "en":"Question 2" + } + }, + "order":2, + "id":36043 + }, + { + "question":{ + "responses":[ + { + "title":{ + "en":"Response with score 2.0" + }, + "props":{ + "id":244 + }, + "order":1, + "score":"2.0000", + "id":103061 + }, + { + "title":{ + "en":"Response with score 1.0" + }, + "props":{ + "id":954 + }, + "order":2, + "score":"1.0000", + "id":103062 + }, + { + "title":{ + "en":"Response with score 0.0" + }, + "props":{ + "id":954 + }, + "order":2, + "score":"0.0000", + "id":103063 + } + ], + "props":{ + "maxscore":2, + "shuffleanswers":"1", + "required": false + }, + "type":"multichoice", + "id":36250, + "title":{ + "en":"Question 3" + } + }, + "order":3, + "id":36044 + }, + { + "question":{ + "responses":[ + { + "title":{ + "en":"Response with score 2.0" + }, + "props":{ + "id":244 + }, + "order":1, + "score":"2.0000", + "id":103064 + }, + { + "title":{ + "en":"Response with score 1.0" + }, + "props":{ + "id":954 + }, + "order":2, + "score":"1.0000", + "id":103065 + }, + { + "title":{ + "en":"Response with score 0.0" + }, + "props":{ + "id":954 + }, + "order":2, + "score":"0.0000", + "id":103066 + } + ], + "props":{ + "maxscore":2, + "shuffleanswers":"1", + "required": false + }, + "type":"multichoice", + "id":36250, + "title":{ + "en":"Question 4" + } + }, + "order":3, + "id":36045 + } + ] +} \ No newline at end of file diff --git a/app/src/androidTest/java/androidTestFiles/features/quiz/FeedbackGradeBoundariesUITest.java b/app/src/androidTest/java/androidTestFiles/features/quiz/FeedbackGradeBoundariesUITest.java index 16a8ed3cd..b6ab0cfe1 100644 --- a/app/src/androidTest/java/androidTestFiles/features/quiz/FeedbackGradeBoundariesUITest.java +++ b/app/src/androidTest/java/androidTestFiles/features/quiz/FeedbackGradeBoundariesUITest.java @@ -8,6 +8,8 @@ import static androidx.test.espresso.matcher.ViewMatchers.withText; import android.content.Context; +import android.content.res.Configuration; +import android.content.res.Resources; import android.os.Bundle; import androidx.test.ext.junit.runners.AndroidJUnit4; @@ -24,6 +26,7 @@ import org.junit.runner.RunWith; import java.util.ArrayList; +import java.util.Locale; import androidTestFiles.utils.FileUtils; @@ -33,13 +36,20 @@ public class FeedbackGradeBoundariesUITest { private static final String MULTICHOICE_NOFEEDBACK_JSON = "quizzes/multichoice_no_feedback.json"; private static final String FEEDBACK_GRADE_BOUNDARIES_JSON = "quizzes/feedback_grade_boundaries.json"; private static final String FEEDBACK_INCORRECT_GRADE_BOUNDARIES_JSON = "quizzes/feedback_incorrect_grade_boundaries.json"; - private static final String DEFAULT_LANG = "en"; + private static final String FEEDBACK_MULTILANG_GRADE_BOUNDARIES_JSON = "quizzes/feedback_multilang_grade_boundaries.json"; + private static final String EN_LANG = "en"; + private static final String ES_LANG = "es"; + private static final String FI_LANG = "fi"; private static String feedbackWithGradeBoundariesContent; private static String feedbackWithDefaultFeedbackMessageContent; private static String feedbackWithIncorrectGradeBoundariesContent; - private static final String FEEDBACK_MESSAGE_25 = "Quiz score is between 0% and 49%. MaxQuizScore: 8; UserScore: 2; QuizScore: 25%"; - private static final String FEEDBACK_MESSAGE_75 = "Quiz score is between 50% and 99%. MaxQuizScore: 8; UserScore: 6; QuizScore: 75%"; - private static final String FEEDBACK_MESSAGE_100 = "Quiz score is 100%. MaxQuizScore: 8; UserScore: 8; QuizScore: 100%"; + private static String feedbackWithMultilangGradeBoundariesContent; + private static final String DEFAULT_FEEDBACK_MESSAGE = "Thank you for submitting your feedback."; + private static final String FEEDBACK_MESSAGE_25_EN = "Quiz score is between 20% and 49%. MaxQuizScore: 8; UserScore: 2; QuizScore: 25%"; + private static final String FEEDBACK_MESSAGE_75_EN = "Quiz score is between 50% and 99%. MaxQuizScore: 8; UserScore: 6; QuizScore: 75%"; + private static final String FEEDBACK_MESSAGE_100_EN = "Quiz score is 100%. MaxQuizScore: 8; UserScore: 8; QuizScore: 100%"; + private static final String FEEDBACK_MESSAGE_75_ES = "La puntuación del quiz está entre 50% y 99%. PuntuaciónMáxima: 8; PuntuaciónDelUsuario: 6; PuntuaciónDelQuiz: 75%"; + private static final String FEEDBACK_MESSAGE_100_ES = "La puntuación del quiz es de 100%. PuntuaciónMáxima: 8; PuntuaciónDelUsuario: 8; PuntuaciónDelQuiz: 100%"; private static final String FEEDBACK_INCORRECT_MESSAGE = "Property missing double curly braces: {max_score}; Property does not exist: {{not_exist}}"; private static final String FEEDBACK_RESPONSE_SCORE_2 = "Response with score 2.0"; private static final String FEEDBACK_RESPONSE_SCORE_1 = "Response with score 1.0"; @@ -48,7 +58,6 @@ public class FeedbackGradeBoundariesUITest { private Activity act; private Bundle args; - @Before public void setup() throws Exception { Context context = InstrumentationRegistry.getInstrumentation().getContext(); @@ -56,19 +65,71 @@ public void setup() throws Exception { feedbackWithGradeBoundariesContent = FileUtils.getStringFromFile(context, FEEDBACK_GRADE_BOUNDARIES_JSON); feedbackWithDefaultFeedbackMessageContent = FileUtils.getStringFromFile(context, MULTICHOICE_NOFEEDBACK_JSON); feedbackWithIncorrectGradeBoundariesContent = FileUtils.getStringFromFile(context, FEEDBACK_INCORRECT_GRADE_BOUNDARIES_JSON); + feedbackWithMultilangGradeBoundariesContent = FileUtils.getStringFromFile(context, FEEDBACK_MULTILANG_GRADE_BOUNDARIES_JSON); act = new Activity(); - args = new Bundle(); args.putSerializable(Activity.TAG, act); args.putSerializable(Course.TAG, new Course("")); args.putBoolean(CourseActivity.BASELINE_TAG, true); } + private void changeDefaultLocale(String lang) { + Resources resources = InstrumentationRegistry.getInstrumentation().getTargetContext().getResources(); + Locale locale = new Locale(lang); + Locale.setDefault(locale); + Configuration config = resources.getConfiguration(); + config.locale = locale; + resources.updateConfiguration(config, resources.getDisplayMetrics()); + } + + @Test + public void test_gradeBoundary_feedback_0_default_message_is_shown() { + changeDefaultLocale(EN_LANG); + ArrayList contents = new ArrayList<>(); + contents.add(new Lang(EN_LANG, feedbackWithGradeBoundariesContent)); + act.setContents(contents); + + launchInContainer(FeedbackWidget.class, args, R.style.Oppia_ToolbarTheme); + + // Question 1 + onView(withId(R.id.question_text)) + .check(matches(withText("Question 1"))); + + onView(withText(FEEDBACK_RESPONSE_SCORE_0)).perform(click()); + onView(withId(R.id.mquiz_next_btn)).perform(click()); + + // Question 2 + onView(withId(R.id.question_text)) + .check(matches(withText("Question 2"))); + + onView(withText(FEEDBACK_RESPONSE_SCORE_0)).perform(click()); + onView(withId(R.id.mquiz_next_btn)).perform(click()); + + // Question 3 + onView(withId(R.id.question_text)) + .check(matches(withText("Question 3"))); + + onView(withText(FEEDBACK_RESPONSE_SCORE_0)).perform(click()); + onView(withId(R.id.mquiz_next_btn)).perform(click()); + + // Question 4 + onView(withId(R.id.question_text)) + .check(matches(withText("Question 4"))); + + onView(withText(FEEDBACK_RESPONSE_SCORE_0)).perform(click()); + onView(withId(R.id.mquiz_next_btn)).perform(click()); + + String expected = DEFAULT_FEEDBACK_MESSAGE; + onView(withId(R.id.quiz_results_score)) + .check(matches(withText(expected))); + } + @Test public void test_gradeBoundary_feedback_message_100_is_shown() { + changeDefaultLocale(EN_LANG); ArrayList contents = new ArrayList<>(); - contents.add(new Lang(DEFAULT_LANG, feedbackWithGradeBoundariesContent)); + contents.add(new Lang(EN_LANG, feedbackWithGradeBoundariesContent)); act.setContents(contents); launchInContainer(FeedbackWidget.class, args, R.style.Oppia_ToolbarTheme); @@ -101,15 +162,16 @@ public void test_gradeBoundary_feedback_message_100_is_shown() { onView(withText(FEEDBACK_RESPONSE_SCORE_2)).perform(click()); onView(withId(R.id.mquiz_next_btn)).perform(click()); - String expected = FEEDBACK_MESSAGE_100; + String expected = FEEDBACK_MESSAGE_100_EN; onView(withId(R.id.quiz_results_score)) .check(matches(withText(expected))); } @Test public void test_gradeBoundary_feedback_message_75_is_shown() { + changeDefaultLocale(EN_LANG); ArrayList contents = new ArrayList<>(); - contents.add(new Lang(DEFAULT_LANG, feedbackWithGradeBoundariesContent)); + contents.add(new Lang(EN_LANG, feedbackWithGradeBoundariesContent)); act.setContents(contents); launchInContainer(FeedbackWidget.class, args, R.style.Oppia_ToolbarTheme); @@ -142,16 +204,16 @@ public void test_gradeBoundary_feedback_message_75_is_shown() { onView(withText(FEEDBACK_RESPONSE_SCORE_2)).perform(click()); onView(withId(R.id.mquiz_next_btn)).perform(click()); - String expected = FEEDBACK_MESSAGE_75; + String expected = FEEDBACK_MESSAGE_75_EN; onView(withId(R.id.quiz_results_score)) .check(matches(withText(expected))); } @Test public void test_gradeBoundary_feedback_message_25_is_shown() { - + changeDefaultLocale(EN_LANG); ArrayList contents = new ArrayList<>(); - contents.add(new Lang(DEFAULT_LANG, feedbackWithGradeBoundariesContent)); + contents.add(new Lang(EN_LANG, feedbackWithGradeBoundariesContent)); act.setContents(contents); launchInContainer(FeedbackWidget.class, args, R.style.Oppia_ToolbarTheme); @@ -184,15 +246,16 @@ public void test_gradeBoundary_feedback_message_25_is_shown() { onView(withText(FEEDBACK_RESPONSE_SCORE_1)).perform(click()); onView(withId(R.id.mquiz_next_btn)).perform(click()); - String expected = FEEDBACK_MESSAGE_25; + String expected = FEEDBACK_MESSAGE_25_EN; onView(withId(R.id.quiz_results_score)) .check(matches(withText(expected))); } @Test public void test_no_gradeBoundary_default_feedback_message_is_shown() { + changeDefaultLocale(EN_LANG); ArrayList contents = new ArrayList<>(); - contents.add(new Lang(DEFAULT_LANG, feedbackWithDefaultFeedbackMessageContent)); + contents.add(new Lang(EN_LANG, feedbackWithDefaultFeedbackMessageContent)); act.setContents(contents); launchInContainer(FeedbackWidget.class, args, R.style.Oppia_ToolbarTheme); @@ -212,9 +275,9 @@ public void test_no_gradeBoundary_default_feedback_message_is_shown() { @Test public void test_gradeBoundary_incorrect_feedback_message_is_shown() { - + changeDefaultLocale(EN_LANG); ArrayList contents = new ArrayList<>(); - contents.add(new Lang(DEFAULT_LANG, feedbackWithIncorrectGradeBoundariesContent)); + contents.add(new Lang(EN_LANG, feedbackWithIncorrectGradeBoundariesContent)); act.setContents(contents); launchInContainer(FeedbackWidget.class, args, R.style.Oppia_ToolbarTheme); @@ -252,4 +315,176 @@ public void test_gradeBoundary_incorrect_feedback_message_is_shown() { .check(matches(withText(expected))); } + @Test + public void test_gradeBoundary_feedback_message_100_is_shown_ES() { + changeDefaultLocale(ES_LANG); + ArrayList contents = new ArrayList<>(); + contents.add(new Lang(ES_LANG, feedbackWithMultilangGradeBoundariesContent)); + act.setContents(contents); + + launchInContainer(FeedbackWidget.class, args, R.style.Oppia_ToolbarTheme); + + // Question 1 + onView(withId(R.id.question_text)) + .check(matches(withText("Question 1"))); + + onView(withText(FEEDBACK_RESPONSE_SCORE_2)).perform(click()); + onView(withId(R.id.mquiz_next_btn)).perform(click()); + + // Question 2 + onView(withId(R.id.question_text)) + .check(matches(withText("Question 2"))); + + onView(withText(FEEDBACK_RESPONSE_SCORE_2)).perform(click()); + onView(withId(R.id.mquiz_next_btn)).perform(click()); + + // Question 3 + onView(withId(R.id.question_text)) + .check(matches(withText("Question 3"))); + + onView(withText(FEEDBACK_RESPONSE_SCORE_2)).perform(click()); + onView(withId(R.id.mquiz_next_btn)).perform(click()); + + // Question 4 + onView(withId(R.id.question_text)) + .check(matches(withText("Question 4"))); + + onView(withText(FEEDBACK_RESPONSE_SCORE_2)).perform(click()); + onView(withId(R.id.mquiz_next_btn)).perform(click()); + + String expected = FEEDBACK_MESSAGE_100_ES; + onView(withId(R.id.quiz_results_score)) + .check(matches(withText(expected))); + } + + @Test + public void test_gradeBoundary_feedback_message_75_is_shown_ES() { + changeDefaultLocale(ES_LANG); + ArrayList contents = new ArrayList<>(); + contents.add(new Lang(ES_LANG, feedbackWithMultilangGradeBoundariesContent)); + act.setContents(contents); + + launchInContainer(FeedbackWidget.class, args, R.style.Oppia_ToolbarTheme); + + // Question 1 + onView(withId(R.id.question_text)) + .check(matches(withText("Question 1"))); + + onView(withText(FEEDBACK_RESPONSE_SCORE_0)).perform(click()); + onView(withId(R.id.mquiz_next_btn)).perform(click()); + + // Question 2 + onView(withId(R.id.question_text)) + .check(matches(withText("Question 2"))); + + onView(withText(FEEDBACK_RESPONSE_SCORE_2)).perform(click()); + onView(withId(R.id.mquiz_next_btn)).perform(click()); + + // Question 3 + onView(withId(R.id.question_text)) + .check(matches(withText("Question 3"))); + + onView(withText(FEEDBACK_RESPONSE_SCORE_2)).perform(click()); + onView(withId(R.id.mquiz_next_btn)).perform(click()); + + // Question 4 + onView(withId(R.id.question_text)) + .check(matches(withText("Question 4"))); + + onView(withText(FEEDBACK_RESPONSE_SCORE_2)).perform(click()); + onView(withId(R.id.mquiz_next_btn)).perform(click()); + + String expected = FEEDBACK_MESSAGE_75_ES; + onView(withId(R.id.quiz_results_score)) + .check(matches(withText(expected))); + } + + @Test + public void test_gradeBoundary_feedback_message_25_is_shown_ES() { + changeDefaultLocale(ES_LANG); + ArrayList contents = new ArrayList<>(); + contents.add(new Lang(ES_LANG, feedbackWithMultilangGradeBoundariesContent)); + act.setContents(contents); + + launchInContainer(FeedbackWidget.class, args, R.style.Oppia_ToolbarTheme); + + // Question 1 + onView(withId(R.id.question_text)) + .check(matches(withText("Question 1"))); + + onView(withText(FEEDBACK_RESPONSE_SCORE_0)).perform(click()); + onView(withId(R.id.mquiz_next_btn)).perform(click()); + + // Question 2 + onView(withId(R.id.question_text)) + .check(matches(withText("Question 2"))); + + onView(withText(FEEDBACK_RESPONSE_SCORE_0)).perform(click()); + onView(withId(R.id.mquiz_next_btn)).perform(click()); + + // Question 3 + onView(withId(R.id.question_text)) + .check(matches(withText("Question 3"))); + + onView(withText(FEEDBACK_RESPONSE_SCORE_1)).perform(click()); + onView(withId(R.id.mquiz_next_btn)).perform(click()); + + // Question 4 + onView(withId(R.id.question_text)) + .check(matches(withText("Question 4"))); + + onView(withText(FEEDBACK_RESPONSE_SCORE_1)).perform(click()); + onView(withId(R.id.mquiz_next_btn)).perform(click()); + + String expected = FEEDBACK_MESSAGE_25_EN; // This grade boundary is only in english, + // so even if the language is set to Spanish, + // the English message will be displayed + onView(withId(R.id.quiz_results_score)) + .check(matches(withText(expected))); + } + + @Test + public void test_gradeBoundary_feedback_message_100_is_shown_nonexisting_lang() { + changeDefaultLocale(FI_LANG); + ArrayList contents = new ArrayList<>(); + contents.add(new Lang(FI_LANG, feedbackWithMultilangGradeBoundariesContent)); + act.setContents(contents); + + launchInContainer(FeedbackWidget.class, args, R.style.Oppia_ToolbarTheme); + + // Question 1 + onView(withId(R.id.question_text)) + .check(matches(withText("Question 1"))); + + onView(withText(FEEDBACK_RESPONSE_SCORE_2)).perform(click()); + onView(withId(R.id.mquiz_next_btn)).perform(click()); + + // Question 2 + onView(withId(R.id.question_text)) + .check(matches(withText("Question 2"))); + + onView(withText(FEEDBACK_RESPONSE_SCORE_2)).perform(click()); + onView(withId(R.id.mquiz_next_btn)).perform(click()); + + // Question 3 + onView(withId(R.id.question_text)) + .check(matches(withText("Question 3"))); + + onView(withText(FEEDBACK_RESPONSE_SCORE_2)).perform(click()); + onView(withId(R.id.mquiz_next_btn)).perform(click()); + + // Question 4 + onView(withId(R.id.question_text)) + .check(matches(withText("Question 4"))); + + onView(withText(FEEDBACK_RESPONSE_SCORE_2)).perform(click()); + onView(withId(R.id.mquiz_next_btn)).perform(click()); + + String expected = FEEDBACK_MESSAGE_100_EN; // English message will be displayed because + // is the first defined language in the grade boundary message + onView(withId(R.id.quiz_results_score)) + .check(matches(withText(expected))); + + } + } diff --git a/app/src/main/java/org/digitalcampus/mobile/quiz/Quiz.java b/app/src/main/java/org/digitalcampus/mobile/quiz/Quiz.java index 2df4e1ba7..30d7b0adc 100644 --- a/app/src/main/java/org/digitalcampus/mobile/quiz/Quiz.java +++ b/app/src/main/java/org/digitalcampus/mobile/quiz/Quiz.java @@ -574,7 +574,7 @@ public void updateResponsesAfterLanguageChange(String previousLang, String newLa } } - private List getGradeBoundaries() { + private List getGradeBoundaries(String lang) { ArrayList gradeBoundaries = new ArrayList<>(); JSONArray gradeBoundariesJSON = propsSerializedGetJSONArray("grade_boundaries"); @@ -582,13 +582,11 @@ private List getGradeBoundaries() { if(gradeBoundariesJSON != null) { for (int i = 0; i < gradeBoundariesJSON.length(); i++) { JSONObject gradeBoundary = gradeBoundariesJSON.getJSONObject(i); - Iterator keys = gradeBoundary.keys(); - while (keys.hasNext()) { - String key = keys.next(); - int grade = Integer.parseInt(key); - String message = gradeBoundary.getString(key); - gradeBoundaries.add(new GradeBoundary(grade, message)); - } + String gradeStr = gradeBoundary.keys().next(); + int grade = Integer.parseInt(gradeStr); + String multilangMessage = gradeBoundary.getString(gradeStr); + String message = getGradeBoundaryMessageForLang(multilangMessage, lang); + gradeBoundaries.add(new GradeBoundary(grade, message)); } Collections.sort(gradeBoundaries, GradeBoundary.sorByGradeDescending); } @@ -599,10 +597,31 @@ private List getGradeBoundaries() { return gradeBoundaries; } + private String getGradeBoundaryMessageForLang(String multilangMessage, String lang) { + String defaultMessage = ""; + String[] messages = multilangMessage.trim().split("\r\n"); + + for (String message : messages) { + String[] messageSplit = message.split("="); // Split language code and message + if (messageSplit.length == 1) { + return messageSplit[0]; // If there is no language code, this is the message + } + String langCode = messageSplit[0]; + String messageText = messageSplit[1]; + if (langCode.equalsIgnoreCase(lang)){ + return messageText; + } else if (defaultMessage.isEmpty()) { + defaultMessage = messageText; // Set first message as default message in case + // language is not found + } + } + return defaultMessage; + } + // Get the feedback message associated to a grade. The learner must get a grade // that is greater or equal than the defined grade boundaries public String getFeedbackMessageBasedOnQuizGrade(float quizGrade) { - List gradeBoundaries = this.getGradeBoundaries(); + List gradeBoundaries = this.getGradeBoundaries(defaultLang); for(GradeBoundary gradeBoundary : gradeBoundaries) { if(quizGrade >= gradeBoundary.getGrade()){ return cleanFeedbackMessage(gradeBoundary.getMessage()); diff --git a/app/src/test/java/testFiles/features/quiz/FeedbackGradeBoundariesTest.java b/app/src/test/java/testFiles/features/quiz/FeedbackGradeBoundariesTest.java index ad4be20dd..188e6722d 100644 --- a/app/src/test/java/testFiles/features/quiz/FeedbackGradeBoundariesTest.java +++ b/app/src/test/java/testFiles/features/quiz/FeedbackGradeBoundariesTest.java @@ -14,9 +14,9 @@ public class FeedbackGradeBoundariesTest { private static final String FEEDBACK_JSON_FILE = "quizzes/feedback_grade_boundaries.json"; - private static final String FEEDBACK_MESSAGE_25 = "Quiz score is between 0% and 49%. MaxQuizScore: 8.0; UserScore: 2.0; QuizScore: 25.0%"; - private static final String FEEDBACK_MESSAGE_75 = "Quiz score is between 50% and 99%. MaxQuizScore: 8.0; UserScore: 6.0; QuizScore: 75.0%"; - private static final String FEEDBACK_MESSAGE_100 = "Quiz score is 100%. MaxQuizScore: 8.0; UserScore: 8.0; QuizScore: 100.0%"; + private static final String FEEDBACK_MESSAGE_25 = "Quiz score is between 20% and 49%. MaxQuizScore: 8; UserScore: 2; QuizScore: 25%"; + private static final String FEEDBACK_MESSAGE_75 = "Quiz score is between 50% and 99%. MaxQuizScore: 8; UserScore: 6; QuizScore: 75%"; + private static final String FEEDBACK_MESSAGE_100 = "Quiz score is 100%. MaxQuizScore: 8; UserScore: 8; QuizScore: 100%"; @Test public void testCorrectFeedbackMessageIsShown() throws Exception { diff --git a/app/src/test/resources/quizzes/feedback_grade_boundaries.json b/app/src/test/resources/quizzes/feedback_grade_boundaries.json index 52fc2f3a8..e6ab8a3ba 100644 --- a/app/src/test/resources/quizzes/feedback_grade_boundaries.json +++ b/app/src/test/resources/quizzes/feedback_grade_boundaries.json @@ -15,7 +15,7 @@ "availability":0, "showfeedback":2, "grade_boundaries": [ - {"0": "Quiz score is between 0% and 49%. MaxQuizScore: {{max_score}}; UserScore: {{user_score}}; QuizScore: {{score_percentage}}%"}, + {"20": "Quiz score is between 20% and 49%. MaxQuizScore: {{max_score}}; UserScore: {{user_score}}; QuizScore: {{score_percentage}}%"}, {"50": "Quiz score is between 50% and 99%. MaxQuizScore: {{max_score}}; UserScore: {{user_score}}; QuizScore: {{score_percentage}}%"}, {"100": "Quiz score is 100%. MaxQuizScore: {{max_score}}; UserScore: {{user_score}}; QuizScore: {{score_percentage}}%"} ]