Skip to content

Commit

Permalink
Merge f01d595 into 069216a
Browse files Browse the repository at this point in the history
  • Loading branch information
volkipp committed Jan 16, 2018
2 parents 069216a + f01d595 commit b030ea5
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Carousel3d.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@
},
rightIndices () {
let n = (this.visible - 1) / 2
n = (this.bias.toLowerCase() === 'right' ? Math.ceil(n) : Math.floor(n))
const indices = []
Expand Down Expand Up @@ -405,9 +405,12 @@
/**
* Re-compute the number of slides and current slide
*/
computeData () {
computeData (firstRun) {
this.total = this.getSlideCount()
this.currentIndex = parseInt(this.startIndex) > this.total - 1 ? this.total - 1 : parseInt(this.startIndex)
if (firstRun || this.currentIndex >= this.total) {
this.currentIndex = parseInt(this.startIndex) > this.total - 1 ? this.total - 1 : parseInt(this.startIndex)
}
this.viewport = this.$el.clientWidth
},
setSize () {
Expand All @@ -417,7 +420,7 @@
},
mounted () {
this.computeData()
this.computeData(true)
this.attachMutationObserver()
if (!this.$isServer) {
Expand Down
30 changes: 30 additions & 0 deletions tests/client/components/Carousel3d.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,35 @@ describe('Carousel3d', () => {
return utils.expectToMatchSnapshot(vm);
});

it('should not change current slide index if computeData called and total number of slides have not change and in of bounds ', () => {
const vm = new Vue({
el: document.createElement('div'),
render: (h) => h(Carousel3d, { props: { startIndex: 0, loop: false } }, [h(Slide), h(Slide)]),
});
const carouselInstance = vm.$children[0];
return carouselInstance.$nextTick().then(() => {
carouselInstance.goNext();
carouselInstance.computeData();
expect(carouselInstance.$data.currentIndex).toBe(1);

return utils.expectToMatchSnapshot(vm);
});
});

it('should change current slide index if computeData called and current slide index falls out of bounds ', () => {
const vm = new Vue({
el: document.createElement('div'),
render: (h) => h(Carousel3d, { props: { startIndex: 0, loop: false } }, [h(Slide), h(Slide), h(Slide)]),
});
const carouselInstance = vm.$children[0];
return carouselInstance.$nextTick().then(() => {
carouselInstance.goSlide(2);
carouselInstance.$slots.default.pop();
carouselInstance.computeData();
expect(carouselInstance.$data.currentIndex).toBe(0);

return utils.expectToMatchSnapshot(vm);
});
});

})
17 changes: 17 additions & 0 deletions tests/client/components/__snapshots__/Carousel3d.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ exports[`Carousel3d should be able to go on prev slide if start slide index is 0
"
`;

exports[`Carousel3d should change current slide index if computeData called and current slide index falls out of bounds 1`] = `
".carousel-3d-slider(style=\'width: 0px; height: 0px;\')
.carousel-3d-slide(style=\'border-width: 1px; width: 0px; height: 0px;\')
.carousel-3d-slide(style=\'border-width: 1px; width: 0px; height: 0px;\')
.carousel-3d-slide(style=\'border-width: 1px; width: 0px; height: 0px;\')
//
"
`;

exports[`Carousel3d should decrease current index number by 1 when goPrev is called 1`] = `
".carousel-3d-slider(style=\'width: 0px; height: 0px;\')
.carousel-3d-slide(style=\'border-width: 1px; width: 0px; height: 0px;\')
Expand Down Expand Up @@ -70,6 +79,14 @@ exports[`Carousel3d should not be able to go on next slide if start slide index
"
`;

exports[`Carousel3d should not change current slide index if computeData called and total number of slides have not change and in of bounds 1`] = `
".carousel-3d-slider(style=\'width: 0px; height: 0px;\')
.carousel-3d-slide(style=\'border-width: 1px; width: 0px; height: 0px;\')
.carousel-3d-slide(style=\'border-width: 1px; width: 0px; height: 0px;\')
//
"
`;

exports[`Carousel3d should register 0 slides when 0 slides are added to the slots 1`] = `
".carousel-3d-slider(style=\'width: 0px; height: 0px;\')
//
Expand Down

0 comments on commit b030ea5

Please sign in to comment.