pages.py 4.91 KB
Newer Older
1
# pylint: disable=missing-docstring
2
# pylint: disable=redefined-outer-name
3
# pylint: disable=unused-argument
4

5
from lettuce import step, world
6
from nose.tools import assert_equal, assert_in
7

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


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


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


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

31

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

37

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


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


55 56 57
@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
58 59


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


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


72
@step(u'I have created two different static pages$')
cahrens committed
73 74 75 76
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"')
77
    step.given('I add a new static page')
78 79
    # Verify order of pages
    _verify_page_names('First', 'Empty')
cahrens committed
80 81


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


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


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


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


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


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


122 123 124
@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')
125 126 127 128 129


@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"
130
    assert_equal(world.css_find(CSS_FOR_TAB_ELEMENT.format(page_id)).checked, hidden)
131 132


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


138
def drag_first_to_last_with_css(css_class):
139 140 141 142 143 144 145 146 147 148 149 150 151 152
    # 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)