@vnejs/plugins.time.time 0.1.19 → 0.1.20
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/package.json +5 -3
- package/src/tests/setup.ts +20 -0
- package/src/tests/time.test.ts +56 -0
- package/tsconfig.json +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.time.time",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"tsconfig.json"
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
|
-
"test": "
|
|
21
|
+
"test": "npx @vnejs/monorepo test",
|
|
22
22
|
"build": "npx @vnejs/monorepo package",
|
|
23
23
|
"publish:major:plugin": "npm run publish:major",
|
|
24
24
|
"publish:minor:plugin": "npm run publish:minor",
|
|
@@ -38,6 +38,8 @@
|
|
|
38
38
|
"@vnejs/shared": "~0.1.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@vnejs/configs.ts-common": "~0.1.0"
|
|
41
|
+
"@vnejs/configs.ts-common": "~0.1.0",
|
|
42
|
+
"@vnejs/configs.vitest": "~0.1.0",
|
|
43
|
+
"@vnejs/test-utils": "~0.1.0"
|
|
42
44
|
}
|
|
43
45
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CONSTANTS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.time.time";
|
|
2
|
+
import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin, stubSilentEvent } from "@vnejs/test-utils";
|
|
3
|
+
|
|
4
|
+
export const registerTimePluginVne = () => {
|
|
5
|
+
registerCoreVne();
|
|
6
|
+
registerVnePlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS });
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const createTimeTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
|
|
10
|
+
ModuleClass: T,
|
|
11
|
+
options: Parameters<typeof baseCreateTestModule>[1] = {},
|
|
12
|
+
) => {
|
|
13
|
+
const result = baseCreateTestModule(ModuleClass, options);
|
|
14
|
+
|
|
15
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.CHANGED);
|
|
16
|
+
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { SUBSCRIBE_EVENTS, CONSTANTS, PLUGIN_NAME };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { SUBSCRIBE_EVENTS as SCENARIO_EVENTS } from "@vnejs/contracts.core.scenario";
|
|
4
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
5
|
+
|
|
6
|
+
import { TimeModule } from "../modules/time.js";
|
|
7
|
+
import { CONSTANTS, createTimeTestModule, registerTimePluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("TimeModule", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerTimePluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("SET replaces time state and emits CHANGED", async () => {
|
|
15
|
+
const { module, observer } = createTimeTestModule(TimeModule);
|
|
16
|
+
const changed = spyEvent(observer, SUBSCRIBE_EVENTS.CHANGED);
|
|
17
|
+
|
|
18
|
+
await observer.emit(SUBSCRIBE_EVENTS.SET, { hours: 10, minutes: 30, seconds: 15 });
|
|
19
|
+
|
|
20
|
+
expect((module as TimeModule).state).toEqual({ hours: 10, minutes: 30, seconds: 15 });
|
|
21
|
+
expect(changed).toHaveBeenCalledOnce();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("ADD carries seconds and minutes", async () => {
|
|
25
|
+
const { module, observer } = createTimeTestModule(TimeModule);
|
|
26
|
+
|
|
27
|
+
(module as TimeModule).setState({ hours: 1, minutes: 59, seconds: 50 });
|
|
28
|
+
|
|
29
|
+
await observer.emit(SUBSCRIBE_EVENTS.ADD, { hours: 0, minutes: 0, seconds: 20 });
|
|
30
|
+
|
|
31
|
+
expect((module as TimeModule).state).toEqual({ hours: 2, minutes: 0, seconds: 10 });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("ADD emits ROLLOVER when hours reach 24", async () => {
|
|
35
|
+
const { module, observer } = createTimeTestModule(TimeModule);
|
|
36
|
+
const rollover = spyEvent(observer, SUBSCRIBE_EVENTS.ROLLOVER);
|
|
37
|
+
|
|
38
|
+
(module as TimeModule).setState({ hours: 23, minutes: 0, seconds: 0 });
|
|
39
|
+
|
|
40
|
+
await observer.emit(SUBSCRIBE_EVENTS.ADD, { hours: 2, minutes: 0, seconds: 0 });
|
|
41
|
+
|
|
42
|
+
expect(rollover).toHaveBeenCalledExactlyOnceWith({ count: 1 });
|
|
43
|
+
expect((module as TimeModule).state.hours).toBe(1);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("onLineExec routes set action and emits NEXT", async () => {
|
|
47
|
+
const { module, observer } = createTimeTestModule(TimeModule);
|
|
48
|
+
const next = spyEvent(observer, SCENARIO_EVENTS.NEXT);
|
|
49
|
+
|
|
50
|
+
await (module as TimeModule).init();
|
|
51
|
+
await (module as TimeModule).onLineExec({ line: `${CONSTANTS.ACTIONS.SET} 5 10 0` });
|
|
52
|
+
|
|
53
|
+
expect((module as TimeModule).state).toEqual({ hours: 5, minutes: 10, seconds: 0 });
|
|
54
|
+
expect(next).toHaveBeenCalledOnce();
|
|
55
|
+
});
|
|
56
|
+
});
|
package/tsconfig.json
CHANGED