def test_check_classes_added_for_images(web_fixture): """A Widget can be supplied to be used caption for an added image.""" carousel = Carousel(web_fixture.view, 'my_carousel_id') img_widget = Img(web_fixture.view) carousel.add_slide(img_widget) assert img_widget.get_attribute('class') == 'd-block w-100'
def test_adding_items_to_carousel(web_fixture, carousel_fixture): """Images can be added to a Carousel.""" fixture = carousel_fixture carousel = Carousel(web_fixture.view, 'my_carousel_id', show_indicators=True) main_div = fixture.get_main_div_for(carousel) [indicator_list, carousel_inner, left_control, right_control] = main_div.children # Initially, no items or indicators are present assert carousel_inner.children == [] assert fixture.carousel_indicators_present(carousel) assert fixture.get_indicator_list_for(carousel) == [] image = Img(web_fixture.view) added_item = carousel.add_slide(image) # A carousel item was added for the image [carousel_item] = carousel_inner.children assert carousel_item is added_item assert 'carousel-item' in carousel_item.get_attribute('class') [actual_image] = carousel_item.children assert actual_image is image # An indicator was added for the item [indicator] = fixture.get_indicator_list_for(carousel) assert indicator.get_attribute('data-target') == '#my_carousel_id' assert indicator.get_attribute('data-slide-to') == '0'
def test_active_state_of_items(web_fixture, carousel_fixture): """The first item added is marked as active, and also its corresponding indicator.""" fixture = carousel_fixture carousel = Carousel(web_fixture.view, 'my_carousel_id') carousel.add_slide(Img(web_fixture.view)) carousel.add_slide(Img(web_fixture.view)) main_div = fixture.get_main_div_for(carousel) [indicator_list, carousel_inner, left_control, right_control] = main_div.children #only the first item is active [carousel_item_1, carousel_item_2] = carousel_inner.children assert carousel_item_1.get_attribute('class') == 'active carousel-item' assert carousel_item_2.get_attribute('class') == 'carousel-item' #only the first indicator is active [indicator_0, indicator_1] = fixture.get_indicator_list_for(carousel) assert indicator_0.get_attribute('class') == 'active' assert not indicator_1.has_attribute('class') assert indicator_0.get_attribute('data-slide-to') == '0' assert indicator_1.get_attribute('data-slide-to') == '1'
def item_indicators_are_optional(fixture): """With show_indicators=False, indicators are not added when adding items.""" carousel = Carousel(fixture.view, 'my_carousel_id', show_indicators=False) vassert(not fixture.carousel_indicators_present(carousel)) carousel.add_slide(Img(fixture.view)) #after adding the item, indicators shouldn't appear vassert(not fixture.carousel_indicators_present(carousel))
def test_item_indicators_are_optional(web_fixture, carousel_fixture): """With show_indicators=False, indicators are not added when adding items.""" fixture = carousel_fixture carousel = Carousel(web_fixture.view, 'my_carousel_id', show_indicators=False) assert not fixture.carousel_indicators_present(carousel) carousel.add_slide(Img(web_fixture.view)) #after adding the item, indicators shouldn't appear assert not fixture.carousel_indicators_present(carousel)
def test_adding_items_with_captions(web_fixture): """A Widget can be supplied to be used caption for an added image.""" carousel = Carousel(web_fixture.view, 'my_carousel_id') caption_widget = Widget(web_fixture.view) carousel_item = carousel.add_slide(Img(web_fixture.view), caption_widget=caption_widget) [image, div_containing_caption] = carousel_item.children assert div_containing_caption.get_attribute('class') == 'carousel-caption' [actual_caption_widget] = div_containing_caption.children assert actual_caption_widget is caption_widget
def test_carousel_basics(web_fixture): """A Carousel contains all the right classes and contents to act as a Bootstrap Carousel component.""" widget = Carousel(web_fixture.view, 'my_carousel_id') [main_div] = widget.children # The main div assert main_div.get_attribute('id') == 'my_carousel_id' assert main_div.get_attribute('class') == 'carousel slide' [indicator_list, carousel_inner, left_control, right_control] = main_div.children # Indicators assert indicator_list.get_attribute('class') == 'carousel-indicators' # Inner (container of the images) assert carousel_inner.get_attribute('class') == 'carousel-inner' # Controls def check_control(control, action, label): assert control.get_attribute('class') == 'carousel-control-%s' % action assert control.get_attribute('role') == 'button' assert control.get_attribute('data-slide') == action [icon, text] = control.children assert icon.get_attribute('class') == 'carousel-control-%s-icon' % action assert icon.get_attribute('aria-hidden') == 'true' assert text.children[0].value == label assert text.get_attribute('class') == 'sr-only' check_control(left_control, 'prev', 'Previous') check_control(right_control, 'next', 'Next')
def test_carousel_has_options(web_fixture, carousel_fixture): """Constructor allows you to set certain customizing options""" carousel = Carousel(web_fixture.view, 'my_carousel_id', interval=1000, pause='hover', wrap=True, keyboard=True) main_div = carousel_fixture.get_main_div_for(carousel) assert main_div.get_attribute('data-interval') == '1000' assert main_div.get_attribute('data-pause') == 'hover' assert main_div.get_attribute('data-wrap') == 'true' assert main_div.get_attribute('data-keyboard') == 'true'
def __init__(self, view): super(MyPage, self).__init__(view) self.body.use_layout(Container()) carousel = Carousel(view, 'my_example_carousel_id', show_indicators=True) self.body.add_child(carousel) carousel.add_slide(PlaceholderImage(view, 900, 500, text='Slide 1', alt='Slide 1 was here'), caption_widget=P(view, text='a paragraph with text')) carousel.add_slide(PlaceholderImage(view, 900, 500, text='Slide 2', alt='Slide 2 was here'), caption_widget=P(view, text='a different paragraph'))
def test_i18n(web_fixture): """User-visible labels are internationalised.""" context = LocaleContextStub(locale='af').install() context.config = web_fixture.config context.session = web_fixture.context.session context.request = webob.Request.blank('/', charset='utf8') widget = Carousel(web_fixture.view, 'my_carousel_id') [main_div] = widget.children [indicator_list, carousel_inner, left_control, right_control] = main_div.children def check_control(control, label): [icon, text] = control.children assert text.children[0].value == label check_control(left_control, 'Vorige') check_control(right_control, 'Volgende')
def i18n(fixture): """User-visible labels are internationalised.""" @stubclass(WebExecutionContext) class AfrikaansContext(WebExecutionContext): request = webob.Request.blank('/', charset='utf8') @property def interface_locale(self): return 'af' with AfrikaansContext(): widget = Carousel(fixture.view, 'my_carousel_id') [main_div] = widget.children [indicator_list, carousel_inner, left_control, right_control] = main_div.children def check_control(control, label): [icon, text] = control.children vassert(text.children[0].value == label) check_control(left_control, 'Vorige') check_control(right_control, 'Volgende')
def carousel_basics(fixture): """A Carousel contains all the right classes and contents to act as a Bootstrap Carousel component.""" widget = Carousel(fixture.view, 'my_carousel_id') [main_div] = widget.children # The main div vassert(main_div.get_attribute('id') == 'my_carousel_id') vassert(main_div.get_attribute('class') == 'carousel slide') [indicator_list, carousel_inner, left_control, right_control] = main_div.children # Indicators vassert(indicator_list.get_attribute('class') == 'carousel-indicators') # Inner (container of the images) vassert(carousel_inner.get_attribute('class') == 'carousel-inner') vassert(carousel_inner.get_attribute('role') == 'listbox') # Controls def check_control(control, position, action, label): vassert( control.get_attribute('class') == 'carousel-control %s' % position) vassert(control.get_attribute('role') == 'button') vassert(control.get_attribute('data-slide') == action) [icon, text] = control.children vassert(icon.get_attribute('class') == 'icon-%s' % action) vassert(icon.get_attribute('aria-hidden') == 'true') vassert(text.children[0].value == label) vassert(text.get_attribute('class') == 'sr-only') check_control(left_control, 'left', 'prev', 'Previous') check_control(right_control, 'right', 'next', 'Next')