rdkcentral/Lightning-UI-Components

Feature Request: test utils for animations

mauro1855 opened this issue · 0 comments

Hi,
Recently I was writing some tests to check if my animations were correctly triggered when, for example, I press a button or when I navigate away or wtv other use case I had.

I created a couple of functions to help me with this, which to be honest I'm not sure are strictly correct since I had to dig around in the methods / props available for a Lightning component instance. I wrote this:

export function getAnimations(Element) {
  return Array.from(Element.stage.animations.active).filter(
    a => a._element === Element || a._settings._actions.some(e => e._selector === Element.__ref)
  )
}

export function isAnimatingProp(Element, property) {
  const animations = getAnimations(Element)
  return animations.some(e => {
    if (e._element === Element) {
      return e._settings._actions.some(a => a._props[0] === property)
    } else {
      return e._settings._actions.some(
        a => a._selector === Element.__ref && a._props[0] === property
      )
    }
  })
}

I was wondering if you want to include these methods in the test-utils. Feel free to modify them if you think they are not correct.

Here is an example of a test making use of these:

test('moreInfo signal from Controls triggers controls and more info animations', async () => {
    const { instance } = await renderComponent(mockedStation, mockedVideoRecording)
    instance.PlayerControls.signal('moreInfo')

    expect(isAnimatingProp(instance.PlayerControls, 'y')).toBeTruthy()
    expect(isAnimatingProp(instance.MoreInfo, 'x')).toBeTruthy()
  })