Commit 9af13c34 by Tim Krones

Merge pull request #59 from open-craft/fix-invalid-links-in-tables

Fix: Translate links in table column headers
parents d500a621 07586e6d
...@@ -113,7 +113,11 @@ class MentoringTableBlock( ...@@ -113,7 +113,11 @@ class MentoringTableBlock(
for child_id in self.children: for child_id in self.children:
child = self.runtime.get_block(child_id) child = self.runtime.get_block(child_id)
# Child should be an instance of MentoringTableColumn # Child should be an instance of MentoringTableColumn
header_values.append(child.header) header = child.header
# Make sure /jump_to_id/ URLs are expanded correctly
if getattr(self.runtime, 'replace_jump_to_id_urls', None):
header = self.runtime.replace_jump_to_id_urls(header)
header_values.append(header)
child_frag = child.render('mentoring_view', context) child_frag = child.render('mentoring_view', context)
content_values.append(child_frag.content) content_values.append(child_frag.content)
context['header_values'] = header_values if any(header_values) else None context['header_values'] = header_values if any(header_values) else None
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
# Imports ########################################################### # Imports ###########################################################
from mock import patch
from workbench.runtime import WorkbenchRuntime
from .base_test import MentoringBaseTest from .base_test import MentoringBaseTest
...@@ -54,3 +56,16 @@ class MentoringTableBlockTest(MentoringBaseTest): ...@@ -54,3 +56,16 @@ class MentoringTableBlockTest(MentoringBaseTest):
self.assertEqual(len(rows), 2) self.assertEqual(len(rows), 2)
self.assertEqual(rows[0].text, 'This is the answer #1') self.assertEqual(rows[0].text, 'This is the answer #1')
self.assertEqual(rows[1].text, 'This is the answer #2') self.assertEqual(rows[1].text, 'This is the answer #2')
# Ensure that table block makes an effort to translate URLs in column headers
link_template = "<a href='http://www.test.com'>{}</a> in a column header."
original_contents = link_template.format('Link')
updated_contents = link_template.format('Updated link')
with patch.object(WorkbenchRuntime, 'replace_jump_to_id_urls', create=True) as patched_method:
patched_method.return_value = updated_contents
table = self.go_to_page('Table 3', css_selector='.mentoring-table')
patched_method.assert_called_once_with(original_contents)
link = table.find_element_by_css_selector('a')
self.assertEquals(link.text, 'Updated link')
<vertical_demo>
<problem-builder display_submit="false" enforce_dependency="false">
<pb-table>
<pb-column header="&lt;a href='http://www.test.com'&gt;Link&lt;/a&gt; in a column header.">
<pb-answer-recap name="table_3_answer_1"/>
</pb-column>
</pb-table>
</problem-builder>
</vertical_demo>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment