-
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose more stuff with engine, add more containScroll options, add sl…
…idesInView, remove scrollProgress actions
- Loading branch information
davidcetinkaya
committed
May 1, 2020
1 parent
d9b7f51
commit 3adbae9
Showing
10 changed files
with
320 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { Alignment, Alignments } from '../components/alignment' | ||
import { SlidesInView } from '../components/slidesInView' | ||
|
||
const viewSize = 100 | ||
const slideSizes = [30, 40, 30, 40, 60, 30, 50] | ||
const firstSlide = slideSizes[0] | ||
const contentSize = slideSizes.reduce((a, s) => a + s, 0) | ||
|
||
const noThreshold = 0 | ||
const fullThreshold = 1 | ||
|
||
const getAlignment = (align: Alignments): Alignment => { | ||
return Alignment({ align, viewSize }) | ||
} | ||
|
||
const getSlidesInView = ( | ||
loop: boolean, | ||
inViewThreshold: number, | ||
): SlidesInView => { | ||
return SlidesInView({ | ||
contentSize, | ||
slideSizes, | ||
viewSize, | ||
inViewThreshold, | ||
loop, | ||
}) | ||
} | ||
|
||
describe('SlidesInView', () => { | ||
const startAlign = getAlignment('start').measure(firstSlide) | ||
const centerAlign = getAlignment('center').measure(firstSlide) | ||
const endAlign = getAlignment('end').measure(firstSlide) | ||
|
||
describe('Finds slides in view with no threshold when', () => { | ||
describe('Loop is false, and align is', () => { | ||
const slidesInView = getSlidesInView(false, noThreshold) | ||
|
||
test('Start', () => { | ||
const indexesInView = slidesInView.check(startAlign) | ||
expect(indexesInView).toEqual([0, 1, 2]) | ||
}) | ||
|
||
test('Center', () => { | ||
const indexesInView = slidesInView.check(centerAlign) | ||
expect(indexesInView).toEqual([0, 1]) | ||
}) | ||
|
||
test('End', () => { | ||
const indexesInView = slidesInView.check(endAlign) | ||
expect(indexesInView).toEqual([0]) | ||
}) | ||
}) | ||
|
||
describe('Loop is true, and align is', () => { | ||
const slidesInView = getSlidesInView(true, noThreshold) | ||
|
||
test('Start', () => { | ||
const indexesInView = slidesInView.check(startAlign) | ||
expect(indexesInView).toEqual([0, 1, 2]) | ||
}) | ||
|
||
test('Center', () => { | ||
const indexesInView = slidesInView.check(centerAlign) | ||
expect(indexesInView).toEqual([0, 1, 6]) | ||
}) | ||
|
||
test('End', () => { | ||
const indexesInView = slidesInView.check(endAlign) | ||
expect(indexesInView).toEqual([0, 5, 6]) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('Finds slides in view with full threshold when', () => { | ||
describe('Loop is false, and align is', () => { | ||
const slidesInView = getSlidesInView(false, fullThreshold) | ||
|
||
test('Start', () => { | ||
const indexesInView = slidesInView.check(startAlign) | ||
expect(indexesInView).toEqual([1]) | ||
}) | ||
|
||
test('Center', () => { | ||
const indexesInView = slidesInView.check(centerAlign) | ||
expect(indexesInView).toEqual([0]) | ||
}) | ||
|
||
test('End', () => { | ||
const indexesInView = slidesInView.check(endAlign) | ||
expect(indexesInView).toEqual([]) | ||
}) | ||
}) | ||
|
||
describe('Loop is true, and align is', () => { | ||
const slidesInView = getSlidesInView(true, fullThreshold) | ||
|
||
test('Start', () => { | ||
const indexesInView = slidesInView.check(startAlign) | ||
expect(indexesInView).toEqual([1]) | ||
}) | ||
|
||
test('Center', () => { | ||
const indexesInView = slidesInView.check(centerAlign) | ||
expect(indexesInView).toEqual([0]) | ||
}) | ||
|
||
test('End', () => { | ||
const indexesInView = slidesInView.check(endAlign) | ||
expect(indexesInView).toEqual([6]) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.