Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
LinYunMo committed Aug 28, 2023
1 parent 382fff5 commit 8a532e8
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
10 changes: 10 additions & 0 deletions cocos/2d/components/label-outline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ export class LabelOutline extends Component {
label.outlineUsed = false;
}
}

/**
* @deprecated since v3.8.2, please use [[Label.outlineUsed]] instead.
*/
public onLoad (): void {
const label = this.node.getComponent(Label);
if (label && this.enabledInHierarchy) {
label.outlineUsed = true;
}
}
}

cclegacy.LabelOutline = LabelOutline;
10 changes: 10 additions & 0 deletions cocos/2d/components/label-shadow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,14 @@ export class LabelShadow extends Component {
label.shadowUsed = false;
}
}

/**
* @deprecated since v3.8.2, please use [[Label.outlineUsed]] instead.
*/
public onLoad (): void {
const label = this.node.getComponent(Label);
if (label && this.enabledInHierarchy) {
label.shadowUsed = true;
}
}
}
49 changes: 48 additions & 1 deletion tests/ui/label.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Label } from "../../cocos/2d/components";
import { Label, LabelOutline, LabelShadow } from "../../cocos/2d/components";
import { Node } from "../../cocos/scene-graph/node";
import { Color, Vec2 } from "../../exports/base";

test('label.string.setter', () => {
let node = new Node();
Expand All @@ -25,4 +26,50 @@ test('label.string.setter', () => {
expect(label.string).toStrictEqual('1');
label.string = 0;
expect(label.string).toStrictEqual('0');
});

test('labelOutline.setter', () => {
let node = new Node();
node.addComponent(Label);
let label = node.getComponent(Label) as Label;

node.addComponent(LabelOutline);
let labelOutline = node.getComponent(LabelOutline) as LabelOutline;
node._setActiveInHierarchy(true);
labelOutline.onLoad();
expect(label.outlineUsed).toStrictEqual(true);
labelOutline.color = new Color(255, 0, 0, 255);
expect(label.outlineColor).toStrictEqual(new Color(255, 0, 0, 255));
labelOutline.width = 2;
expect(label.outlineWidth).toStrictEqual(2);
labelOutline.enabled = false;
labelOutline.onDisable();
expect(label.outlineUsed).toStrictEqual(false);
labelOutline.enabled = true;
labelOutline.onEnable();
expect(label.outlineUsed).toStrictEqual(true);
});

test('labelShadow.setter', () => {
let node = new Node();
node.addComponent(Label);
let label = node.getComponent(Label) as Label;

node.addComponent(LabelShadow);
let labelShadow = node.getComponent(LabelShadow) as LabelShadow;
node._setActiveInHierarchy(true);
labelShadow.onLoad();
expect(label.shadowUsed).toStrictEqual(true);
labelShadow.color = new Color(255, 0, 0, 255);
expect(label.shadowColor).toStrictEqual(new Color(255, 0, 0, 255));
labelShadow.offset = new Vec2(2, 2);
expect(label.shadowOffset).toStrictEqual(new Vec2(2, 2));
labelShadow.blur = 2;
expect(label.shadowBlur).toStrictEqual(2);
labelShadow.enabled = false;
labelShadow.onDisable();
expect(label.shadowUsed).toStrictEqual(false);
labelShadow.enabled = true;
labelShadow.onEnable();
expect(label.shadowUsed).toStrictEqual(true);
});

0 comments on commit 8a532e8

Please sign in to comment.