Repository: biolab/orange3-text

Issue:
Corpus Viewer: highlight doesn't work anymore
<!--
This is an issue template. Please fill in the relevant details in the
sections below.
-->

##### Text version
<!-- From menu _Options→Add-ons→Orange3-Text_ or code `orangecontrib.text.version.full_version` -->
0.4.0.

##### Orange version
<!-- From menu _Help→About→Version_ or code `Orange.version.full_version` -->
3.16.dev

##### Expected behavior
Words are highlighted upon search.


##### Actual behavior
Search does not highlight words.


##### Steps to reproduce the behavior
Corpus - Corpus Viewer (search for any word that is in the text).


##### Additional info (worksheets, data, screenshots, ...)





Discussion:

Resolving patch:
diff --git a/orangecontrib/text/widgets/owcorpusviewer.py b/orangecontrib/text/widgets/owcorpusviewer.py
--- a/orangecontrib/text/widgets/owcorpusviewer.py
+++ b/orangecontrib/text/widgets/owcorpusviewer.py
@@ -322,13 +322,13 @@ def show_docs(self):
             row_ind = index.data(Qt.UserRole).row_index
             for ind in self.display_indices:
                 feature = self.display_features[ind]
-                mark = 'class="mark-area"' if feature in marked_search_features else ''
+                mark = ' mark-area' if feature in marked_search_features else ''
                 value = str(index.data(Qt.UserRole)[feature.name]).replace('\n', '<br/>')
                 is_image = feature.attributes.get('type', '') == 'image'
                 if is_image and value != '?':
                     value = '<img src="{}"></img>'.format(value)
                 html += '<tr><td class="variables"><strong>{}:</strong></td>' \
-                        '<td class="content" {}>{}</td></tr>'.format(
+                        '<td class="content{}">{}</td></tr>'.format(
                     feature.name, mark, value)
 
             if self.show_tokens:


Test patch:
diff --git a/orangecontrib/text/widgets/tests/test_owcorpusviewer.py b/orangecontrib/text/widgets/tests/test_owcorpusviewer.py
new file mode 100644
--- /dev/null
+++ b/orangecontrib/text/widgets/tests/test_owcorpusviewer.py
@@ -0,0 +1,39 @@
+import unittest
+from AnyQt.QtTest import QSignalSpy
+from Orange.widgets.tests.base import WidgetTest
+
+from orangecontrib.text.corpus import Corpus
+from orangecontrib.text.widgets.owcorpusviewer import OWCorpusViewer
+
+
+class TestCorpusViewerWidget(WidgetTest):
+    def setUp(self):
+        self.widget = self.create_widget(OWCorpusViewer)
+        self.corpus = Corpus.from_file('deerwester')
+
+    def test_data(self):
+        self.send_signal(self.widget.Inputs.corpus, self.corpus)
+        self.assertEqual(self.widget.n_documents, 9)
+        out_corpus = self.get_output(self.widget.Outputs.matching_docs)
+        self.assertEqual(out_corpus, self.corpus)
+
+    def test_search(self):
+        self.send_signal(self.widget.Inputs.corpus, self.corpus)
+        self.widget.regexp_filter = "graph"
+        self.process_events()
+        out_corpus = self.get_output(self.widget.Outputs.matching_docs)
+        self.assertEqual(len(out_corpus), 4)
+
+    def test_highlighting(self):
+        self.send_signal(self.widget.Inputs.corpus, self.corpus)
+        self.widget.regexp_filter = "graph"
+        self.process_events()
+        self.widget.doc_webview.html()
+        spy = QSignalSpy(self.widget.doc_webview.loadFinished)
+        spy.wait()
+        html = self.widget.doc_webview.html()
+        self.assertIn('<mark data-markjs="true">', html)
+
+
+if __name__ == "__main__":
+    unittest.main()