Skip to content

Commit

Permalink
#154 DisplayObjectContainerのusecaseにUnitTestを追加(WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
ienaga committed Dec 4, 2024
1 parent 3691719 commit c3df4f5
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 625 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { execute } from "./DisplayObjectContainerAddChildUseCase";
import { Shape } from "../../Shape";
import { DisplayObjectContainer } from "../../DisplayObjectContainer";
import { describe, expect, it } from "vitest";

describe("DisplayObjectContainerAddChildUseCase.js test", () =>
{
it("execute test case1", () =>
{
const container = new DisplayObjectContainer();
const shape1 = new Shape();
const shape2 = new Shape();

container.changed = false;
expect(container.changed).toBe(false);

expect(shape1.$added).toBe(false);
expect(shape1.parent).toBe(null);
expect(container.children.length).toBe(0);
execute(container, shape1);
expect(shape1.$added).toBe(true);
expect((shape1.parent as NonNullable<DisplayObjectContainer>).instanceId).toBe(container.instanceId);
expect(container.changed).toBe(true);

container.changed = false;
expect(container.changed).toBe(false);

expect(shape2.$added).toBe(false);
expect(shape2.parent).toBe(null);
expect(container.children.length).toBe(1);
execute(container, shape2);
expect(shape2.$added).toBe(true);
expect((shape2.parent as NonNullable<DisplayObjectContainer>).instanceId).toBe(container.instanceId);
expect(container.changed).toBe(true);

expect(container.children.length).toBe(2);

expect((container.children[0] as NonNullable<Shape>).instanceId).toBe(shape1.instanceId);
expect((container.children[1] as NonNullable<Shape>).instanceId).toBe(shape2.instanceId);
});

it("execute test case2", () =>
{
const container = new DisplayObjectContainer();
const shape1 = new Shape();
const shape2 = new Shape();
const shape3 = new Shape();

container.changed = false;
expect(container.changed).toBe(false);

expect(shape1.$added).toBe(false);
expect(shape1.parent).toBe(null);
expect(container.children.length).toBe(0);
execute(container, shape1, 0);
expect(container.children.length).toBe(1);
expect(shape1.$added).toBe(true);
expect((shape1.parent as NonNullable<DisplayObjectContainer>).instanceId).toBe(container.instanceId);
expect(container.changed).toBe(true);

container.changed = false;
expect(container.changed).toBe(false);

expect(shape2.$added).toBe(false);
expect(shape2.parent).toBe(null);
execute(container, shape2, 0);
expect(container.children.length).toBe(2);
expect(shape2.$added).toBe(true);
expect((shape2.parent as NonNullable<DisplayObjectContainer>).instanceId).toBe(container.instanceId);
expect(container.changed).toBe(true);

execute(container, shape3, 0);
expect(container.children.length).toBe(3);

expect((container.children[0] as NonNullable<Shape>).instanceId).toBe(shape3.instanceId);
expect((container.children[1] as NonNullable<Shape>).instanceId).toBe(shape2.instanceId);
expect((container.children[2] as NonNullable<Shape>).instanceId).toBe(shape1.instanceId);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { execute } from "./DisplayObjectContainerAdvanceFrameUseCase";
import { DisplayObjectContainer } from "../../DisplayObjectContainer";
import { MovieClip } from "../../MovieClip";
import { describe, expect, it } from "vitest";

describe("DisplayObjectContainerAdvanceFrameUseCase.js test", () =>
{
it("execute test case1", () =>
{
const container = new DisplayObjectContainer();
const movieClip = container.addChild(new MovieClip());

movieClip.totalFrames = 10;
movieClip.$canAction = false;
movieClip.$hasTimelineHeadMoved = false;

expect(movieClip.currentFrame).toBe(1);
expect(movieClip.$canAction).toBe(false);
expect(movieClip.$hasTimelineHeadMoved).toBe(false);

execute(container);

expect(movieClip.currentFrame).toBe(2);
expect(movieClip.$canAction).toBe(true);
expect(movieClip.$hasTimelineHeadMoved).toBe(true);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { execute } from "./DisplayObjectContainerRemoveChildUseCase";
import { Shape } from "../../Shape";
import { DisplayObjectContainer } from "../../DisplayObjectContainer";
import { describe, expect, it } from "vitest";

describe("DisplayObjectContainerRemoveChildUseCase.js test", () =>
{
it("execute test case1", () =>
{
const container = new DisplayObjectContainer();
const shape1 = container.addChild(new Shape());
const shape2 = container.addChild(new Shape());

expect(shape1.$added).toBe(true);
expect(shape1.parent?.instanceId).toBe(container.instanceId);

expect(shape2.$added).toBe(true);
expect(shape2.parent?.instanceId).toBe(container.instanceId);

expect(container.children.length).toBe(2);
execute(container, shape1);

expect(container.children.length).toBe(1);
expect(shape1.$added).toBe(false);
expect(shape1.parent).toBe(null);

execute(container, shape2);

expect(container.children.length).toBe(0);
expect(shape2.$added).toBe(false);
expect(shape2.parent).toBe(null);
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const execute = <P extends DisplayObjectContainer, D extends DisplayObjec

const parent = display_object.parent;
if (parent
&& (parent as unknown as DisplayObjectContainer).instanceId === display_object_container.instanceId
&& (parent as unknown as DisplayObjectContainer).instanceId !== display_object_container.instanceId
) {
return ;
}
Expand Down
Loading

0 comments on commit c3df4f5

Please sign in to comment.