@nlxai/touchpoint-ui 1.2.4-alpha.6 → 1.2.4-alpha.8

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/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ nodejs 20.19.6
package/README.md CHANGED
@@ -187,7 +187,7 @@ the context object
187
187
  ##### input?
188
188
 
189
189
  ```ts
190
- optional input: "text" | "voice" | "voiceMini";
190
+ optional input: "text" | "external" | "voice" | "voiceMini";
191
191
  ```
192
192
 
193
193
  Controls the ways in which the user can communicate with the application. Defaults to `"text"`
@@ -0,0 +1,123 @@
1
+ import { renderHook, act, waitFor } from "@testing-library/react";
2
+ import { useFeedback, getFeedbackInfo } from "../src/feedback";
3
+ import { vi, describe, it, expect, beforeEach } from "vitest";
4
+
5
+ // Mock ConversationHandler
6
+ const mockHandlerObj = {
7
+ submitFeedback: vi.fn(async () => Promise.resolve()),
8
+ };
9
+ const mockHandler =
10
+ mockHandlerObj as unknown as import("@nlxai/core").ConversationHandler;
11
+
12
+ describe("useFeedback", () => {
13
+ beforeEach(() => {
14
+ vi.clearAllMocks();
15
+ });
16
+
17
+ it("should initialize with default state", () => {
18
+ const { result } = renderHook(() => useFeedback(mockHandler));
19
+ const [state] = result.current;
20
+ expect(state.comment.state).toBe("idle");
21
+ expect(state.items).toEqual({});
22
+ });
23
+
24
+ it("should handle clickRating and update state", async () => {
25
+ const { result } = renderHook(() => useFeedback(mockHandler as any));
26
+ const [, actions] = result.current;
27
+ await act(async () => {
28
+ actions.clickRating("url1", 4);
29
+ });
30
+ const [state] = result.current;
31
+ expect(getFeedbackInfo(state as any, "url1").rating).toBe(4);
32
+ expect(mockHandler.submitFeedback).toHaveBeenCalledWith("url1", {
33
+ rating: 4,
34
+ });
35
+ });
36
+
37
+ it("should handle clickCommentButton and enter editing state", () => {
38
+ const { result } = renderHook(() => useFeedback(mockHandler));
39
+ const [, actions] = result.current;
40
+ act(() => {
41
+ actions.clickCommentButton("url2");
42
+ });
43
+ const [state] = result.current;
44
+ expect(state.comment.state).toBe("editing");
45
+ if (state.comment.state === "editing") {
46
+ expect(state.comment.activeFeedbackUrl).toBe("url2");
47
+ } else {
48
+ throw new Error("Expected comment state to be 'editing'");
49
+ }
50
+ });
51
+
52
+ it("should handle editCommentText and update text", () => {
53
+ const { result } = renderHook(() => useFeedback(mockHandler));
54
+ act(() => {
55
+ result.current[1].clickCommentButton("url3");
56
+ });
57
+ act(() => {
58
+ result.current[1].editCommentText("Test comment");
59
+ });
60
+ const [state] = result.current;
61
+ if (state.comment.state !== "editing") throw new Error();
62
+ expect(state.comment.text).toBe("Test comment");
63
+ });
64
+
65
+ it("should handle submitComment and update state on success", async () => {
66
+ const { result } = renderHook(() => useFeedback(mockHandler));
67
+ act(() => {
68
+ result.current[1].clickCommentButton("url4");
69
+ });
70
+ act(() => {
71
+ result.current[1].editCommentText("My feedback");
72
+ });
73
+ await act(async () => {
74
+ await result.current[1].submitComment();
75
+ });
76
+ // Wait for the state to update to 'submitted'
77
+ await waitFor(() => {
78
+ const [state] = result.current;
79
+ expect(state.comment.state).toBe("idle");
80
+ });
81
+ const [state] = result.current;
82
+ expect(getFeedbackInfo(state as any, "url4").commentSubmitted).toBe(true);
83
+ expect(getFeedbackInfo(state as any, "url4").commentText).toBe(
84
+ "My feedback",
85
+ );
86
+ expect(mockHandler.submitFeedback).toHaveBeenCalledWith("url4", {
87
+ comment: "My feedback",
88
+ });
89
+ });
90
+
91
+ it("should handle cancelComment and return to idle", () => {
92
+ const { result } = renderHook(() => useFeedback(mockHandler));
93
+ const [, actions] = result.current;
94
+ act(() => {
95
+ actions.clickCommentButton("url5");
96
+ actions.cancelComment();
97
+ });
98
+ const [state] = result.current;
99
+ expect(state.comment.state).toBe("idle");
100
+ });
101
+
102
+ it("should handle submission error", async () => {
103
+ const errorHandlerObj = {
104
+ submitFeedback: vi.fn(async () => Promise.reject(new Error("fail"))),
105
+ };
106
+ const errorHandler =
107
+ errorHandlerObj as unknown as import("@nlxai/core").ConversationHandler;
108
+ const { result } = renderHook(() => useFeedback(errorHandler));
109
+
110
+ act(() => {
111
+ result.current[1].clickCommentButton("url6");
112
+ result.current[1].editCommentText("fail");
113
+ });
114
+ await act(async () => {
115
+ await result.current[1].submitComment();
116
+ });
117
+ // Wait for the state to update to 'error'
118
+ await waitFor(() => {
119
+ const [state] = result.current;
120
+ expect(state.comment.state).toBe("error");
121
+ });
122
+ });
123
+ });
package/index.html CHANGED
@@ -25,13 +25,17 @@
25
25
  const touchpoint = await create({
26
26
  config: {
27
27
  applicationUrl:
28
- "https://apps.nlx.ai/c/Xq3kT5uVOCGipRW8kW9pB/BajtUGSLN5hoqiSmgTA7B",
28
+ "https://bots.dev.studio.nlx.ai/c/Nji0Tkk8UOqaFc3Z3mDW9/5p7ZdO_XgcnCKnuxbhNAS",
29
+
29
30
  headers: {
30
- "nlx-api-key": "VkvGvxQ-iQQ/EgpgyJQxkDL-OhmhVwzV",
31
+ "nlx-api-key": "crLjtXvXIOPtc1AgnPHoEE1y",
31
32
  },
32
33
  languageCode: "en-US",
34
+ conversationId: "12345",
33
35
  },
34
36
  windowSize: "full",
37
+ input: "external",
38
+ bidirectional: {},
35
39
  // colorMode: "light dark",
36
40
  // userMessageBubble: true,
37
41
  // agentMessageBubble: true,
@@ -44,6 +48,16 @@
44
48
  // fontFamily: "'BW Haas Text Mono C 55 Rom Regular', monospace",
45
49
  // },
46
50
  });
51
+
52
+ touchpoint.setCustomBidirectionalCommands([
53
+ {
54
+ action: "externalInput",
55
+ // description: "Handle external input",
56
+ handler: (args) => {
57
+ alert(`External input received: ${args}`);
58
+ },
59
+ },
60
+ ]);
47
61
  </script>
48
62
  </body>
49
63
  </html>
package/lib/feedback.d.ts CHANGED
@@ -3,6 +3,7 @@ interface FeedbackInfo {
3
3
  rating: number | null;
4
4
  commentSubmitted: boolean;
5
5
  commentText: string;
6
+ pending: boolean;
6
7
  }
7
8
  export interface State {
8
9
  comment: CommentState;