Skip to content

Commit 5118b42

Browse files
committedMar 24, 2015
[added] Test for carousel control behaviour with wrap=true
1 parent ea479db commit 5118b42

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
 

‎test/CarouselSpec.jsx

+41
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,45 @@ describe('Carousel', function () {
7373
)[0]
7474
);
7575
});
76+
77+
it('Should show all controls on the first/last image if wrap is true', function () {
78+
var instance = ReactTestUtils.renderIntoDocument(
79+
<Carousel activeIndex={0} controls={true} wrap={true}>
80+
<CarouselItem ref="item1">Item 1 content</CarouselItem>
81+
<CarouselItem ref="item2">Item 2 content</CarouselItem>
82+
</Carousel>
83+
);
84+
85+
var backButton = ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'left');
86+
87+
assert.ok(backButton);
88+
assert.equal(backButton.props.href, '#prev');
89+
90+
instance = ReactTestUtils.renderIntoDocument(
91+
<Carousel activeIndex={1} controls={true} wrap={true}>
92+
<CarouselItem ref="item1">Item 1 content</CarouselItem>
93+
<CarouselItem ref="item2">Item 2 content</CarouselItem>
94+
</Carousel>
95+
);
96+
97+
var nextButton = ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'right');
98+
99+
assert.ok(nextButton);
100+
assert.equal(nextButton.props.href, '#next');
101+
});
102+
103+
it('Should not show the prev button on the first image if wrap is false', function () {
104+
var instance = ReactTestUtils.renderIntoDocument(
105+
<Carousel activeIndex={0} controls={true} wrap={false}>
106+
<CarouselItem ref="item1">Item 1 content</CarouselItem>
107+
<CarouselItem ref="item2">Item 2 content</CarouselItem>
108+
</Carousel>
109+
);
110+
111+
var backButtons = ReactTestUtils.scryRenderedDOMComponentsWithClass(instance, 'left');
112+
var nextButtons = ReactTestUtils.scryRenderedDOMComponentsWithClass(instance, 'right');
113+
114+
assert.equal(backButtons.length, 0);
115+
assert.equal(nextButtons.length, 1);
116+
});
76117
});

0 commit comments

Comments
 (0)
Please sign in to comment.