studio-overview-togglesection.py 3.96 KB
Newer Older
1 2 3
#pylint: disable=C0111
#pylint: disable=W0621

4 5 6 7 8 9 10
from lettuce import world, step
from common import *
from nose.tools import assert_true, assert_false, assert_equal

from logging import getLogger
logger = getLogger(__name__)

Calen Pennington committed
11

12 13
@step(u'I have a course with no sections$')
def have_a_course(step):
14
    world.clear_courses()
15
    course = world.CourseFactory.create()
16

Calen Pennington committed
17

18 19
@step(u'I have a course with 1 section$')
def have_a_course_with_1_section(step):
20
    world.clear_courses()
21 22 23
    course = world.CourseFactory.create()
    section = world.ItemFactory.create(parent_location=course.location)
    subsection1 = world.ItemFactory.create(
24
        parent_location=section.location,
Calen Pennington committed
25 26 27
        template='i4x://edx/templates/sequential/Empty',
        display_name='Subsection One',)

28 29 30

@step(u'I have a course with multiple sections$')
def have_a_course_with_two_sections(step):
31
    world.clear_courses()
32 33 34
    course = world.CourseFactory.create()
    section = world.ItemFactory.create(parent_location=course.location)
    subsection1 = world.ItemFactory.create(
35
        parent_location=section.location,
Calen Pennington committed
36 37
        template='i4x://edx/templates/sequential/Empty',
        display_name='Subsection One',)
38
    section2 = world.ItemFactory.create(
39 40
        parent_location=course.location,
        display_name='Section Two',)
41
    subsection2 = world.ItemFactory.create(
42
        parent_location=section2.location,
Calen Pennington committed
43 44
        template='i4x://edx/templates/sequential/Empty',
        display_name='Subsection Alpha',)
45
    subsection3 = world.ItemFactory.create(
46
        parent_location=section2.location,
Calen Pennington committed
47 48 49
        template='i4x://edx/templates/sequential/Empty',
        display_name='Subsection Beta',)

50 51 52 53 54

@step(u'I navigate to the course overview page$')
def navigate_to_the_course_overview_page(step):
    log_into_studio(is_staff=True)
    course_locator = '.class-name'
55
    world.css_click(course_locator)
56

Calen Pennington committed
57

58 59 60 61 62
@step(u'I navigate to the courseware page of a course with multiple sections')
def nav_to_the_courseware_page_of_a_course_with_multiple_sections(step):
    step.given('I have a course with multiple sections')
    step.given('I navigate to the course overview page')

Calen Pennington committed
63

64 65 66 67
@step(u'I add a section')
def i_add_a_section(step):
    add_section(name='My New Section That I Just Added')

Calen Pennington committed
68

69 70 71
@step(u'I click the "([^"]*)" link$')
def i_click_the_text_span(step, text):
    span_locator = '.toggle-button-sections span'
72
    assert_true(world.browser.is_element_present_by_css(span_locator))
73 74
    # first make sure that the expand/collapse text is the one you expected
    assert_equal(world.browser.find_by_css(span_locator).value, text)
75
    world.css_click(span_locator)
76

Calen Pennington committed
77

78 79 80
@step(u'I collapse the first section$')
def i_collapse_a_section(step):
    collapse_locator = 'section.courseware-section a.collapse'
81
    world.css_click(collapse_locator)
82

Calen Pennington committed
83

84 85 86
@step(u'I expand the first section$')
def i_expand_a_section(step):
    expand_locator = 'section.courseware-section a.expand'
87
    world.css_click(expand_locator)
88

Calen Pennington committed
89

90 91 92
@step(u'I see the "([^"]*)" link$')
def i_see_the_span_with_text(step, text):
    span_locator = '.toggle-button-sections span'
93 94 95
    assert_true(world.is_css_present(span_locator))
    assert_equal(world.css_find(span_locator).value, text)
    assert_true(world.css_visible(span_locator))
96

Calen Pennington committed
97

98 99 100 101
@step(u'I do not see the "([^"]*)" link$')
def i_do_not_see_the_span_with_text(step, text):
    # Note that the span will exist on the page but not be visible
    span_locator = '.toggle-button-sections span'
102 103
    assert_true(world.is_css_present(span_locator))
    assert_false(world.css_visible(span_locator))
104

Calen Pennington committed
105

106 107 108
@step(u'all sections are expanded$')
def all_sections_are_expanded(step):
    subsection_locator = 'div.subsection-list'
109
    subsections = world.css_find(subsection_locator)
110 111 112
    for s in subsections:
        assert_true(s.visible)

Calen Pennington committed
113

114
@step(u'all sections are collapsed$')
115
def all_sections_are_collapsed(step):
116
    subsection_locator = 'div.subsection-list'
117
    subsections = world.css_find(subsection_locator)
118
    for s in subsections:
Calen Pennington committed
119
        assert_false(s.visible)