• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript _helpers.testEnv函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@interactjs/core/tests/_helpers.testEnv函数的典型用法代码示例。如果您正苦于以下问题:TypeScript testEnv函数的具体用法?TypeScript testEnv怎么用?TypeScript testEnv使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了testEnv函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: test

test('pointerEvents down move up tap', (t) => {
  const {
    scope,
    interaction,
    event,
  } = helpers.testEnv({ plugins: [pointerEvents, interactableTargets ] })

  const interactable = scope.interactables.new(event.target)
  const fired: Event[] = []

  for (const type of pointerEvents.types) {
    interactable.on(type, (e) => fired.push(e))
  }

  interaction.pointerDown(event, event, event.target)
  interaction.pointerMove(event, event, event.target)

  t.deepEqual(
    fired.map((e) => e.type),
    ['down'],
    'duplicate move event is not fired')

  interaction.pointerUp(event, event, scope.document.body, event.target)

  t.deepEqual(
    fired.map((e) => e.type),
    ['down', 'up', 'tap'],
    'tap event is fired after down and up event')

  t.end()
})
开发者ID:taye,项目名称:interact.js,代码行数:31,代码来源:base.spec.ts


示例2: test

test('modifiers/snap/edges', (t) => {
  const rect = { top: 0, left: 0, bottom: 100, right: 100 }
  const {
    interaction,
    interactable,
  } = helpers.testEnv({ rect })
  interaction.interactable = interactable
  interaction._interacting = true

  const target0 = Object.freeze({
    left: 50,
    right: 150,
    top: 0,
    bottom: 100,
  })
  const options = {
    targets: [
      { ...target0 },
    ],
    range: Infinity,
  }
  const pageCoords = Object.freeze({ x: 0, y: 0 })
  const arg = {
    interaction,
    interactable: interaction.interactable,
    state: null,
    pageCoords,
    coords: { ...pageCoords },
    offset: [{ x: 0, y: 0 }],
  }

  // resize from top left
  interaction.prepared.edges = { top: true, left: true }

  arg.state = { options }
  snapEdges.start(arg)
  snapEdges.set(arg)

  t.deepEqual(
    arg.coords,
    { x: target0.left, y: target0.top },
    'modified coords are correct')

  // resize from bottom right
  interaction.prepared.edges = { bottom: true, right: true }

  arg.state = { options }
  snapEdges.start(arg)
  snapEdges.set(arg)

  t.deepEqual(
    arg.coords,
    { x: target0.right, y: target0.bottom },
    'modified coord are correct')

  t.end()
})
开发者ID:taye,项目名称:interact.js,代码行数:57,代码来源:edges.spec.ts


示例3: test

test('holdRepeat count', (t) => {
  const pointerEvent = {
    type: 'hold',
    count: 0,
  }

  const { scope } = helpers.testEnv({ plugins: [pointerEvents, holdRepeat] })

  scope.pointerEvents.signals.fire('new', { pointerEvent })
  t.equal(pointerEvent.count, 1, 'first hold count is 1 with count previously undefined')

  const count = 20
  pointerEvent.count = count
  scope.pointerEvents.signals.fire('new', { pointerEvent })
  t.equal(pointerEvent.count, count + 1, 'existing hold count is incremented')

  t.end()
})
开发者ID:taye,项目名称:interact.js,代码行数:18,代码来源:holdRepeat.spec.ts


示例4: test

test('reflow', (t) => {
  const rect = Object.freeze({ top: 100, left: 200, bottom: 300, right: 400 })

  const {
    scope,
    interactable,
  } = helpers.testEnv({ plugins: [reflow], rect })

  Object.assign(scope.actions, { TEST: {}, names: ['TEST'] })

  t.ok(
    scope.Interactable.prototype.reflow instanceof Function,
    'reflow method is added to Interactable.prototype'
  )

  const fired = []

  interactable.fire = ((iEvent) => { fired.push(iEvent) }) as any
  (interactable.target as any) = {}
  interactable.options.TEST = { enabled: true }
  interactable.rectChecker(() => ({ ...rect }))

  // modify move coords
  scope.interactions.signals.on('before-action-move', ({ interaction }) => {
    interaction.coords.cur.page = {
      x: rect.left + 100,
      y: rect.top - 50,
    }
  })

  interactable.reflow({ name: 'TEST' })

  const phases = ['reflow', 'start', 'move', 'end']

  for (const index in phases) {
    const phase = phases[index]
    t.equal(fired[index].type, `TEST${phase}`, `event #${index} is ${phase}`)
  }

  const interaction = fired[0]._interaction

  t.deepEqual(
    interaction.coords.start.page,
    {
      x: rect.left,
      y: rect.top,
    },
    'uses element top left for event coords'
  )

  const reflowMove = fired[2]

  t.deepEqual(
    reflowMove.delta,
    { x: 100, y: -50 },
    'move delta is correct with modified interaction coords'
  )

  t.notOk(
    interaction.pointerIsDown,
    'reflow pointer was lifted'
  )

  t.equal(
    interaction.pointers.length,
    0,
    'reflow pointer was removed from interaction'
  )

  t.notOk(
    scope.interactions.list.includes(interaction),
    'interaction is removed from list'
  )

  t.end()
})
开发者ID:taye,项目名称:interact.js,代码行数:76,代码来源:reflow.spec.ts


示例5: test

