Skip to content

Commit 1ecf790

Browse files
added tests for new method getSlideDirection
1 parent d0056dd commit 1ecf790

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

test/specs/carousel.test.js

+52
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,58 @@ describe('<Carousel />', () => {
408408
nextButton.simulate('click');
409409
expect(wrapper).toHaveState({ currentSlide: 0 });
410410
});
411+
412+
describe('#getSlideDirection', () => {
413+
let instance;
414+
415+
beforeEach(async () => {
416+
const wrapper = mount(
417+
<Carousel>
418+
<p>Slide 1</p>
419+
<p>Slide 2</p>
420+
<p>Slide 3</p>
421+
</Carousel>
422+
);
423+
instance = wrapper.instance();
424+
});
425+
426+
it('should return zero if start and end slide are the same regardless of isWrapping', () => {
427+
expect(instance.getSlideDirection(2, 2, true)).toEqual(0);
428+
expect(instance.getSlideDirection(2, 2, false)).toEqual(0);
429+
});
430+
431+
it('should return -1 if isWrapping is true and start is less than end', () => {
432+
const isWrapping = true;
433+
const start = 0;
434+
const end = 6;
435+
436+
expect(instance.getSlideDirection(start, end, isWrapping)).toEqual(-1);
437+
});
438+
439+
it('should return 1 if isWrapping is true and start is greater than end', () => {
440+
const isWrapping = true;
441+
const start = 6;
442+
const end = 0;
443+
444+
expect(instance.getSlideDirection(start, end, isWrapping)).toEqual(1);
445+
});
446+
447+
it('should return 1 if isWrapping is false and start is less than end', () => {
448+
const isWrapping = false;
449+
const start = 0;
450+
const end = 6;
451+
452+
expect(instance.getSlideDirection(start, end, isWrapping)).toEqual(1);
453+
});
454+
455+
it('should return -1 if isWrapping is false and start is greater than end', () => {
456+
const isWrapping = false;
457+
const start = 6;
458+
const end = 0;
459+
460+
expect(instance.getSlideDirection(start, end, isWrapping)).toEqual(-1);
461+
});
462+
});
411463
});
412464

413465
describe('Controls', () => {

0 commit comments

Comments
 (0)