{/* prettier-ignore */}
{/*
Copyright 2023 Comcast Cable Communications Management, LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

SPDX-License-Identifier: Apache-2.0
\*/}

import { Meta } from '@storybook/blocks';

<Meta title="Docs / Unit Testing / Test Utils / completeAnimation" />

# completeAnimation

Returns a Promise that resolves once all animating properties have updated to their target value(s).

## Arguments

`completeAnimation(element, transitionProperties = [])`

| argument             | type              | default | description                                                 |
| -------------------- | ----------------- | ------- | ----------------------------------------------------------- |
| element              | Lightning.Element | -       | element with properties that transition value changes       |
| transitionProperties | array\|string     | []      | property name(s) that transition value changes on component |

<br />

##### Example: Testing element properties before and after their values have transitioned

```js
import lng from '@lightningjs/core';
import { makeCreateComponent } from '@lightningjs/ui-components-test-utils';

class Example extends lng.Component {
  static _template() {
    return {
      TransitioningRect: {
        rect: true,
        color: 0xffffffff,
        w: 100,
        h: 100,
        x: 0,
        y: 0
      }
    };
  }

  _updatePosition() {
    this.tag('TransitioningRect').setSmooth('x', this.axisPosition);
    this.tag('TransitioningRect').setSmooth('y', this.axisPosition);
  }

  set axisPosition(value) {
    this._axisPosition = value;
    this._updatePosition();
  }

  get axisPosition() {
    return this._axisPosition;
  }
}

// generate a createComponent function to use in tests
const createExampleComponent = makeCreateComponent(Example);

// Ex. await the transitions of x and y values to finish before testing the result
it('should transition the x value of the component', async () => {
  const [example] = createExampleComponent();
  expect(example.tag('TransitioningRect').x).toBe(0);
  expect(example.tag('TransitioningRect').y).toBe(0);

  example.axisPosition = 50;
  await completeAnimation(example.tag('TransitioningRect'), ['x', 'y']);

  expect(example.tag('TransitioningRect').x).toBe(50);
  expect(example.tag('TransitioningRect').y).toBe(50);
});
```
