|
| 1 | +import { expect } from 'chai' |
| 2 | +import { shallowMount } from '@vue/test-utils' |
| 3 | +import Agile from '@/Agile.vue' |
| 4 | + |
| 5 | +const slides = '<div>1</div><div>2</div><div>3</div><div>4</div><div>5</div><div>6</div>' |
| 6 | + |
| 7 | +describe('Infinite mode:', () => { |
| 8 | + describe('Enabled:', () => { |
| 9 | + it('click prev button on first slide should move to the last one', () => { |
| 10 | + const wrapper = shallowMount(Agile, { |
| 11 | + propsData: { |
| 12 | + infinite: true |
| 13 | + }, |
| 14 | + slots: { |
| 15 | + default: slides |
| 16 | + } |
| 17 | + }) |
| 18 | + |
| 19 | + const prevButton = wrapper.find({ ref: 'prevButton' }) |
| 20 | + prevButton.trigger('click') |
| 21 | + |
| 22 | + expect(wrapper.vm.canGoToPrev).equal(true) |
| 23 | + expect(wrapper.vm.getCurrentSlide()).equal(5) |
| 24 | + }) |
| 25 | + |
| 26 | + it('click next button on last slide should move to the first one', () => { |
| 27 | + const wrapper = shallowMount(Agile, { |
| 28 | + propsData: { |
| 29 | + infinite: true, |
| 30 | + initialSlide: 5 |
| 31 | + }, |
| 32 | + slots: { |
| 33 | + default: slides |
| 34 | + } |
| 35 | + }) |
| 36 | + |
| 37 | + const nextButton = wrapper.find({ ref: 'nextButton' }) |
| 38 | + nextButton.trigger('click') |
| 39 | + |
| 40 | + expect(wrapper.vm.canGoToNext).equal(true) |
| 41 | + expect(wrapper.vm.getCurrentSlide()).equal(0) |
| 42 | + }) |
| 43 | + }) |
| 44 | + |
| 45 | + describe('Disabled:', () => { |
| 46 | + it('click prev button on first slide shouldn\'t be available', () => { |
| 47 | + const wrapper = shallowMount(Agile, { |
| 48 | + propsData: { |
| 49 | + infinite: false |
| 50 | + }, |
| 51 | + slots: { |
| 52 | + default: slides |
| 53 | + } |
| 54 | + }) |
| 55 | + |
| 56 | + const prevButton = wrapper.find({ ref: 'prevButton' }) |
| 57 | + prevButton.trigger('click') |
| 58 | + |
| 59 | + expect(wrapper.vm.canGoToPrev).equal(false) |
| 60 | + expect(wrapper.vm.getCurrentSlide()).equal(0) |
| 61 | + }) |
| 62 | + |
| 63 | + it('click next button on last slide shouldn\'t be available', () => { |
| 64 | + const wrapper = shallowMount(Agile, { |
| 65 | + propsData: { |
| 66 | + infinite: false, |
| 67 | + initialSlide: 5 |
| 68 | + }, |
| 69 | + slots: { |
| 70 | + default: slides |
| 71 | + } |
| 72 | + }) |
| 73 | + |
| 74 | + const nextButton = wrapper.find({ ref: 'nextButton' }) |
| 75 | + nextButton.trigger('click') |
| 76 | + |
| 77 | + expect(wrapper.vm.canGoToNext).equal(false) |
| 78 | + expect(wrapper.vm.getCurrentSlide()).equal(5) |
| 79 | + }) |
| 80 | + }) |
| 81 | +}) |
0 commit comments