Skip to content

Commit

Permalink
#128 テストコードを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
ienaga committed Feb 6, 2025
1 parent 1a54f9c commit 20fdd99
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 7 deletions.
35 changes: 35 additions & 0 deletions src/application/Context/service/ContextRunService.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { execute } from "./ContextRunService";
import { $getContext } from "../../../application/variable/Context";
import { describe, expect, it, vi } from "vitest";
import { MovieClip } from "@next2d/display";

const root = new MovieClip();

Object.defineProperty(window, "next2d", {
"get": vi.fn().mockReturnValue({
"createRootMovieClip": async () => {
return root;
}
})
});

describe("ContextRunService Test", () =>
{
it("execute test case", async () =>
{
const config = {
"platform": "web",
"spa": false,
"stage": {
"width": 800,
"height": 600,
"fps": 60
}
};

await execute(config);
const context = $getContext();
expect(context).not.toBeNull();
expect(context.root.instanceId).toBe(root.instanceId)
});
});
47 changes: 47 additions & 0 deletions src/application/Context/service/ContextUnbindService.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type { ViewModel } from "../../../view/ViewModel";
import { execute } from "./ContextUnbindService";
import { MovieClip } from "@next2d/display";
import { Context } from "../../../application/Context";
import { $setContext } from "../../../application/variable/Context";
import { $setConfig } from "../../../application/variable/Config";
import { View } from "../../../view/View";
import { describe, expect, it } from "vitest";

describe("ContextUnbindService Test", () =>
{
it("execute test case", async () =>
{
// mock
$setConfig({
"platform": "web",
"spa": false,
"stage": {
"width": 800,
"height": 600,
"fps": 60
}
});

const root = new MovieClip();
const context = new Context(root);
$setContext(context);

let state = "none";
context.view = new View();
root.addChild(context.view);
context.viewModel = {
"unbind": (view: View) =>
{
state = "unbind";
}
} as ViewModel;

expect(state).toBe("none");
expect(root.numChildren).toBe(1);

await execute(context);

expect(state).toBe("unbind");
expect(root.numChildren).toBe(0);
});
});
51 changes: 51 additions & 0 deletions src/application/Context/usecase/ContextBindUseCase.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { execute } from "./ContextBindUseCase";
import { MovieClip } from "@next2d/display";
import { Context } from "../../../application/Context";
import { $setContext } from "../../../application/variable/Context";
import { $setConfig } from "../../../application/variable/Config";
import { packages } from "../../../application/variable/Packages";
import { View } from "../../../view/View";
import { ViewModel } from "../../../view/ViewModel";
import { describe, expect, it } from "vitest";

describe("ContextBindUseCase Test", () =>
{
it("execute test case1", async () =>
{
// mock
$setConfig({
"platform": "web",
"spa": false,
"stage": {
"width": 800,
"height": 600,
"fps": 60
}
});

let state = "none";
class TestViewModel extends ViewModel
{
async bind ()
{
state = "bind";
}
}

packages.clear();
packages.set("TestView", View);
packages.set("TestViewModel", TestViewModel);

const root = new MovieClip();
const context = new Context(root);
$setContext(context);

expect(state).toBe("none");
expect(root.numChildren).toBe(0);

await execute(context, "test");

expect(state).toBe("bind");
expect(root.numChildren).toBe(1);
});
});
8 changes: 1 addition & 7 deletions src/domain/loading/Loading/service/LoadingEndService.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { execute } from "./LoadingEndService";
import { MovieClip } from "@next2d/display";
import { Context } from "../../../../application/Context";
import { $setContext } from "../../../../application/variable/Context";
import { $setConfig } from "../../../../application/variable/Config";
import { packages } from "../../../../application/variable/Packages";
import {
$getInstance,
$setInstance
} from "../../Loading";
import { $setInstance } from "../../Loading";
import { describe, expect, it } from "vitest";

describe("LoadingEndService Test", () =>
Expand Down

0 comments on commit 20fdd99

Please sign in to comment.