|
| 1 | +import test from 'tape' |
| 2 | +import {getOffset} from '../src/offset' |
| 3 | + |
| 4 | +test('getOffset() all visible', assert => { |
| 5 | + const msg = "no offset for all cards" |
| 6 | + const expected = [0, 0, 0] |
| 7 | + const testGetOffset = index => getOffset({index, firstVisibleIndex:0, lastVisibleIndex:2}) |
| 8 | + const actual = [0,1,2].map((e, i) => testGetOffset(i)) |
| 9 | + assert.deepEqual(actual, expected, msg) |
| 10 | + assert.end() |
| 11 | +}) |
| 12 | + |
| 13 | +test('getOffset() 1 hidden on left', assert => { |
| 14 | + const msg = "only first card offset of -2" |
| 15 | + const stackSpace = 2 |
| 16 | + const expected = [-stackSpace, 0, 0, 0] |
| 17 | + const testGetOffset = index => getOffset({index, firstVisibleIndex:1, lastVisibleIndex:3, stackSpace}) |
| 18 | + const actual = [0,1,2,3].map(i => testGetOffset(i)) |
| 19 | + assert.deepEqual(actual, expected, msg) |
| 20 | + assert.end() |
| 21 | +}) |
| 22 | + |
| 23 | +test('getOffset() 6 hidden on left', assert => { |
| 24 | + const msg = "two most left are on top of each others" |
| 25 | + const stackSpace = 2 |
| 26 | + const visibleStack = 3 |
| 27 | + const expected = [-4*stackSpace-1, -4*stackSpace-1,-4*stackSpace,-3*stackSpace,-2*stackSpace,-stackSpace, 0, 0, 0] |
| 28 | + const testGetOffset = index => getOffset({index, firstVisibleIndex:6, lastVisibleIndex:8, stackSpace, visibleStack}) |
| 29 | + const actual = [0,1,2,3,4,5,6,7,8].map(i => testGetOffset(i)) |
| 30 | + assert.deepEqual(actual, expected, msg) |
| 31 | + assert.end() |
| 32 | +}) |
| 33 | + |
| 34 | +test('getOffset() 1 hidden on each side', assert => { |
| 35 | + const msg = "first and last card offset" |
| 36 | + const stackSpace = 2 |
| 37 | + const expected = [-stackSpace, 0, 0, 0, stackSpace] |
| 38 | + const testGetOffset = index => getOffset({index, firstVisibleIndex:1, lastVisibleIndex:3, stackSpace}) |
| 39 | + const actual = [0,1,2,3,4].map(i => testGetOffset(i)) |
| 40 | + assert.deepEqual(actual, expected, msg) |
| 41 | + assert.end() |
| 42 | +}) |
| 43 | + |
| 44 | +test('getOffset() 6 hidden on each side', assert => { |
| 45 | + const msg = "offsets" |
| 46 | + const stackSpace = 2 |
| 47 | + const visibleStack = 3 |
| 48 | + const expected = [-4*stackSpace-1, -4*stackSpace-1,-4*stackSpace,-3*stackSpace,-2*stackSpace,-stackSpace, 0, 0, 0, |
| 49 | + stackSpace, 2*stackSpace, 3*stackSpace,4*stackSpace, 4*stackSpace+1, 4*stackSpace+1] |
| 50 | + const testGetOffset = index => getOffset({index, firstVisibleIndex:6, lastVisibleIndex:8, stackSpace, visibleStack}) |
| 51 | + const actual = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14].map(i => testGetOffset(i)) |
| 52 | + assert.deepEqual(actual, expected, msg) |
| 53 | + assert.end() |
| 54 | +}) |
0 commit comments