From af7599ff19d1e5c7362f1621bcf90943d32e22d0 Mon Sep 17 00:00:00 2001 From: Josue Balandrano Coronel Date: Sun, 17 Mar 2019 10:56:35 -0500 Subject: [PATCH 1/9] Add visitied hostspots styling. --- image_explorer/image_explorer.py | 2 ++ image_explorer/public/css/image_explorer.css | 2 +- image_explorer/templates/html/image_explorer.html | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/image_explorer/image_explorer.py b/image_explorer/image_explorer.py index 77822d0..4ecb728 100644 --- a/image_explorer/image_explorer.py +++ b/image_explorer/image_explorer.py @@ -373,6 +373,8 @@ def _get_hotspots(self, xmltree, absolute_urls=False): if not hotspot.y.endswith('%'): hotspot.y += 'px' # px is deprecated as it is not responsive + hotspot.visited = True + hotspots.append(hotspot) return hotspots diff --git a/image_explorer/public/css/image_explorer.css b/image_explorer/public/css/image_explorer.css index 5a8d65d..af82312 100644 --- a/image_explorer/public/css/image_explorer.css +++ b/image_explorer/public/css/image_explorer.css @@ -64,7 +64,7 @@ div.image-explorer-hotspot a{ text-decoration: underline; } -.image-explorer-wrapper div.image-explorer-hotspot:hover { +.image-explorer-wrapper div.image-explorer-hotspot:hover, .image-explorer-wrapper.visited { background-position: 0 -43px } diff --git a/image_explorer/templates/html/image_explorer.html b/image_explorer/templates/html/image_explorer.html index e7091a4..83c4bf1 100644 --- a/image_explorer/templates/html/image_explorer.html +++ b/image_explorer/templates/html/image_explorer.html @@ -9,7 +9,9 @@

{{title}}

{% for hotspot in hotspots %} -
+
From e9b0d24ba1301991ea6ba16e1d20b34bcb994e73 Mon Sep 17 00:00:00 2001 From: Josue Balandrano Coronel Date: Sun, 17 Mar 2019 22:50:22 -0500 Subject: [PATCH 2/9] Add test to check on verified feature. --- tests/unit/test_image_explorer.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/unit/test_image_explorer.py b/tests/unit/test_image_explorer.py index b9b55b7..d7983d5 100644 --- a/tests/unit/test_image_explorer.py +++ b/tests/unit/test_image_explorer.py @@ -1,4 +1,5 @@ import unittest +from unittest.mock import patch from lxml import etree from parsel import Selector @@ -129,3 +130,18 @@ def test_hotspot_coordinates_property(self): # for schema version 2 hotspot coordinates are centered self.assertTrue(image_explorer_block_schema2.hotspot_coordinates_centered) + + @patch('image_explorer.image_explorer.ImageExplorerBlock._inner_content') + def test__get_hotspots(self, mock__inner_content): + """ + Test _get_hotspots return all hotspots. + """ + image_explorer_data = {'data': self.image_explorer_xml_version2} + image_explorer_block_schema2 = ImageExplorerBlock( + self.runtime, + DictFieldData(image_explorer_data), + None + ) + hotspots = image_explorer_data._get_hotspots(xmltree=etree.fromstring(self.image_explorer_xml)) + self.assertEqual(len(hotspots), 1) + self.assertTrue(hotspots[0].visited) From 0495f1640d887be28bdfeaa6c6c3d6414012fb0c Mon Sep 17 00:00:00 2001 From: Josue Balandrano Coronel Date: Mon, 18 Mar 2019 11:00:27 -0500 Subject: [PATCH 3/9] Fix unit test. --- tests/unit/test_image_explorer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_image_explorer.py b/tests/unit/test_image_explorer.py index d7983d5..69fe5e8 100644 --- a/tests/unit/test_image_explorer.py +++ b/tests/unit/test_image_explorer.py @@ -1,5 +1,5 @@ import unittest -from unittest.mock import patch +from mock import patch from lxml import etree from parsel import Selector @@ -142,6 +142,6 @@ def test__get_hotspots(self, mock__inner_content): DictFieldData(image_explorer_data), None ) - hotspots = image_explorer_data._get_hotspots(xmltree=etree.fromstring(self.image_explorer_xml)) + hotspots = image_explorer_block_schema2._get_hotspots(xmltree=etree.fromstring(self.image_explorer_xml)) self.assertEqual(len(hotspots), 1) self.assertTrue(hotspots[0].visited) From 6e6191469eee7ccb5456d1490e69162957060707 Mon Sep 17 00:00:00 2001 From: Josue Balandrano Coronel Date: Mon, 18 Mar 2019 12:02:01 -0500 Subject: [PATCH 4/9] Fix test and html typo. --- image_explorer/image_explorer.py | 4 +++- image_explorer/public/css/image_explorer.css | 3 ++- image_explorer/templates/html/image_explorer.html | 2 +- tests/unit/test_image_explorer.py | 4 ++++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/image_explorer/image_explorer.py b/image_explorer/image_explorer.py index 4ecb728..2410724 100644 --- a/image_explorer/image_explorer.py +++ b/image_explorer/image_explorer.py @@ -373,7 +373,9 @@ def _get_hotspots(self, xmltree, absolute_urls=False): if not hotspot.y.endswith('%'): hotspot.y += 'px' # px is deprecated as it is not responsive - hotspot.visited = True + hotspot.visited = False + if hotspot.item_id in self.opened_hotspots: + hotspot.visited = True hotspots.append(hotspot) diff --git a/image_explorer/public/css/image_explorer.css b/image_explorer/public/css/image_explorer.css index af82312..2189143 100644 --- a/image_explorer/public/css/image_explorer.css +++ b/image_explorer/public/css/image_explorer.css @@ -64,7 +64,8 @@ div.image-explorer-hotspot a{ text-decoration: underline; } -.image-explorer-wrapper div.image-explorer-hotspot:hover, .image-explorer-wrapper.visited { +.image-explorer-wrapper div.image-explorer-hotspot:hover, +.image-explorer-wrapper div.image-explorer-hotspot.visited { background-position: 0 -43px } diff --git a/image_explorer/templates/html/image_explorer.html b/image_explorer/templates/html/image_explorer.html index 83c4bf1..6b0c8e3 100644 --- a/image_explorer/templates/html/image_explorer.html +++ b/image_explorer/templates/html/image_explorer.html @@ -9,7 +9,7 @@

