pages.py 4.96 KB
Newer Older
1 2
# pylint: disable=C0111
# pylint: disable=W0621
3
# pylint: disable=W0613
4 5

from lettuce import world, step
6
from nose.tools import assert_equal, assert_in  # pylint: disable=E0611
7 8


9 10 11
CSS_FOR_TAB_ELEMENT = "li[data-tab-id='{0}'] input.toggle-checkbox"


12
@step(u'I go to the pages page$')
13
def go_to_static(step):
14
    menu_css = 'li.nav-course-courseware'
15
    static_css = 'li.nav-course-courseware-pages a'
16 17
    world.css_click(menu_css)
    world.css_click(static_css)
18 19


20
@step(u'I add a new static page$')
21
def add_page(step):
22
    button_css = 'a.new-button'
23
    world.css_click(button_css)
24 25


26 27
@step(u'I should see a static page named "([^"]*)"$')
def see_a_static_page_named_foo(step, name):
28
    pages_css = 'div.xmodule_StaticTabModule'
29 30
    page_name_html = world.css_html(pages_css)
    assert_equal(page_name_html, '\n    {name}\n'.format(name=name))
31

32

33 34
@step(u'I should not see any static pages$')
def not_see_any_static_pages(step):
35
    pages_css = 'div.xmodule_StaticTabModule'
36
    assert (world.is_css_not_present(pages_css, wait_time=30))
37

38

39 40
@step(u'I "(edit|delete)" the static page$')
def click_edit_or_delete(step, edit_or_delete):
41
    button_css = 'ul.component-actions a.%s-button' % edit_or_delete
42
    world.css_click(button_css)
43 44 45


@step(u'I change the name to "([^"]*)"$')
46
def change_name(step, new_name):
47
    settings_css = '.settings-button'
48
    world.css_click(settings_css)
49
    input_css = 'input.setting-input'
50 51 52
    world.css_fill(input_css, new_name)
    if world.is_firefox():
        world.trigger_event(input_css)
53
    world.save_component()
cahrens committed
54 55


56 57 58
@step(u'I drag the first static page to the last$')
def drag_first_static_page_to_last(step):
    drag_first_to_last_with_css('.component')
cahrens committed
59 60


61
@step(u'I have created a static page$')
cahrens committed
62
def create_static_page(step):
63 64 65 66
    step.given('I have opened the pages page in a new course')
    step.given('I add a new static page')


67
@step(u'I have opened the pages page in a new course$')
68
def open_pages_page_in_new_course(step):
cahrens committed
69
    step.given('I have opened a new course in Studio')
70
    step.given('I go to the pages page')
cahrens committed
71 72


73
@step(u'I have created two different static pages$')
cahrens committed
74 75 76 77
def create_two_pages(step):
    step.given('I have created a static page')
    step.given('I "edit" the static page')
    step.given('I change the name to "First"')
78
    step.given('I add a new static page')
79 80
    # Verify order of pages
    _verify_page_names('First', 'Empty')
cahrens committed
81 82


83 84
@step(u'the static pages are switched$')
def static_pages_are_switched(step):
85
    _verify_page_names('Empty', 'First')
cahrens committed
86 87


88
def _verify_page_names(first, second):
cahrens committed
89 90 91
    world.wait_for(
        func=lambda _: len(world.css_find('.xmodule_StaticTabModule')) == 2,
        timeout=200,
92
        timeout_msg="Timed out waiting for two pages to be present"
cahrens committed
93
    )
94
    pages = world.css_find('.xmodule_StaticTabModule')
95 96
    assert_equal(pages[0].text, first)
    assert_equal(pages[1].text, second)
97 98


99
@step(u'the built-in pages are in the default order$')
100
def built_in_pages_in_default_order(step):
101
    expected_pages = ['Courseware', 'Course Info', 'Wiki', 'Progress']
102 103 104
    see_pages_in_expected_order(expected_pages)


105 106
@step(u'the built-in pages are switched$')
def built_in_pages_switched(step):
107
    expected_pages = ['Courseware', 'Course Info', 'Progress', 'Wiki']
108 109 110
    see_pages_in_expected_order(expected_pages)


111
@step(u'the pages are in the default order$')
112
def pages_in_default_order(step):
113
    expected_pages = ['Courseware', 'Course Info', 'Wiki', 'Progress', 'First', 'Empty']
114 115 116
    see_pages_in_expected_order(expected_pages)


117 118
@step(u'the pages are switched$$')
def pages_are_switched(step):
119
    expected_pages = ['Courseware', 'Course Info', 'Progress', 'First', 'Empty', 'Wiki']
120 121 122
    see_pages_in_expected_order(expected_pages)


123 124 125
@step(u'I drag the first page to the last$')
def drag_first_page_to_last(step):
    drag_first_to_last_with_css('.is-movable')
126 127 128 129 130


@step(u'I should see the "([^"]*)" page as "(visible|hidden)"$')
def page_is_visible_or_hidden(step, page_id, visible_or_hidden):
    hidden = visible_or_hidden == "hidden"
131
    assert_equal(world.css_find(CSS_FOR_TAB_ELEMENT.format(page_id)).checked, hidden)
132 133


134
@step(u'I toggle the visibility of the "([^"]*)" page$')
135
def page_toggle_visibility(step, page_id):
136
    world.css_find(CSS_FOR_TAB_ELEMENT.format(page_id))[0].click()
137 138


139
def drag_first_to_last_with_css(css_class):
140 141 142 143 144 145 146 147 148 149 150 151 152 153
    # For some reason, the drag_and_drop method did not work in this case.
    draggables = world.css_find(css_class + ' .drag-handle')
    source = draggables.first
    target = draggables.last
    source.action_chains.click_and_hold(source._element).perform()  # pylint: disable=protected-access
    source.action_chains.move_to_element_with_offset(target._element, 0, 50).perform()  # pylint: disable=protected-access
    source.action_chains.release().perform()


def see_pages_in_expected_order(page_names_in_expected_order):
    pages = world.css_find("li.course-tab")
    assert_equal(len(page_names_in_expected_order), len(pages))
    for i, page_name in enumerate(page_names_in_expected_order):
        assert_in(page_name, pages[i].text)