Skip to content

Commit

Permalink
test: fix e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
theniceangel committed Feb 1, 2021
1 parent 5e72621 commit ce7387e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 60 deletions.
78 changes: 39 additions & 39 deletions packages/wheel/src/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ describe('wheel plugin tests', () => {
expect(scroll.proxy).toHaveBeenLastCalledWith([
{
key: 'wheelTo',
sourceKey: 'plugins.wheel.wheelTo',
sourceKey: 'plugins.wheel.wheelTo'
},
{
key: 'getSelectedIndex',
sourceKey: 'plugins.wheel.getSelectedIndex',
sourceKey: 'plugins.wheel.getSelectedIndex'
},
{
key: 'restorePosition',
sourceKey: 'plugins.wheel.restorePosition',
},
sourceKey: 'plugins.wheel.restorePosition'
}
])
})

Expand All @@ -72,14 +72,14 @@ describe('wheel plugin tests', () => {
expect(wheel.selectedIndex).toBe(0)
// specified
const { wheel: wheel2 } = createWheel({
selectedIndex: 2,
selectedIndex: 2
})
expect(wheel2.selectedIndex).toBe(2)
})

it('should trigger scroll.scrollTo when invoking wheelTo method', () => {
addPropertiesToWheel(wheel, {
itemHeight: 40,
itemHeight: 40
})
wheel.wheelTo(0)

Expand All @@ -89,25 +89,25 @@ describe('wheel plugin tests', () => {

it('should return seletedIndex when invoking getSelectedIndex', () => {
const { wheel: wheel2 } = createWheel({
selectedIndex: 2,
selectedIndex: 2
})
expect(wheel2.getSelectedIndex()).toBe(2)
})

it('should support scrollTo somewhere by selectedIndex when initialized', () => {
addPropertiesToWheel(wheel, {
selectedIndex: 1,
itemHeight: 50,
itemHeight: 50
})
const postion = {
x: 100,
y: 100,
y: 100
}
// manually trigger
scroll.hooks.trigger(scroll.hooks.eventTypes.beforeInitialScrollTo, postion)
expect(postion).toMatchObject({
x: 0,
y: -50,
y: -50
})
})

Expand All @@ -116,7 +116,7 @@ describe('wheel plugin tests', () => {
addPropertiesToWheel(wheel, {
items: [div],
target: div,
wheelTo: jest.fn(),
wheelTo: jest.fn()
})

scroll.scroller.hooks.trigger('checkClick')
Expand All @@ -127,7 +127,7 @@ describe('wheel plugin tests', () => {
addPropertiesToWheel(wheel, {
items: [div],
target: null,
wheelTo: jest.fn(),
wheelTo: jest.fn()
})
let ret = scroll.scroller.hooks.trigger('checkClick')
expect(ret).toBe(true)
Expand All @@ -140,7 +140,7 @@ describe('wheel plugin tests', () => {
items: [div],
target: div,
itemHeight: 40,
wheelTo: jest.fn(),
wheelTo: jest.fn()
})

scroll.scroller.hooks.trigger('scrollTo', endPoint)
Expand All @@ -152,36 +152,36 @@ describe('wheel plugin tests', () => {
addPropertiesToWheel(wheel, {
items: [div],
target: div,
itemHeight: 40,
itemHeight: 40
})
let pos = {
top: -20,
left: 0,
left: 0
}
div.className = 'wheel-item'
scroll.scroller.hooks.trigger('scrollToElement', div, pos)

expect(pos).toEqual({
top: -0,
left: 0,
left: 0
})

// mismatch target element
let div1 = document.createElement('div')
let pos1 = {
top: -40,
left: 0,
left: 0
}
addPropertiesToWheel(wheel, {
items: [div1],
target: div1,
itemHeight: 40,
itemHeight: 40
})
let ret = scroll.scroller.hooks.trigger('scrollToElement', div1, pos1)
expect(ret).toBe(true)
expect(pos1).toMatchObject({
top: -40,
left: 0,
left: 0
})
})

Expand All @@ -200,7 +200,7 @@ describe('wheel plugin tests', () => {
let cachedYBoundary = {} as Boundary
addPropertiesToWheel(wheel, {
items: [div, div],
itemHight: 50,
itemHight: 50
})
const { scrollBehaviorX, scrollBehaviorY } = scroll.scroller
// append two element
Expand All @@ -220,46 +220,46 @@ describe('wheel plugin tests', () => {

expect(cachedXBoundary).toMatchObject({
minScrollPos: 0,
maxScrollPos: 0,
maxScrollPos: 0
})

expect(cachedYBoundary).toMatchObject({
minScrollPos: 0,
maxScrollPos: -50,
maxScrollPos: -50
})
})

it('should change momentumInfo when scroll.scroller.scrollBehaviorY trigger momentum or end hook', () => {
let momentumInfo = {
destination: 0,
rate: 15,
rate: 15
}
let div = document.createElement('div')
addPropertiesToWheel(wheel, {
items: [div],
target: div,
itemHeight: 40,
itemHeight: 40
})
scroll.scroller.scrollBehaviorY.hooks.trigger('momentum', momentumInfo)

expect(momentumInfo).toEqual({
destination: -0,
rate: 4,
rate: 4
})

scroll.scroller.scrollBehaviorY.currentPos = -20
scroll.scroller.scrollBehaviorY.hooks.trigger('end', momentumInfo)
expect(momentumInfo).toEqual({
destination: -0,
rate: 4,
duration: 400,
duration: 400
})

scroll.scroller.scrollBehaviorY.hooks.trigger('momentum', momentumInfo, 800)
expect(momentumInfo).toEqual({
destination: -0,
rate: 4,
duration: 2000,
duration: 400
})
})

Expand All @@ -269,7 +269,7 @@ describe('wheel plugin tests', () => {
addPropertiesToWheel(wheel, {
items: [div],
target: div,
itemHeight: 40,
itemHeight: 40
})
wheel.options.selectedIndex = 1
scroll.hooks.trigger(scroll.hooks.eventTypes.refresh, newContent)
Expand All @@ -280,7 +280,7 @@ describe('wheel plugin tests', () => {
it('scroll.scroller.animater.hooks.time ', () => {
let div = document.createElement('div')
addPropertiesToWheel(wheel, {
items: [div],
items: [div]
})
const animater = scroll.scroller.animater
animater.hooks.trigger(animater.hooks.eventTypes.time, 100)
Expand All @@ -290,7 +290,7 @@ describe('wheel plugin tests', () => {
it('scroll.scroller.animater.hooks.timeFunction ', () => {
let div = document.createElement('div')
addPropertiesToWheel(wheel, {
items: [div],
items: [div]
})
const animater = scroll.scroller.animater
animater.hooks.trigger(
Expand All @@ -308,7 +308,7 @@ describe('wheel plugin tests', () => {
addPropertiesToWheel(wheel, {
items: [div1, div2],
itemHeight: 40,
wheelItemsAllDisabled: false,
wheelItemsAllDisabled: false
})
scroll.y = -41
scroll.maxScrollY = -80
Expand All @@ -321,20 +321,20 @@ describe('wheel plugin tests', () => {
addPropertiesToWheel(wheel, {
items: [div],
itemHeight: 40,
wheelItemsAllDisabled: false,
wheelItemsAllDisabled: false
})
const translater = scroll.scroller.animater.translater
translater.hooks.trigger(translater.hooks.eventTypes.translate, {
x: 0,
y: -20,
y: -20
})
expect(wheel.selectedIndex).toEqual(0)
})

it('scroll.scroller.hooks.minDistanceScroll ', () => {
let div = document.createElement('div')
addPropertiesToWheel(wheel, {
items: [div],
items: [div]
})
const scroller = scroll.scroller
scroller.animater.forceStopped = true
Expand All @@ -347,7 +347,7 @@ describe('wheel plugin tests', () => {
let div2 = document.createElement('div')
addPropertiesToWheel(wheel, {
itemHeight: 40,
items: [div1, div2],
items: [div1, div2]
})
scroll.maxScrollY = -80
scroll.scroller.animater.forceStopped = true
Expand All @@ -366,7 +366,7 @@ describe('wheel plugin tests', () => {

it('wheel.restorePosition()', () => {
addPropertiesToWheel(wheel, {
itemHeight: 40,
itemHeight: 40
})
// simulate bs is scrolling
scroll.pending = true
Expand All @@ -383,7 +383,7 @@ describe('wheel plugin tests', () => {
addPropertiesToWheel(wheel, {
items: [div1, div2],
itemHeight: 40,
wheelItemsAllDisabled: false,
wheelItemsAllDisabled: false
})
scroll.y = -41
scroll.maxScrollY = -80
Expand All @@ -398,12 +398,12 @@ describe('wheel plugin tests', () => {

let div3 = document.createElement('div')
let position3 = {
y: -39,
y: -39
}
addPropertiesToWheel(wheel, {
items: [div1, div2, div3],
itemHeight: 40,
wheelItemsAllDisabled: false,
wheelItemsAllDisabled: false
})
scroller.hooks.trigger(scroller.hooks.eventTypes.scrollTo, position3)
expect(position3.y).toBe(-80)
Expand Down
14 changes: 7 additions & 7 deletions tests/e2e/compose-plugins/pullup-pulldown.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('Compose/pullup-pulldown', () => {

const itemsCounts = await page.$$eval(
'.pullup-down-list-item',
(element) => element.length
element => element.length
)

await expect(itemsCounts).toBeGreaterThanOrEqual(30)
Expand All @@ -28,19 +28,19 @@ describe('Compose/pullup-pulldown', () => {
y: 150,
xDistance: 0,
yDistance: 300,
gestureSourceType: 'touch',
gestureSourceType: 'touch'
})
const { isShowPullDownTxt, isShowLoading } = await page.$$eval(
'.pulldown-wrapper',
(elements) => {
elements => {
const isShowPullDownTxt =
window.getComputedStyle(elements[0].children[0]).display === 'block'
const isShowLoading =
window.getComputedStyle(elements[0].children[1].children[0])
.display === 'block'
return {
isShowPullDownTxt,
isShowLoading,
isShowLoading
}
}
)
Expand All @@ -56,14 +56,14 @@ describe('Compose/pullup-pulldown', () => {
x: 200,
y: 630,
xDistance: 0,
yDistance: -500,
yDistance: -1000,
speed: 1500,
gestureSourceType: 'touch',
gestureSourceType: 'touch'
})
await page.waitFor(4000)
const itemsCounts = await page.$$eval(
'.pullup-down-list-item',
(element) => element.length
element => element.length
)
await expect(itemsCounts).toBeGreaterThanOrEqual(60)
})
Expand Down
Loading

0 comments on commit ce7387e

Please sign in to comment.