{{title}}

{% for hotspot in hotspots %} -
diff --git a/tests/unit/test_image_explorer.py b/tests/unit/test_image_explorer.py index 69fe5e8..30d2959 100644 --- a/tests/unit/test_image_explorer.py +++ b/tests/unit/test_image_explorer.py @@ -144,4 +144,8 @@ def test__get_hotspots(self, mock__inner_content): ) hotspots = image_explorer_block_schema2._get_hotspots(xmltree=etree.fromstring(self.image_explorer_xml)) self.assertEqual(len(hotspots), 1) + self.assertFalse(hotspots[0].visited) + image_explorer_block_schema2.opened_hotspots.append('hotspotA') + hotspots = image_explorer_block_schema2._get_hotspots(xmltree=etree.fromstring(self.image_explorer_xml)) + self.assertEqual(len(hotspots), 1) self.assertTrue(hotspots[0].visited) From cbd20739e1cbfd3fe0d465bbaf84c2f0941d5971 Mon Sep 17 00:00:00 2001 From: Josue Balandrano Coronel Date: Mon, 18 Mar 2019 14:02:53 -0500 Subject: [PATCH 5/9] Add selenium test. --- tests/integration/test_image_explorer.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/integration/test_image_explorer.py b/tests/integration/test_image_explorer.py index 2acbf7d..71c8cd9 100644 --- a/tests/integration/test_image_explorer.py +++ b/tests/integration/test_image_explorer.py @@ -47,6 +47,8 @@ def assert_only_hotspotA_revealed(self, block): self.assertIn("Below are some of the highlights:", block.hotspotA.content.text) self.assertIn("Once there was a police car up here", block.hotspotA.content.text) self.assertIn("Also there was a Fire Truck put up there", block.hotspotA.content.text) + self.assertIn('visited', block.hotspotA.get_attribute("class")) + self.assertNotIn('visited', block.hotspotB.get_attribute("class")) def assert_only_hotspotB_revealed(self, block): hs = self.hotspots(block) @@ -57,6 +59,8 @@ def assert_only_hotspotB_revealed(self, block): self.assertIn("Watch the Red Line subway go around the dome", block.hotspotB.content.text) self.assertTrue(block.hotspotB.find_element_by_css_selector(".image-explorer-hotspot-reveal-youtube")) + self.assertNotIn('visited', block.hotspotA.get_attribute("class")) + self.assertIn('visited', block.hotspotB.get_attribute("class")) def test_simple_scenario(self): self.set_scenario_xml('') @@ -65,6 +69,8 @@ def test_simple_scenario(self): self.assert_in_default_state(block) + self.assertNotIn('visited', block.hotspotA.get_attribute("class")) + self.assertNotIn('visited' in block.hotspotB.get_attribute("class")) block.hotspotA.click() self.assert_only_hotspotA_revealed(block) From ddfab46b2cf4cffc89182617412814e4723b0a84 Mon Sep 17 00:00:00 2001 From: Josue Balandrano Coronel Date: Mon, 18 Mar 2019 17:10:22 -0500 Subject: [PATCH 6/9] Update integration test. --- tests/integration/test_image_explorer.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/integration/test_image_explorer.py b/tests/integration/test_image_explorer.py index 71c8cd9..5117a30 100644 --- a/tests/integration/test_image_explorer.py +++ b/tests/integration/test_image_explorer.py @@ -48,7 +48,6 @@ def assert_only_hotspotA_revealed(self, block): self.assertIn("Once there was a police car up here", block.hotspotA.content.text) self.assertIn("Also there was a Fire Truck put up there", block.hotspotA.content.text) self.assertIn('visited', block.hotspotA.get_attribute("class")) - self.assertNotIn('visited', block.hotspotB.get_attribute("class")) def assert_only_hotspotB_revealed(self, block): hs = self.hotspots(block) @@ -59,7 +58,6 @@ def assert_only_hotspotB_revealed(self, block): self.assertIn("Watch the Red Line subway go around the dome", block.hotspotB.content.text) self.assertTrue(block.hotspotB.find_element_by_css_selector(".image-explorer-hotspot-reveal-youtube")) - self.assertNotIn('visited', block.hotspotA.get_attribute("class")) self.assertIn('visited', block.hotspotB.get_attribute("class")) def test_simple_scenario(self): @@ -70,7 +68,7 @@ def test_simple_scenario(self): self.assert_in_default_state(block) self.assertNotIn('visited', block.hotspotA.get_attribute("class")) - self.assertNotIn('visited' in block.hotspotB.get_attribute("class")) + self.assertNotIn('visited', block.hotspotB.get_attribute("class")) block.hotspotA.click() self.assert_only_hotspotA_revealed(block) From 6ae5dba5a74f7bf112d8b62eed31241cb5023401 Mon Sep 17 00:00:00 2001 From: Josue Balandrano Coronel Date: Mon, 18 Mar 2019 17:11:42 -0500 Subject: [PATCH 7/9] Compact statement. --- image_explorer/image_explorer.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/image_explorer/image_explorer.py b/image_explorer/image_explorer.py index 2410724..76ff8f6 100644 --- a/image_explorer/image_explorer.py +++ b/image_explorer/image_explorer.py @@ -373,9 +373,7 @@ def _get_hotspots(self, xmltree, absolute_urls=False): if not hotspot.y.endswith('%'): hotspot.y += 'px' # px is deprecated as it is not responsive - hotspot.visited = False - if hotspot.item_id in self.opened_hotspots: - hotspot.visited = True + hotspot.visited = hotspot.item_id in self.opened_hotspots: hotspots.append(hotspot) From 411764a2740ff4a8ccbb3cf986d5e064065e7855 Mon Sep 17 00:00:00 2001 From: Josue Balandrano Coronel Date: Tue, 19 Mar 2019 15:15:50 -0500 Subject: [PATCH 8/9] Fix typo. --- image_explorer/image_explorer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/image_explorer/image_explorer.py b/image_explorer/image_explorer.py index 76ff8f6..7337811 100644 --- a/image_explorer/image_explorer.py +++ b/image_explorer/image_explorer.py @@ -373,7 +373,7 @@ def _get_hotspots(self, xmltree, absolute_urls=False): if not hotspot.y.endswith('%'): hotspot.y += 'px' # px is deprecated as it is not responsive - hotspot.visited = hotspot.item_id in self.opened_hotspots: + hotspot.visited = hotspot.item_id in self.opened_hotspots hotspots.append(hotspot) From 2dd9d4dac92406024f0920de2fc46e28a631ac15 Mon Sep 17 00:00:00 2001 From: Josue Balandrano Coronel Date: Tue, 19 Mar 2019 16:32:55 -0500 Subject: [PATCH 9/9] Version upgraded to 1.1.3 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 1877de5..ff18418 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ def package_data(pkg, root_list): setup( name='xblock-image-explorer', - version='1.1.2', + version='1.1.3', description='XBlock - Image Explorer', packages=['image_explorer'], install_requires=[