@vnejs/plugins.time.time 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -2
- package/dist/modules/time.d.ts +1 -1
- package/dist/modules/time.js +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -2
- package/src/modules/time.ts +1 -1
- package/src/tests/time.test.ts +14 -14
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "@vnejs/contracts.time.time";
|
|
2
2
|
import { regPlugin } from "@vnejs/shared";
|
|
3
3
|
import { CONSTANTS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.time.time";
|
|
4
|
-
import {
|
|
5
|
-
regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS }, [
|
|
4
|
+
import { Time } from "./modules/time.js";
|
|
5
|
+
regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS }, [Time]);
|
package/dist/modules/time.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ModuleCore } from "@vnejs/module.core";
|
|
|
2
2
|
import type { LineExecHandlerArg } from "@vnejs/module.core";
|
|
3
3
|
import type { TimePluginConstants, TimePluginEvents, TimePluginParams, TimePluginSettings } from "../types.js";
|
|
4
4
|
import type { TimeState, TimeValuePayload } from "../utils/time.js";
|
|
5
|
-
export declare class
|
|
5
|
+
export declare class Time extends ModuleCore<TimePluginEvents, TimePluginConstants, TimePluginSettings, TimePluginParams, TimeState> {
|
|
6
6
|
name: string;
|
|
7
7
|
subscribe: () => void;
|
|
8
8
|
init: () => Promise<unknown[]> | undefined;
|
package/dist/modules/time.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ModuleCore } from "@vnejs/module.core";
|
|
2
2
|
import { tokenizeExecLine } from "@vnejs/helpers";
|
|
3
|
-
export class
|
|
3
|
+
export class Time extends ModuleCore {
|
|
4
4
|
name = "time";
|
|
5
5
|
subscribe = () => {
|
|
6
6
|
this.on(this.EVENTS.TIME.SET, this.onTimeSet);
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -3,6 +3,6 @@ import "@vnejs/contracts.time.time";
|
|
|
3
3
|
import { regPlugin } from "@vnejs/shared";
|
|
4
4
|
import { CONSTANTS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.time.time";
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { Time } from "./modules/time.js";
|
|
7
7
|
|
|
8
|
-
regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS }, [
|
|
8
|
+
regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS }, [Time]);
|
package/src/modules/time.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { LineExecHandlerArg } from "@vnejs/module.core";
|
|
|
6
6
|
import type { TimePluginConstants, TimePluginEvents, TimePluginParams, TimePluginSettings } from "../types.js";
|
|
7
7
|
import type { TimeState, TimeValuePayload } from "../utils/time.js";
|
|
8
8
|
|
|
9
|
-
export class
|
|
9
|
+
export class Time extends ModuleCore<TimePluginEvents, TimePluginConstants, TimePluginSettings, TimePluginParams, TimeState> {
|
|
10
10
|
name = "time";
|
|
11
11
|
|
|
12
12
|
subscribe = () => {
|
package/src/tests/time.test.ts
CHANGED
|
@@ -3,54 +3,54 @@ import { beforeEach, describe, expect, it } from "vitest";
|
|
|
3
3
|
import { SUBSCRIBE_EVENTS as SCENARIO_EVENTS } from "@vnejs/contracts.core.scenario";
|
|
4
4
|
import { spyEvent } from "@vnejs/test-utils";
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { Time } from "../modules/time.js";
|
|
7
7
|
import { CONSTANTS, createTimeTestModule, registerTimePluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
8
|
|
|
9
|
-
describe("
|
|
9
|
+
describe("Time", () => {
|
|
10
10
|
beforeEach(() => {
|
|
11
11
|
registerTimePluginVne();
|
|
12
12
|
});
|
|
13
13
|
|
|
14
14
|
it("SET replaces time state and emits CHANGED", async () => {
|
|
15
|
-
const { module, observer } = createTimeTestModule(
|
|
15
|
+
const { module, observer } = createTimeTestModule(Time);
|
|
16
16
|
const changed = spyEvent(observer, SUBSCRIBE_EVENTS.CHANGED);
|
|
17
17
|
|
|
18
18
|
await observer.emit(SUBSCRIBE_EVENTS.SET, { hours: 10, minutes: 30, seconds: 15 });
|
|
19
19
|
|
|
20
|
-
expect((module as
|
|
20
|
+
expect((module as Time).state).toEqual({ hours: 10, minutes: 30, seconds: 15 });
|
|
21
21
|
expect(changed).toHaveBeenCalledOnce();
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
it("ADD carries seconds and minutes", async () => {
|
|
25
|
-
const { module, observer } = createTimeTestModule(
|
|
25
|
+
const { module, observer } = createTimeTestModule(Time);
|
|
26
26
|
|
|
27
|
-
(module as
|
|
27
|
+
(module as Time).setState({ hours: 1, minutes: 59, seconds: 50 });
|
|
28
28
|
|
|
29
29
|
await observer.emit(SUBSCRIBE_EVENTS.ADD, { hours: 0, minutes: 0, seconds: 20 });
|
|
30
30
|
|
|
31
|
-
expect((module as
|
|
31
|
+
expect((module as Time).state).toEqual({ hours: 2, minutes: 0, seconds: 10 });
|
|
32
32
|
});
|
|
33
33
|
|
|
34
34
|
it("ADD emits ROLLOVER when hours reach 24", async () => {
|
|
35
|
-
const { module, observer } = createTimeTestModule(
|
|
35
|
+
const { module, observer } = createTimeTestModule(Time);
|
|
36
36
|
const rollover = spyEvent(observer, SUBSCRIBE_EVENTS.ROLLOVER);
|
|
37
37
|
|
|
38
|
-
(module as
|
|
38
|
+
(module as Time).setState({ hours: 23, minutes: 0, seconds: 0 });
|
|
39
39
|
|
|
40
40
|
await observer.emit(SUBSCRIBE_EVENTS.ADD, { hours: 2, minutes: 0, seconds: 0 });
|
|
41
41
|
|
|
42
42
|
expect(rollover).toHaveBeenCalledExactlyOnceWith({ count: 1 });
|
|
43
|
-
expect((module as
|
|
43
|
+
expect((module as Time).state.hours).toBe(1);
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
it("onLineExec routes set action and emits NEXT", async () => {
|
|
47
|
-
const { module, observer } = createTimeTestModule(
|
|
47
|
+
const { module, observer } = createTimeTestModule(Time);
|
|
48
48
|
const next = spyEvent(observer, SCENARIO_EVENTS.NEXT);
|
|
49
49
|
|
|
50
|
-
await (module as
|
|
51
|
-
await (module as
|
|
50
|
+
await (module as Time).init();
|
|
51
|
+
await (module as Time).onLineExec({ line: `${CONSTANTS.ACTIONS.SET} 5 10 0` });
|
|
52
52
|
|
|
53
|
-
expect((module as
|
|
53
|
+
expect((module as Time).state).toEqual({ hours: 5, minutes: 10, seconds: 0 });
|
|
54
54
|
expect(next).toHaveBeenCalledOnce();
|
|
55
55
|
});
|
|
56
56
|
});
|