jest.setTimeout(30000);
describe('test swiper', () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isMP = platformInfo.startsWith('mp')
const isWeb = platformInfo.startsWith('web')
const isHarmony = platformInfo.startsWith('harmony')
let page;
const detailResWithCurrentItemId = {
current: 1,
currentItemId: 'B',
source: 'autoplay' ,
}
const detailRes = {
current: 1,
source: 'autoplay' ,
}
beforeAll(async () => {
page = await program.reLaunch('/pages/component/swiper/swiper')
await page.waitFor(600)
})
if(!isMP) {
it('check autoplay loop', async () => {
await page.setData({
currentValChange: 0,
autoplaySelect: true,
})
await page.waitFor(isHarmony ? 2700 : 2500)
expect(await page.data('currentValChange')).toEqual(1)
await page.waitFor(isHarmony ? 2700 : 2500)
expect(await page.data('currentValChange')).toEqual(2)
await page.waitFor(isHarmony ? 2700 : 2500)
expect(await page.data('currentValChange')).toEqual(0)
await page.setData({
autoplaySelect: false
})
await page.waitFor(300)
});
}
it('check current', async () => {
if(isMP) {
await page.setData({
intervalSelect: 0,
})
}
await page.setData({
currentVal: 2,
})
await page.waitFor(600)
expect(await page.data('currentValChange')).toEqual(2)
await page.setData({
currentVal: 0,
})
await page.waitFor(600)
expect(await page.data('currentValChange')).toEqual(0)
if(isMP) {
await page.setData({
intervalSelect: 2000,
})
}
});
it('check currentId', async () => {
await page.setData({
currentItemIdVal: 'C',
})
await page.waitFor(800)
expect(await page.data('currentValChange')).toEqual(2)
await page.setData({
currentItemIdVal: 'A',
})
await page.waitFor(800)
expect(await page.data('currentValChange')).toEqual(0)
});
it('Trigger Event', async () => {
await page.setData({
swiperChangeSelect: true,
swiperTransitionSelect: true,
swiperAnimationfinishSelect: true,
autoplaySelect:true
})
await page.waitFor(2000)
await page.waitFor(async()=>{
return await page.data('currentValChange') == 1
})
await page.setData({
autoplaySelect:false
})
});
it('Event transition', async () => {
await page.waitFor(100)
const transitionDetailInfo = await page.data('transitionDetailTest')
expect(transitionDetailInfo.dy).toBe(0)
expect(transitionDetailInfo.dx).not.toBe(0)
expect(await page.data('isTransitionTest')).toBe('transition:Success')
});
it('Event change', async () => {
const changeDetailInfo = await page.data('changeDetailTest')
if(isWeb || isMP || isHarmony){
expect(changeDetailInfo).toEqual(detailResWithCurrentItemId)
}else{
expect(changeDetailInfo).toEqual(detailRes)
}
expect(await page.data('isChangeTest')).toBe('change:Success')
});
it('Event animationfinish', async () => {
await page.waitFor(2000)
const animationfinishDetailInfo = await page.data('animationfinishDetailTest')
if(isWeb || isMP || isHarmony){
expect(animationfinishDetailInfo).toEqual(detailResWithCurrentItemId)
}else{
expect(animationfinishDetailInfo).toEqual(detailRes)
}
expect(await page.data('isAnimationfinishTest')).toBe('animationfinish:Success')
});
});