test('modifiers/snap', (t) => {
  const {
    interaction,
    interactable,
  } = helpers.testEnv()
  const origin = { x: 120, y: 120 }

  interactable.options.TEST = { origin }
  interaction.interactable = interactable
  interaction.prepared = { name: 'TEST' }
  interaction._interacting = true

  let funcArgs = null
  const target0 = Object.freeze({ x:  50, y:  100 })
  // eslint-disable-next-line no-restricted-syntax, no-shadow
  const targetFunc = (x, y, _interaction, offset, index, ...unexpected) => {
    funcArgs = { x, y, offset, index, unexpected }
    return target0
  }
  const relativePoint = { x: 0, y: 0 }
  const options = {
    offset: null,
    offsetWithOrigin: true,
    targets: [
      target0,
      targetFunc,
    ],
    range: Infinity,
    relativePoints: [relativePoint],
  }

  const state = {
    options,
    realX: 0,
    realY: 0,
  }
  const pageCoords = Object.freeze({ x: 200, y: 300 })
  const arg = {
    interaction,
    interactable,
    state,
    pageCoords,
    coords: { ...pageCoords },
    rect: { top: 0, left: 0, bottom: 100, right: 100, width: 100, height: 100 },
    startOffset: { top: 0, left: 0, bottom: 0, right: 0 },
  } as any

  snap.start(arg)
  snap.set(arg)

  t.deepEqual(
    arg.coords,
    { x: target0.x + origin.x, y: target0.y + origin.y },
    'snaps to target and adds origin which will be subtracted by InteractEvent'
  )

  arg.coords = { ...pageCoords }
  state.options.targets = [targetFunc]
  snap.start(arg)
  snap.set(arg)

  t.deepEqual(
    funcArgs,
    {
      x: pageCoords.x - origin.x,
      y: pageCoords.y - origin.y,
      offset: {
        x: origin.x,
        y: origin.y,
        relativePoint,
        index: 0,
      },
      index: 0,
      unexpected: [],
    },
    'x, y, interaction, offset, index are passed to target function; origin subtracted from x, y'
  )

  arg.coords = { ...pageCoords }
  options.offset = { x: 300, y: 300 }
  options.offsetWithOrigin = false
  snap.start(arg)
  snap.set(arg)

  t.deepEqual(
    arg.coords,
    { x: target0.x + 300, y: target0.y + 300 },
    'origin not added to target when !options.offsetWithOrigin'
  )

  t.deepEqual(
    { x: funcArgs.x, y: funcArgs.y },
    { x: pageCoords.x - origin.x - 300, y: pageCoords.y - origin.y - 300 },
    'origin still subtracted from function target x, y args when !options.offsetWithOrigin'
  )

  t.end()
})
开发者ID:taye,项目名称:interact.js,代码行数:98,代码来源:pointer.spec.ts


示例6: test

test('inertia', (t) => {
  const {
    scope,
    interaction,
    target,
    interactable,
    coords,
    event,
  } = helpers.testEnv({ plugins: [inertia, drag] })
  const element = target as HTMLElement
  const modifierChange = 5
  const testModifier = {
    options: { endOnly: true },
    methods: { set ({ coords: modifierCoords }) {
      modifierCoords.x += modifierChange
      modifierCoords.y += modifierChange
      modifierCallCount++
    } },
  }

  let modifierCallCount = 0

  coords.client = coords.page
  scope.now = () => coords.timeStamp
  interactable.draggable({ inertia: true })

  // test inertia without modifiers or throw
  downStartMoveUp({ x: 100, y: 0, dt: 1000 })
  t.notOk(interaction.inertia.active, '{ modifiers: [] } && !thrown: inertia is not activated')

  // test inertia without modifiers and with throw
  downStartMoveUp({ x: 100, y: 0, dt: 10 })
  t.ok(interaction.inertia.active, 'thrown: inertia is activated')

  interactable.draggable({ modifiers: [testModifier as any] })

  // test inertia with { endOnly: true } modifier and with throw
  downStartMoveUp({ x: 100, y: 0, dt: 10 })
  t.equal(modifierCallCount, 1, '{ endOnly: true } && thrown: modifier is not called from pointerUp')
  t.deepEqual(
    helpers.getProps(interaction.inertia, ['modifiedXe', 'modifiedYe']),
    {
      modifiedXe: interaction.inertia.xe + modifierChange,
      modifiedYe: interaction.inertia.ye + modifierChange,
    },
    '{ endOnly: true } && thrown: inertia target coords are correct')

  // test smoothEnd with { endOnly: false } modifier
  testModifier.options.endOnly = false
  downStartMoveUp({ x: 1, y: 0, dt: 1000 })
  t.notOk(interaction.inertia.active, '{ endOnly: false } && !thrown: inertia smoothEnd is not activated')
  t.equal(modifierCallCount, 2, '{ endOnly: false } && !thrown: modifier is called from pointerUp')

  // test smoothEnd with { endOnly: true } modifier
  testModifier.options.endOnly = true
  downStartMoveUp({ x: 1, y: 0, dt: 1000 })
  t.ok(interaction.inertia.active, '{ endOnly: true } && !thrown: inertia smoothEnd is activated')
  t.equal(modifierCallCount, 1, '{ endOnly: true } && !thrown: modifier is not called from pointerUp')

  interaction.stop()
  t.end()

  function downStartMoveUp ({ x, y, dt }) {
    modifierCallCount = 0
    coords.timeStamp = 0
    interaction.stop()

    Object.assign(coords.page, { x: 0, y: 0 })
    interaction.pointerDown(event, event, element)

    interaction.start({ name: 'drag' }, interactable, element)

    Object.assign(coords.page, { x, y })
    coords.timeStamp = dt
    interaction.pointerMove(event, event, element)
    interaction.pointerUp(event, event, element, element)
  }
})
开发者ID:taye,项目名称:interact.js,代码行数:78,代码来源:inertia.spec.ts



注:本文中的@interactjs/core/tests/_helpers.testEnv函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript utils.extend函数代码示例发布时间:2022-05-28
下一篇:
TypeScript _helpers.mockSignals函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap