Skip to content

Commit

Permalink
add sequence unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
zxx43 committed Sep 15, 2023
1 parent f6f9843 commit 8b94881
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
27 changes: 9 additions & 18 deletions cocos/tween/actions/action-interval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,7 @@ export class Sequence extends ActionInterval {
for (let i = 1; i < last; i++) {
if (paramArray[i]) {
action1 = prev;
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
prev = Sequence._actionOneTwo(action1, paramArray[i]);
prev = Sequence._actionOneTwo(action1 as ActionInterval, paramArray[i] as ActionInterval);
}
}
this.initWithTwoActions(prev, paramArray[last]);
Expand All @@ -349,8 +348,7 @@ export class Sequence extends ActionInterval {
durationOne *= actionOne._repeatMethod ? actionOne._timesForRepeat : 1;
durationTwo *= actionTwo._repeatMethod ? actionTwo._timesForRepeat : 1;
const d = durationOne + durationTwo;
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
this.initWithDuration(d);
this.initWithDuration(d as number);

this._actions[0] = actionOne;
this._actions[1] = actionTwo;
Expand All @@ -359,8 +357,7 @@ export class Sequence extends ActionInterval {

clone (): any {
const action = new Sequence();
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
this._cloneDecoration(action as any);
this._cloneDecoration(action as ActionInterval);
action.initWithTwoActions(this._actions[0].clone(), this._actions[1].clone());
return action as any;
}
Expand Down Expand Up @@ -472,14 +469,12 @@ export function sequence (/* Multiple Arguments */tempArray: any): ActionInterva
result = paramArray[0];
for (let i = 1; i <= last; i++) {
if (paramArray[i]) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
result = Sequence._actionOneTwo(result, paramArray[i]);
result = Sequence._actionOneTwo(result as ActionInterval, paramArray[i] as ActionInterval);
}
}
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return result;
return result as ActionInterval;
}

/*
Expand All @@ -502,8 +497,7 @@ export class Repeat extends ActionInterval {

constructor (action?: any, times?: any) {
super();
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
times !== undefined && this.initWithAction(action, times);
times !== undefined && this.initWithAction(action as FiniteTimeAction, times as number);

Check warning on line 500 in cocos/tween/actions/action-interval.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Expected an assignment or function call and instead saw an expression
}

/*
Expand Down Expand Up @@ -790,11 +784,9 @@ export class Spawn extends ActionInterval {
this._two = action2;

if (d1 > d2) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
this._two = Sequence._actionOneTwo(action2, delayTime(d1 - d2));
this._two = Sequence._actionOneTwo(action2 as ActionInterval, delayTime(d1 - d2));
} else if (d1 < d2) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
this._one = Sequence._actionOneTwo(action1, delayTime(d2 - d1));
this._one = Sequence._actionOneTwo(action1 as ActionInterval, delayTime(d2 - d1));
}

ret = true;
Expand Down Expand Up @@ -919,8 +911,7 @@ export class ReverseTime extends ActionInterval {

constructor (action?: any) {
super();
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
action && this.initWithAction(action);
action && this.initWithAction(action as ActionInterval);

Check warning on line 914 in cocos/tween/actions/action-interval.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

Expected an assignment or function call and instead saw an expression
}

/*
Expand Down
25 changes: 25 additions & 0 deletions tests/tween/tween.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,30 @@ test('destroySelf', function () {
tween(node).destroySelf().start();
game.step();
expect(onDestroy).toBeCalledTimes(1);
director.unregisterSystem(sys);
});

test('sequence', function () {
const sys = new TweenSystem();
(TweenSystem.instance as any) = sys;
director.registerSystem(TweenSystem.ID, sys, System.Priority.MEDIUM);

const node = new Node();
const target = new Vec3(10, 20, 30);
const tweenact = tween(node).to(1, {position: target}, { easing: "bounceOut" });
tween(node).sequence(tweenact).start();

for (let i = 0; i < 100; ++i) {
game.step();
}
// @ts-expect-error access private property
const action = tweenact._actions[0] as TweenAction;
// @ts-expect-error access private property
const props = action._props;
for (const property in props) {
const prop = props[property];
expect(Vec3.equals(prop.current, target)).toBeTruthy();
}

director.unregisterSystem(sys);
});

0 comments on commit 8b94881

Please sign in to comment.