html_component_editor.py 1.95 KB
Newer Older
1
from component_editor import ComponentEditorView
2
from common.test.acceptance.pages.studio.utils import type_in_codemirror
3 4 5 6 7 8


class HtmlComponentEditorView(ComponentEditorView):
    """
    Represents the rendered view of an HTML component editor.
    """
9 10 11 12 13 14 15 16 17

    editor_mode_css = '.edit-xblock-modal .editor-modes .editor-button'

    def set_content_and_save(self, content, raw=False):
        """Types content into the html component and presses Save.

        Arguments:
            content (str): The content to be used.
            raw (bool): If true, edits in 'raw HTML' mode.
18
        """
19 20 21 22 23
        if raw:
            self.set_raw_content(content)
        else:
            self.set_content(content)

24 25
        self.save()

26 27 28 29 30 31
    def set_content_and_cancel(self, content, raw=False):
        """Types content into the html component and presses Cancel to abort.

        Arguments:
            content (str): The content to be used.
            raw (bool): If true, edits in 'raw HTML' mode.
32
        """
33 34 35 36 37
        if raw:
            self.set_raw_content(content)
        else:
            self.set_content(content)

38 39 40
        self.cancel()

    def set_content(self, content):
41
        """Sets content in the html component, leaving the component open.
42 43 44

        Arguments:
            content (str): The content to be used.
45
        """
46
        self.q(css=self.editor_mode_css).click()
47
        self.browser.execute_script("tinyMCE.activeEditor.setContent('%s')" % content)
48 49 50 51 52 53 54 55

    def set_raw_content(self, content):
        """Types content in raw html mode, leaving the component open.
        Arguments:
            content (str): The content to be used.
        """
        self.q(css=self.editor_mode_css).click()
        self.q(css='[aria-label="Edit HTML"]').click()
56
        self.wait_for_element_visibility('.mce-title', 'Wait for CodeMirror editor')
57 58
        # Set content in the CodeMirror editor.
        type_in_codemirror(self, 0, content)
59 60

        self.q(css='.mce-foot .mce-primary').click()