-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
134 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
47
src/application/Context/service/ContextUnbindService.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
51
src/application/Context/usecase/ContextBindUseCase.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters