course_wiki.py 3.58 KB
Newer Older
1 2 3 4
"""
Wiki tab on courses
"""

5 6
from common.test.acceptance.pages.lms.course_page import CoursePage
from common.test.acceptance.pages.studio.utils import type_in_codemirror
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23


class CourseWikiPage(CoursePage):
    """
    Course wiki navigation and objects.
    """

    url_path = "wiki"

    def is_browser_on_page(self):
        """
        Browser is on the wiki page if the wiki breadcrumb is present
        """
        return self.q(css='.breadcrumb').present

    def open_editor(self):
        """
24
        Display the editor for a wiki article.
25 26 27 28
        """
        edit_button = self.q(css='.fa-pencil')
        edit_button.click()

29 30 31 32 33 34 35 36 37 38 39 40 41 42
    def show_history(self):
        """
        Show the change history for a wiki article.
        """
        edit_button = self.q(css='.fa-clock-o')
        edit_button.click()

    def show_children(self):
        """
        Show the children of a wiki article.
        """
        children_link = self.q(css='.see-children>a')
        children_link.click()

43 44 45 46 47
    @property
    def article_name(self):
        """
        Return the name of the article
        """
48
        return str(self.q(css='.main-article .entry-title').text[0])
49 50


51 52
class CourseWikiSubviewPage(CoursePage):  # pylint: disable=abstract-method
    """ Abstract base page for subviews within the wiki. """
53 54 55 56 57 58

    def __init__(self, browser, course_id, course_info):
        """
        Course ID is currently of the form "edx/999/2013_Spring"
        but this format could change.
        """
59
        super(CourseWikiSubviewPage, self).__init__(browser, course_id)
60 61 62 63 64 65 66 67
        self.course_id = course_id
        self.course_info = course_info
        self.article_name = "{org}.{course_number}.{course_run}".format(
            org=self.course_info['org'],
            course_number=self.course_info['number'],
            course_run=self.course_info['run']
        )

68 69 70 71 72 73

class CourseWikiEditPage(CourseWikiSubviewPage):
    """
    Editor page
    """

74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
    @property
    def url_path(self):
        """
        Construct a URL to the page within the course.
        """
        return "/wiki/" + self.article_name + "/_edit"

    def is_browser_on_page(self):
        """
        The wiki page editor
        """
        return self.q(css='.CodeMirror-scroll').present

    def replace_wiki_content(self, content):
        """
        Editor must be open already. This will replace any content in the editor
        with new content
        """
        type_in_codemirror(self, 0, content)

    def save_wiki_content(self):
        """
        When the editor is open, click save
        """
        self.q(css='button[name="save"]').click()
        self.wait_for_element_presence('.alert-success', 'wait for the article to be saved')
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137


class CourseWikiHistoryPage(CourseWikiSubviewPage):
    """
    Course wiki change history page.
    """

    def is_browser_on_page(self):
        """
        Return if the browser is on the history page.
        """
        return self.q(css='section.history').present

    @property
    def url_path(self):
        """
        Construct a URL to the page within the course.
        """
        return "/wiki/" + self.article_name + "/_history"


class CourseWikiChildrenPage(CourseWikiSubviewPage):
    """
    Course wiki "All Children" page.
    """

    def is_browser_on_page(self):
        """
        Return if the browser is on the wiki children page (which contains a search widget).
        """
        return self.q(css='.form-search').present

    @property
    def url_path(self):
        """
        Construct a URL to the page within the course.
        """
        return "/wiki/" + self.article_name + "/_dir"