Repository: oppia/oppia

Issue:
Wrong label for navigating the previous lessons for Revision of Fraction chapters
<!--
  - Thanks for taking the time to report a bug in the Oppia project.
  - Before filing a new issue, please do a quick search to check that it hasn't
  - already been filed on the [issue tracker](https://github.com/oppia/oppia/issues)._
  -->

**Describe the bug**
Wrong label for navigating the previous lessons for Revision of Fraction chapters. (Without logging in)

**To Reproduce**
Steps to reproduce the behavior:
 1. Go to 'https://www.oppiatestserver.org/'
 2. Click on 'Fun and Effective Learning start learning tab'.
 3. Scroll down to 'Click on Fraction Lessons.
 4. Now on the top bar click on the Revision button 
 5. Click on the first chapter: What is Fraction?
 6. Scroll down and click on the next skill button at the end of the page.
 7. After coming on the Chapter2 page now try to go back to the previous chapter1 of fractions.
 8. At the end of the page it shows 'Next skill' not the previous chapter but when you click on that button it navigates you to the previous chapter only.
 

**Observed behavior**
When you try to navigate on the previous chapter the button shows you 'Next skill' but it actually navigates you to the previous chapter only.

**Expected behavior**
Instead of 'Next skill'  it should be 'previous Chapter' or 'Previous Skill' icon for revision lesson of fractions.

**Screenshots**
![Screenshot (42)](https://user-images.githubusercontent.com/87786183/145950804-7c320001-b796-484e-b79a-3d60105a56e0.png)

**Desktop (please complete the following information; delete this section if the issue does not arise on desktop):**
 - OS: Windows
 - Browser: Google Chrome
 - Browser: Version 96.0.4664.45 (Official Build) (64-bit)
Wrong label for navigating the previous lessons for Revision of Fraction chapters
<!--
  - Thanks for taking the time to report a bug in the Oppia project.
  - Before filing a new issue, please do a quick search to check that it hasn't
  - already been filed on the [issue tracker](https://github.com/oppia/oppia/issues)._
  -->

**Describe the bug**
Wrong label for navigating the previous lessons for Revision of Fraction chapters. (Without logging in)

**To Reproduce**
Steps to reproduce the behavior:
 1. Go to 'https://www.oppiatestserver.org/'
 2. Click on 'Fun and Effective Learning start learning tab'.
 3. Scroll down to 'Click on Fraction Lessons.
 4. Now on the top bar click on the Revision button 
 5. Click on the first chapter: What is Fraction?
 6. Scroll down and click on the next skill button at the end of the page.
 7. After coming on the Chapter2 page now try to go back to the previous chapter1 of fractions.
 8. At the end of the page it shows 'Next skill' not the previous chapter but when you click on that button it navigates you to the previous chapter only.
 

**Observed behavior**
When you try to navigate on the previous chapter the button shows you 'Next skill' but it actually navigates you to the previous chapter only.

**Expected behavior**
Instead of 'Next skill'  it should be 'previous Chapter' or 'Previous Skill' icon for revision lesson of fractions.

**Screenshots**
![Screenshot (42)](https://user-images.githubusercontent.com/87786183/145950804-7c320001-b796-484e-b79a-3d60105a56e0.png)

**Desktop (please complete the following information; delete this section if the issue does not arise on desktop):**
 - OS: Windows
 - Browser: Google Chrome
 - Browser: Version 96.0.4664.45 (Official Build) (64-bit)


Discussion:

Resolving patch:
diff --git a/core/controllers/subtopic_viewer.py b/core/controllers/subtopic_viewer.py
--- a/core/controllers/subtopic_viewer.py
+++ b/core/controllers/subtopic_viewer.py
@@ -54,6 +54,7 @@ def get(self, topic_name, subtopic_id):
         subtopic_id = int(subtopic_id)
         topic = topic_fetchers.get_topic_by_name(topic_name)
         next_subtopic_dict = None
+        prev_subtopic_dict = None
         for index, subtopic in enumerate(topic.subtopics):
             if subtopic.id == subtopic_id:
                 subtopic_title = subtopic.title
@@ -63,7 +64,7 @@ def get(self, topic_name, subtopic_id):
                 # subtopic page of the topic would always link to itself at the
                 # bottom of the subtopic page which isn't expected.
                 elif len(topic.subtopics) > 1:
-                    next_subtopic_dict = topic.subtopics[0].to_dict()
+                    prev_subtopic_dict = topic.subtopics[index - 1].to_dict()
                 break
         subtopic_page_contents = (
             subtopic_page_services.get_subtopic_page_contents_by_id(
@@ -75,6 +76,7 @@ def get(self, topic_name, subtopic_id):
             'topic_name': topic.name,
             'page_contents': subtopic_page_contents_dict,
             'subtopic_title': subtopic_title,
-            'next_subtopic_dict': next_subtopic_dict
+            'next_subtopic_dict': next_subtopic_dict,
+            'prev_subtopic_dict': prev_subtopic_dict,
         })
         self.render_json(self.values)


Test patch:
diff --git a/core/controllers/subtopic_viewer_test.py b/core/controllers/subtopic_viewer_test.py
--- a/core/controllers/subtopic_viewer_test.py
+++ b/core/controllers/subtopic_viewer_test.py
@@ -194,7 +194,8 @@ def test_get_for_first_subtopic_in_topic(self):
             'topic_id': 'topic_id',
             'page_contents': expected_page_contents_dict,
             'subtopic_title': 'Subtopic Title',
-            'next_subtopic_dict': expected_next_subtopic_dict
+            'next_subtopic_dict': expected_next_subtopic_dict,
+            'prev_subtopic_dict': None
         }
         self.assertDictContainsSubset(expected_dict, json_response)
 
@@ -210,7 +211,7 @@ def test_get_for_last_subtopic_in_topic(self):
             },
             'written_translations': self.written_translations_dict
         }
-        expected_next_subtopic_dict = {
+        expected_prev_subtopic_dict = {
             'thumbnail_bg_color': None,
             'skill_ids': ['skill_id_1'],
             'id': 1,
@@ -224,7 +225,8 @@ def test_get_for_last_subtopic_in_topic(self):
             'topic_id': 'topic_id',
             'page_contents': expected_page_contents_dict,
             'subtopic_title': 'Subtopic Title 2',
-            'next_subtopic_dict': expected_next_subtopic_dict
+            'next_subtopic_dict': None,
+            'prev_subtopic_dict': expected_prev_subtopic_dict
         }
         self.assertDictContainsSubset(expected_dict, json_response)