Skip to content

Commit

Permalink
#154 test: UnitTestを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
ienaga committed Jul 27, 2024
1 parent 66be7b3 commit cdeca53
Show file tree
Hide file tree
Showing 20 changed files with 88 additions and 59 deletions.
16 changes: 8 additions & 8 deletions packages/events/src/Event.test.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
import { Event } from "./Event";
import { describe, expect, it } from "vitest";

describe("Event.js toString test", function()
describe("Event.js toString test", () =>
{
it("toString test case1", function()
it("toString test case1", () =>
{
const event = new Event("test");
expect(event.toString())
.toBe("[Event type=\"test\" bubbles=false cancelable=false eventPhase=2]");
});
});

describe("Event.js static toString test", function()
describe("Event.js static toString test", () =>
{
it("static toString test", function()
it("static toString test", () =>
{
expect(Event.toString()).toBe("[class Event]");
});
});

describe("Event.js namespace test", function()
describe("Event.js namespace test", () =>
{
it("namespace test public", function()
it("namespace test public", () =>
{
const event = new Event("test");
expect(event.namespace).toBe("next2d.events.Event");
});

it("namespace test static", function()
it("namespace test static", () =>
{
expect(Event.namespace).toBe("next2d.events.Event");
});
});

describe("Event.js property test", function()
describe("Event.js property test", () =>
{

it("ACTIVATE test", () =>
Expand Down
4 changes: 2 additions & 2 deletions packages/events/src/Event/EventFormatToStringService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { Event } from "../Event";
import { execute } from "./EventFormatToStringService";
import { describe, expect, it } from "vitest";

describe("EventFormatToStringService.js toString test", function()
describe("EventFormatToStringService.js toString test", () =>
{
it("toString test case", function()
it("toString test case", () =>
{
const event = new Event("test");
expect(execute(event, "Event", "type", "bubbles", "cancelable", "eventPhase"))
Expand Down
12 changes: 6 additions & 6 deletions packages/events/src/EventDispatcher.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EventDispatcher } from "./EventDispatcher";
import { describe, expect, it } from "vitest";

describe("EventDispatcher.js toString test", function()
describe("EventDispatcher.js toString test", () =>
{
// toString
it("toString test success", () =>
Expand All @@ -11,23 +11,23 @@ describe("EventDispatcher.js toString test", function()
});
});

describe("EventDispatcher.js static toString test", function()
describe("EventDispatcher.js static toString test", () =>
{
it("static toString test", function()
it("static toString test", () =>
{
expect(EventDispatcher.toString()).toBe("[class EventDispatcher]");
});
});

describe("EventDispatcher.js namespace test", function()
describe("EventDispatcher.js namespace test", () =>
{
it("namespace test public", function()
it("namespace test public", () =>
{
const eventDispatcher = new EventDispatcher();
expect(eventDispatcher.namespace).toBe("next2d.events.EventDispatcher");
});

it("namespace test static", function()
it("namespace test static", () =>
{
expect(EventDispatcher.namespace).toBe("next2d.events.EventDispatcher");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { EventPhase } from "../EventPhase";
import { $broadcastEvents } from "../EventUtil";
import { describe, expect, it } from "vitest";

describe("EventDispatcher.js dispatchEvent test", function()
describe("EventDispatcher.js dispatchEvent test", () =>
{
it("dispatchEvent test case1", () =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Event } from "../Event";
import { EventDispatcher } from "../EventDispatcher";
import { describe, expect, it } from "vitest";
import { describe, expect, it, vi } from "vitest";

describe("EventDispatcher.js removeAllEventListener test", function()
describe("EventDispatcher.js removeAllEventListener test", () =>
{
it("removeAllEventListener test case1", () =>
{
const eventDispatcher = new EventDispatcher();
eventDispatcher.addEventListener("test", () => {});
eventDispatcher.addEventListener("test", () => {});
eventDispatcher.addEventListener("test", () => {});
eventDispatcher.addEventListener("test", vi.fn());
eventDispatcher.addEventListener("test", vi.fn());
eventDispatcher.addEventListener("test", vi.fn());

expect(eventDispatcher.hasEventListener("test")).toBe(true);
eventDispatcher.removeAllEventListener("test");
Expand All @@ -19,7 +19,7 @@ describe("EventDispatcher.js removeAllEventListener test", function()
it("removeAllEventListener test case2", () =>
{
const eventDispatcher = new EventDispatcher();
eventDispatcher.addEventListener(Event.ENTER_FRAME, () => {});
eventDispatcher.addEventListener(Event.ENTER_FRAME, vi.fn());

expect(eventDispatcher.hasEventListener(Event.ENTER_FRAME)).toBe(true);
eventDispatcher.removeAllEventListener(Event.ENTER_FRAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { EventDispatcher } from "../EventDispatcher";
import { EventListenerImpl } from "../interface/EventListenerImpl";
import { describe, expect, it } from "vitest";

describe("EventDispatcher.js removeEventListener test", function()
describe("EventDispatcher.js removeEventListener test", () =>
{
it("removeEventListener test case1", () =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EventDispatcher } from "../EventDispatcher";
import { describe, expect, it } from "vitest";
import { describe, expect, it, vi } from "vitest";

describe("EventDispatcher.js willTrigger test", function()
describe("EventDispatcher.js willTrigger test", () =>
{
it("willTrigger test success case1", () =>
{
Expand All @@ -25,7 +25,7 @@ describe("EventDispatcher.js willTrigger test", function()
}
const child = new Child(parent1);

parent1.addEventListener("test", () => {});
parent1.addEventListener("test", vi.fn());

expect(parent2.willTrigger("test")).toBe(false);
expect(parent1.willTrigger("test")).toBe(true);
Expand Down Expand Up @@ -54,7 +54,7 @@ describe("EventDispatcher.js willTrigger test", function()
const child1 = new Child(parent);
const child2 = new Child(parent);

parent.addEventListener("test", () => {});
parent.addEventListener("test", vi.fn());

expect(parent.willTrigger("test")).toBe(true);
expect(child1.willTrigger("test")).toBe(true);
Expand Down
6 changes: 3 additions & 3 deletions packages/media/src/Sound/SoundEndedEventService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Event } from "@next2d/events";
import { execute } from "./SoundEndedEventService";
import { describe, expect, it, vi } from "vitest";

describe("SoundEndedEventService.js namespace test", () =>
describe("SoundEndedEventService.js test", () =>
{
it("namespace test case1", () =>
it("execute test case1", () =>
{
let state = "";
const MockSound = vi.fn().mockImplementation(() =>
Expand All @@ -24,7 +24,7 @@ describe("SoundEndedEventService.js namespace test", () =>
expect(state).toBe("play");
});

it("namespace test case2", () =>
it("execute test case2", () =>
{
let state = "";
let type = "";
Expand Down
6 changes: 3 additions & 3 deletions packages/media/src/Sound/SoundLoadStartEventService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
} from "@next2d/events";
import { describe, expect, it, vi } from "vitest";

describe("SoundLoadStartEventService.js namespace test", () =>
describe("SoundLoadStartEventService.js test", () =>
{
it("namespace open event test case1", () =>
it("execute test case1", () =>
{
const sound = new Sound();

Expand All @@ -35,7 +35,7 @@ describe("SoundLoadStartEventService.js namespace test", () =>

});

it("namespace progress event test case1", () =>
it("execute test case2", () =>
{
const sound = new Sound();

Expand Down
6 changes: 3 additions & 3 deletions packages/media/src/Sound/SoundLoadendEventService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
} from "@next2d/events";
import { describe, expect, it, vi } from "vitest";

describe("SoundLoadendEventService.js namespace test", () =>
describe("SoundLoadendEventService.js test", () =>
{
it("namespace progress event test case1", () =>
it("execute test case1", () =>
{
const sound = new Sound();

Expand Down Expand Up @@ -44,7 +44,7 @@ describe("SoundLoadendEventService.js namespace test", () =>
expect(openState).toBe(Next2DProgressEvent.PROGRESS);
});

it("namespace progress event test case2", () =>
it("execute test case2", () =>
{
const sound = new Sound();

Expand Down
4 changes: 2 additions & 2 deletions packages/media/src/Sound/SoundProgressEventService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { execute } from "./SoundProgressEventService";
import { ProgressEvent as Next2DProgressEvent } from "@next2d/events";
import { describe, expect, it, vi } from "vitest";

describe("SoundProgressEventService.js namespace test", () =>
describe("SoundProgressEventService.js test", () =>
{
it("namespace progress event test case1", () =>
it("execute test case1", () =>
{
const sound = new Sound();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { $getSounds, $getVideos } from "../MediaUtil";
import { execute } from "./SoundMixerStopAllService";
import { describe, expect, it, vi } from "vitest";

describe("SoundMixerStopAllService.js namespace test", () =>
describe("SoundMixerStopAllService.js test", () =>
{
it("namespace test case1", () =>
it("execute test case1", () =>
{
let soundState = "";
const MockSound = vi.fn().mockImplementation(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { $getSounds, $getVideos } from "../MediaUtil";
import { execute } from "./SoundMixerUpdateVolumeService";
import { describe, expect, it, vi } from "vitest";

describe("SoundMixerUpdateVolumeService.js namespace test", () =>
describe("SoundMixerUpdateVolumeService.js test", () =>
{
it("namespace test case1", () =>
it("execute test case1", () =>
{
const MockSound = vi.fn().mockImplementation(() =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Event } from "@next2d/events";
import { execute } from "./VideoCanplaythroughEventService";
import { describe, expect, it, vi } from "vitest";

describe("SoundMixerUpdateVolumeService.js namespace test", () =>
describe("VideoCanplaythroughEventService.js test", () =>
{
it("namespace test case1", async () =>
it("execute test case1", async () =>
{
let playState = "stop";
let eventState = "";
Expand Down Expand Up @@ -46,7 +46,7 @@ describe("SoundMixerUpdateVolumeService.js namespace test", () =>
expect(state).toBe("changed");
});

it("namespace test case2", async () =>
it("execute test case2", async () =>
{
let eventState = "";
let state = "";
Expand Down
27 changes: 27 additions & 0 deletions packages/media/src/Video/VideoCreateElementService.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { Video } from "../Video";
import { Event } from "@next2d/events";
import { execute } from "./VideoCreateElementService";
import { describe, expect, it, vi } from "vitest";

describe("VideoCreateElementService.js test", () =>
{
it("execute test case1", () =>
{
const MockVideo = vi.fn().mockImplementation(() =>
{
return {} as unknown as Video;
});

const bounds = {
"xMin": 0,
"yMin": 0,
"xMax": 0,
"yMax": 0
};
const element = execute(new MockVideo(), bounds);

expect(element.autoplay).toBe(false);
expect(element.crossOrigin).toBe("anonymous");
expect(element.getAttribute("playsinline")).toBe("");
});
});
1 change: 1 addition & 0 deletions packages/media/src/Video/VideoCreateElementService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { execute as videoEndedEventService } from "./VideoEndedEventService";
* Create an HTMLVideoElement and set various events
*
* @param {Video} video
* @param {object} bounds
* @return {HTMLVideoElement}
* @method
* @protected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Video } from "../Video";
* @description Videoオブジェクトの幅と高さを更新する
* Update the width and height of the Video object
*
* @param {Video} video
* @param {HTMLVideoElement} element
* @param {object} bounds
* @return {void}
Expand Down
8 changes: 4 additions & 4 deletions packages/ui/src/Job/JobEntriesService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type { EntriesObjectImpl } from "../interface/EntriesObjectImpl";
import { execute } from "./JobEntriesService";
import { describe, expect, it } from "vitest";

describe("JobEntriesService.js method test", () =>
describe("JobEntriesService.js test", () =>
{
it("test case1", () =>
it("execute test case1", () =>
{
const entries = execute({ "x": 100, "y": 200 });
expect(entries.length).toBe(2);
Expand All @@ -14,7 +14,7 @@ describe("JobEntriesService.js method test", () =>
expect(entries[1].value).toBe(200);
});

it("test case2", () =>
it("execute test case2", () =>
{
const entries = execute({
"x": 100,
Expand All @@ -38,7 +38,7 @@ describe("JobEntriesService.js method test", () =>
expect(matrix[1].value).toBe(2);
});

it("test case2", () =>
it("execute test case3", () =>
{
const entries = execute({
"x": 100,
Expand Down
10 changes: 5 additions & 5 deletions packages/ui/src/Job/JobUpdateFrameService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ export const execute = (job: Job, timestamp: number): number =>
job.entries as EntriesObjectImpl[]
);

// update event
if (job.hasEventListener(Event.UPDATE)) {
job.dispatchEvent(new Event(Event.UPDATE));
}

// complete logic
if (job.currentTime >= job.duration) {

Expand All @@ -45,11 +50,6 @@ export const execute = (job: Job, timestamp: number): number =>
return -1;
}

// update event
if (job.hasEventListener(Event.UPDATE)) {
job.dispatchEvent(new Event(Event.UPDATE));
}

return requestAnimationFrame((timestamp: number): void =>
{
execute(job, timestamp);
Expand Down
Loading

0 comments on commit cdeca53

Please sign in to comment.