@plentymarkets/shop-core 1.3.2 → 1.3.4

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/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "shop-core",
3
3
  "configKey": "shopCore",
4
- "version": "1.3.2",
4
+ "version": "1.3.4",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "2.0.0"
@@ -0,0 +1,117 @@
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
+ import { useNotification } from "../useNotification.js";
3
+ describe("useNotification", () => {
4
+ afterEach(() => {
5
+ const { clear } = useNotification();
6
+ clear();
7
+ });
8
+ it("should return the correct initial state", () => {
9
+ const { data, send } = useNotification();
10
+ expect(data.value).toEqual([]);
11
+ expect(send).toBeInstanceOf(Function);
12
+ });
13
+ it("should add a notification", () => {
14
+ const { data, send } = useNotification();
15
+ send({
16
+ message: "Test alert error with a longer message",
17
+ type: "negative",
18
+ persist: true
19
+ });
20
+ expect(data.value.length).toBe(1);
21
+ });
22
+ it("should remove a notification", () => {
23
+ const { data, send } = useNotification();
24
+ send({
25
+ message: "Test alert error with a longer message",
26
+ type: "negative"
27
+ });
28
+ expect(data.value.length).toBe(1);
29
+ if (data.value[0].dismiss) {
30
+ data.value[0].dismiss();
31
+ }
32
+ expect(data.value.length).toBe(0);
33
+ });
34
+ it("should clear all notifications", () => {
35
+ const { data, send, clear } = useNotification();
36
+ for (let i = 0; i < 5; i++) {
37
+ send({
38
+ message: "Test alert error with a longer message",
39
+ type: "negative"
40
+ });
41
+ }
42
+ expect(data.value.length).toBe(5);
43
+ clear();
44
+ expect(data.value.length).toBe(0);
45
+ });
46
+ it("should remove the oldest notification when the maximum number of notifications is reached", async () => {
47
+ const { data, send } = useNotification();
48
+ for (let i = 0; i < 6; i++) {
49
+ send({
50
+ message: `Message ${i}`,
51
+ type: "positive"
52
+ });
53
+ }
54
+ expect(data.value[0].message).toBe("Message 1");
55
+ expect(data.value.length).toBe(5);
56
+ });
57
+ it("should remove a notification after default timeout (5000ms)", async () => {
58
+ const { data, send } = useNotification();
59
+ send({
60
+ message: "Test positive message",
61
+ type: "positive"
62
+ });
63
+ expect(data.value.length).toBe(1);
64
+ await new Promise((resolve) => {
65
+ setTimeout(resolve, 4e3);
66
+ });
67
+ expect(data.value.length).toBe(1);
68
+ await new Promise((resolve) => {
69
+ setTimeout(resolve, 1100);
70
+ });
71
+ expect(data.value.length).toBe(0);
72
+ });
73
+ it("should not remove a negative notification after 10ms", async () => {
74
+ const { data, send } = useNotification();
75
+ send({
76
+ message: "Test negative message",
77
+ type: "negative",
78
+ dismissTimeout: 10
79
+ });
80
+ expect(data.value.length).toBe(1);
81
+ await new Promise((resolve) => {
82
+ setTimeout(resolve, 10);
83
+ });
84
+ expect(data.value.length).toBe(1);
85
+ });
86
+ it("should not remove a persist notification after 10ms", async () => {
87
+ const { data, send } = useNotification();
88
+ send({
89
+ message: "Test persist message",
90
+ type: "positive",
91
+ persist: true,
92
+ dismissTimeout: 10
93
+ });
94
+ expect(data.value.length).toBe(1);
95
+ await new Promise((resolve) => {
96
+ setTimeout(resolve, 10);
97
+ });
98
+ expect(data.value.length).toBe(1);
99
+ });
100
+ it("should call the action function of a notification", () => {
101
+ const { data, send } = useNotification();
102
+ const action = vi.fn();
103
+ send({
104
+ message: "Test alert error with a longer message",
105
+ type: "negative",
106
+ persist: true,
107
+ action: {
108
+ text: "action",
109
+ onClick: action
110
+ }
111
+ });
112
+ if (data.value[0].action) {
113
+ data.value[0].action.onClick();
114
+ }
115
+ expect(action).toHaveBeenCalled();
116
+ });
117
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plentymarkets/shop-core",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "Core module for PlentyONE Shop",
5
5
  "repository": {
6
6
  "type": "git",
@@ -42,7 +42,7 @@
42
42
  "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit"
43
43
  },
44
44
  "dependencies": {
45
- "@plentymarkets/shop-api": "^0.95.0",
45
+ "@plentymarkets/shop-api": "^0.98.0",
46
46
  "@vue-storefront/sdk": "^3.4.1",
47
47
  "mitt": "^3.0.1"
48
48
  },