• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import * as path from 'path';
17import { PluginTestContext, PluginTester } from '../../../utils/plugin-tester';
18import { BuildConfig, mockBuildConfig } from '../../../utils/artkts-config';
19import { getRootPath, MOCK_ENTRY_DIR_PATH } from '../../../utils/path-config';
20import { parseDumpSrc } from '../../../utils/parse-string';
21import { uiNoRecheck } from '../../../utils/plugins';
22import { uiTransform } from '../../../../ui-plugins';
23import { Plugins } from '../../../../common/plugin-context';
24
25const ANIMATION_DIR_PATH: string = 'animation';
26
27const buildConfig: BuildConfig = mockBuildConfig();
28buildConfig.compileFiles = [
29    path.resolve(getRootPath(), MOCK_ENTRY_DIR_PATH, ANIMATION_DIR_PATH, 'animation-basic.ets'),
30];
31
32const animationTransform: Plugins = {
33    name: 'animation',
34    parsed: uiTransform().parsed,
35}
36
37const pluginTester = new PluginTester('test basic animation transform', buildConfig);
38
39const expectedScript: string = `
40import { __memo_id_type as __memo_id_type } from "arkui.stateManagement.runtime";
41
42import { __memo_context_type as __memo_context_type } from "arkui.stateManagement.runtime";
43
44import { memo as memo } from "arkui.stateManagement.runtime";
45
46import { UIColumnAttribute as UIColumnAttribute } from "@ohos.arkui.component";
47
48import { UITextAttribute as UITextAttribute } from "@ohos.arkui.component";
49
50import { EntryPoint as EntryPoint } from "arkui.UserView";
51
52import { CustomComponent as CustomComponent } from "arkui.component.customComponent";
53
54import { Text as Text, Column as Column, Component as Component, Color as Color, Curve as Curve } from "@ohos.arkui.component";
55
56import { Entry as Entry } from "@ohos.arkui.component";
57
58function main() {}
59
60
61
62@Entry({useSharedStorage:false,storage:"",routeName:""}) @Component({freezeWhenInactive:false}) final class AnimatablePropertyExample extends CustomComponent<AnimatablePropertyExample, __Options_AnimatablePropertyExample> {
63  public __initializeStruct(initializers: __Options_AnimatablePropertyExample | undefined, @memo() content: (()=> void) | undefined): void {}
64
65  public __updateStruct(initializers: __Options_AnimatablePropertyExample | undefined): void {}
66
67  @memo() public _build(@memo() style: ((instance: AnimatablePropertyExample)=> AnimatablePropertyExample) | undefined, @memo() content: (()=> void) | undefined, initializers: __Options_AnimatablePropertyExample | undefined): void {
68    Column(undefined, undefined, (() => {
69      Text(@memo() ((instance: UITextAttribute): void => {
70        instance.animationStart({
71          duration: 2000,
72          curve: Curve.Ease,
73        }).backgroundColor(Color.Red).animationStop({
74          duration: 2000,
75          curve: Curve.Ease,
76        }).animationStart({
77          duration: 2000,
78          curve: Curve.Ease,
79        }).fontSize(20).animationStop({
80          duration: 2000,
81          curve: Curve.Ease,
82        }).width("100%");
83        return;
84      }), "AnimatableProperty", undefined, undefined);
85    }));
86  }
87
88  public constructor() {}
89
90}
91
92interface __Options_AnimatablePropertyExample {
93
94}
95
96class __EntryWrapper extends EntryPoint {
97  @memo() public entry(): void {
98    AnimatablePropertyExample._instantiateImpl(undefined, (() => {
99      return new AnimatablePropertyExample();
100    }), undefined, undefined, undefined);
101  }
102
103  public constructor() {}
104
105}
106`;
107
108function testAnimationTransformer(this: PluginTestContext): void {
109    expect(parseDumpSrc(this.scriptSnapshot ?? '')).toBe(parseDumpSrc(expectedScript));
110}
111
112pluginTester.run(
113    'test basic animation transform',
114    [animationTransform, uiNoRecheck],
115    {
116        checked: [testAnimationTransformer],
117    },
118    {
119        stopAfter: 'checked',
120    }
121);
122