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 2322566 commit 6780c1c
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 34 deletions.
63 changes: 29 additions & 34 deletions src/domain/callback/service/CallbackService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { execute } from "./CallbackService";
import { packages } from "../../../application/variable/Packages";
import { describe, expect, it } from "vitest";

describe("CallbackService", () =>
describe("CallbackService Test", () =>
{
it("execute test case1", async () =>
{
Expand Down Expand Up @@ -30,42 +30,37 @@ describe("CallbackService", () =>
expect(state).toBe("single test");
});

// it("execute multiple test", () =>
// {
// // mock
// const MultipleTestCase1 = class MultipleTest
// {
// execute (value: any): any
// {
// return `${value}_1`;
// }
// };
it("execute multiple test", async () =>
{
// mock
let state1 = "none";
const MultipleTestCase1 = class MultipleTest
{
execute (value: any): any
{
state1 = `${value}_1`;
}
};

// const MultipleTestCase2 = class MultipleTest
// {
// execute (value: any): any
// {
// return `${value}_2`;
// }
// };
let state2 = "none";
const MultipleTestCase2 = class MultipleTest
{
execute (value: any): any
{
state2 = `${value}_2`;
}
};

// packages.clear();
// packages.set("multiple.test.case1", MultipleTestCase1);
// packages.set("multiple.test.case2", MultipleTestCase2);
packages.clear();
packages.set("multiple.test.case1", MultipleTestCase1);
packages.set("multiple.test.case2", MultipleTestCase2);

// execute(["multiple.test.case1", "multiple.test.case2"], "multiple test")
// .then((results: string[] | void) =>
// {
// if (!results) {
// throw new Error("stop test");
// }
expect(state1).toBe("none");
expect(state2).toBe("none");

// expect(results.length).toBe(2);
// const result1: string = results[0];
// expect(result1).toBe("multiple test_1");
await execute(["multiple.test.case1", "multiple.test.case2"], "multiple test")

// const result2: string = results[1];
// expect(result2).toBe("multiple test_2");
// });
// });
expect(state1).toBe("multiple test_1");
expect(state2).toBe("multiple test_2");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { Shape } from "@next2d/display";
import type { Job } from "@next2d/ui";
import { MovieClip } from "@next2d/display";
import { Context } from "../../../../application/Context";
import { $setContext } from "../../../../application/variable/Context";
import { $setConfig } from "../../../../application/variable/Config";
import { DefaultLoader } from "../../DefaultLoader";
import { execute } from "./DefaultLoaderEndService";
import { describe, expect, it } from "vitest";

describe("DefaultLoaderEndService Test", () =>
{
it("execute test", () =>
{
$setConfig({
"platform": "web",
"spa": false,
"stage": {
"width": 800,
"height": 600,
"fps": 60
}
});
$setContext(new Context(new MovieClip()));

// mock
const defaultLoader = new DefaultLoader();
defaultLoader.start();

const sprite = defaultLoader.sprite;
const length = sprite.numChildren;
for (let idx = 0; idx < length; ++idx) {
const shape = sprite.getChildAt(idx) as Shape;
expect(shape.hasLocalVariable("reduceJob")).toBe(true);
expect(shape.hasLocalVariable("expandJob")).toBe(true);

const expandJob = shape.getLocalVariable("expandJob") as Job;
const reduceJob = shape.getLocalVariable("reduceJob") as Job;
expect(expandJob.stopFlag).toBe(false);
expect(reduceJob.stopFlag).toBe(false);
}

execute(defaultLoader);

for (let idx = 0; idx < length; ++idx) {
const shape = sprite.getChildAt(idx) as Shape;
const expandJob = shape.getLocalVariable("expandJob") as Job;
const reduceJob = shape.getLocalVariable("reduceJob") as Job;
expect(expandJob.entries).toBeNull();
expect(reduceJob.entries).toBeNull();
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { Shape } from "@next2d/display";
import { MovieClip } from "@next2d/display";
import { Context } from "../../../../application/Context";
import { $setContext } from "../../../../application/variable/Context";
import { $setConfig } from "../../../../application/variable/Config";
import { DefaultLoader } from "../../DefaultLoader";
import { execute } from "./DefaultLoaderStartService";
import { describe, expect, it } from "vitest";

describe("DefaultLoaderStartService Test", () =>
{
it("execute test", async () =>
{
$setConfig({
"platform": "web",
"spa": false,
"stage": {
"width": 800,
"height": 600,
"fps": 60
}
});
$setContext(new Context(new MovieClip()));

// mock
const defaultLoader = new DefaultLoader();

const sprite = defaultLoader.sprite;
const length = sprite.numChildren;
for (let idx = 0; idx < length; ++idx) {
const shape = sprite.getChildAt(idx) as Shape;
expect(shape.hasLocalVariable("reduceJob")).toBe(false);
expect(shape.hasLocalVariable("expandJob")).toBe(false);
}

execute(defaultLoader);

for (let idx = 0; idx < length; ++idx) {
const shape = sprite.getChildAt(idx) as Shape;
expect(shape.hasLocalVariable("reduceJob")).toBe(true);
expect(shape.hasLocalVariable("expandJob")).toBe(true);
}
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { DefaultLoader } from "../../DefaultLoader";
import { execute } from "./DefaultLoadingInitializeService";
import { Sprite } from "@next2d/display";
import { describe, expect, it } from "vitest";

describe("DefaultLoadingInitializeService Test", () =>
{
it("execute test", async () =>
{
// mock
const defaultLoader = {
"sprite": new Sprite(),
} as DefaultLoader;

expect(defaultLoader.sprite.numChildren).toBe(0);
execute(defaultLoader);
expect(defaultLoader.sprite.numChildren).toBe(3);
});
});

0 comments on commit 6780c1c

Please sign in to comment.