@vnejs/plugins.scenario.autoread 0.1.12 → 0.2.0
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 +9 -7
- package/src/tests/autoread.test.ts +57 -0
- package/src/tests/setup.ts +26 -0
- package/tsconfig.json +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.scenario.autoread",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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",
|
|
@@ -30,14 +30,16 @@
|
|
|
30
30
|
"author": "",
|
|
31
31
|
"license": "ISC",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@vnejs/contracts.scenario.autoread": "~0.
|
|
33
|
+
"@vnejs/contracts.scenario.autoread": "~0.2.0"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@vnejs/module.core": "~0.
|
|
37
|
-
"@vnejs/shared": "~0.
|
|
38
|
-
"@vnejs/sources-set": "~0.
|
|
36
|
+
"@vnejs/module.core": "~0.2.0",
|
|
37
|
+
"@vnejs/shared": "~0.2.0",
|
|
38
|
+
"@vnejs/sources-set": "~0.2.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@vnejs/configs.ts-common": "~0.
|
|
41
|
+
"@vnejs/configs.ts-common": "~0.2.0",
|
|
42
|
+
"@vnejs/configs.vitest": "~0.2.0",
|
|
43
|
+
"@vnejs/test-utils": "~0.2.0"
|
|
42
44
|
}
|
|
43
45
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { SUBSCRIBE_EVENTS as INTERACT_EVENTS } from "@vnejs/contracts.core.interact";
|
|
4
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
5
|
+
|
|
6
|
+
import { Autoread } from "../modules/autoread.js";
|
|
7
|
+
import { createAutoreadTestModule, registerAutoreadPluginVne, SETTINGS_KEYS, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("Autoread", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerAutoreadPluginVne();
|
|
12
|
+
vi.useFakeTimers();
|
|
13
|
+
document.body.innerHTML = "";
|
|
14
|
+
document.elementsFromPoint = vi.fn(() => []);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("TRY does nothing when disabled", async () => {
|
|
18
|
+
const { observer, shared } = createAutoreadTestModule(Autoread);
|
|
19
|
+
const interact = spyEvent(observer, INTERACT_EVENTS.EMIT);
|
|
20
|
+
|
|
21
|
+
shared.settings![SETTINGS_KEYS.ENABLED] = false;
|
|
22
|
+
|
|
23
|
+
await observer.emit(SUBSCRIBE_EVENTS.TRY);
|
|
24
|
+
|
|
25
|
+
expect(interact).not.toHaveBeenCalled();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("TRY emits INTERACT when allow element is at center", async () => {
|
|
29
|
+
const { module, observer } = createAutoreadTestModule(Autoread);
|
|
30
|
+
const interact = spyEvent(observer, INTERACT_EVENTS.EMIT);
|
|
31
|
+
const allow = document.createElement("div");
|
|
32
|
+
|
|
33
|
+
allow.setAttribute("vne-autoread-allow", "");
|
|
34
|
+
document.body.appendChild(allow);
|
|
35
|
+
|
|
36
|
+
vi.spyOn(module as Autoread, "waitRerender").mockResolvedValue(undefined);
|
|
37
|
+
vi.spyOn(document, "elementsFromPoint").mockReturnValue([allow]);
|
|
38
|
+
|
|
39
|
+
await observer.emit(SUBSCRIBE_EVENTS.TRY);
|
|
40
|
+
|
|
41
|
+
expect(interact).toHaveBeenCalledOnce();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("PUSH disables autoread and POP restarts timeout", async () => {
|
|
45
|
+
const { observer } = createAutoreadTestModule(Autoread);
|
|
46
|
+
const trySpy = spyEvent(observer, SUBSCRIBE_EVENTS.TRY);
|
|
47
|
+
|
|
48
|
+
await observer.emit(SUBSCRIBE_EVENTS.PUSH, { source: "dialog" });
|
|
49
|
+
vi.runAllTimers();
|
|
50
|
+
expect(trySpy).not.toHaveBeenCalled();
|
|
51
|
+
|
|
52
|
+
await observer.emit(SUBSCRIBE_EVENTS.POP, { source: "dialog" });
|
|
53
|
+
vi.runAllTimers();
|
|
54
|
+
|
|
55
|
+
expect(trySpy).toHaveBeenCalled();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { PLUGIN_NAME, PARAMS, SETTINGS_KEYS, SUBSCRIBE_EVENTS } from "@vnejs/contracts.scenario.autoread";
|
|
2
|
+
import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin } from "@vnejs/test-utils";
|
|
3
|
+
import { SourcesSet } from "@vnejs/sources-set";
|
|
4
|
+
|
|
5
|
+
export const registerAutoreadPluginVne = () => {
|
|
6
|
+
registerCoreVne();
|
|
7
|
+
registerVnePlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, settings: SETTINGS_KEYS, params: PARAMS });
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const createAutoreadTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
|
|
11
|
+
ModuleClass: T,
|
|
12
|
+
options: Parameters<typeof baseCreateTestModule>[1] = {},
|
|
13
|
+
) =>
|
|
14
|
+
baseCreateTestModule(ModuleClass, {
|
|
15
|
+
shared: {
|
|
16
|
+
settings: {
|
|
17
|
+
[SETTINGS_KEYS.ENABLED]: true,
|
|
18
|
+
[SETTINGS_KEYS.DELAY]: PARAMS.DEFAULT_DELAY,
|
|
19
|
+
},
|
|
20
|
+
autoreadDisableSources: new SourcesSet(),
|
|
21
|
+
...(options.shared as Record<string, unknown>),
|
|
22
|
+
},
|
|
23
|
+
...options,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export { SUBSCRIBE_EVENTS, PARAMS, SETTINGS_KEYS, PLUGIN_NAME };
|
package/tsconfig.json
CHANGED