@cdevhub/ngx-chat 1.0.6

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 ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@cdevhub/ngx-chat",
3
+ "version": "1.0.6",
4
+ "description": "A pure presentational Angular 21 library for building chat interfaces",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/avs2001/ngx-chat.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/avs2001/ngx-chat/issues"
14
+ },
15
+ "homepage": "https://github.com/avs2001/ngx-chat#readme",
16
+ "peerDependencies": {
17
+ "@angular/animations": "^21.0.0",
18
+ "@angular/cdk": "^21.0.0",
19
+ "@angular/common": "^21.0.0",
20
+ "@angular/core": "^21.0.0"
21
+ },
22
+ "dependencies": {
23
+ "ngx-scrollbar": "^15.0.0",
24
+ "tslib": "^2.3.0"
25
+ },
26
+ "optionalDependencies": {
27
+ "marked": "^15.0.0",
28
+ "dompurify": "^3.2.0",
29
+ "highlight.js": "^11.10.0"
30
+ },
31
+ "sideEffects": false,
32
+ "keywords": [
33
+ "angular",
34
+ "chat",
35
+ "component",
36
+ "messaging",
37
+ "ui"
38
+ ],
39
+ "license": "MIT",
40
+ "module": "fesm2022/cdevhub-ngx-chat.mjs",
41
+ "typings": "types/cdevhub-ngx-chat.d.ts",
42
+ "exports": {
43
+ "./package.json": {
44
+ "default": "./package.json"
45
+ },
46
+ ".": {
47
+ "types": "./types/cdevhub-ngx-chat.d.ts",
48
+ "default": "./fesm2022/cdevhub-ngx-chat.mjs"
49
+ },
50
+ "./testing": {
51
+ "types": "./types/cdevhub-ngx-chat-testing.d.ts",
52
+ "default": "./fesm2022/cdevhub-ngx-chat-testing.mjs"
53
+ }
54
+ }
55
+ }
@@ -0,0 +1,362 @@
1
+ import { ComponentHarness, BaseHarnessFilters, HarnessPredicate } from '@angular/cdk/testing';
2
+ import { ChatMessage, ConfirmAction, SelectAction, MultiSelectAction, ButtonsAction, MessageAttachment, ChatMessageError } from '@cdevhub/ngx-chat';
3
+
4
+ /**
5
+ * @fileoverview Test harness for ChatComponent.
6
+ * Provides ergonomic methods for testing chat interactions.
7
+ * @module ngx-chat/testing
8
+ */
9
+
10
+ /**
11
+ * Filter criteria for ChatHarness.
12
+ */
13
+ interface ChatHarnessFilters extends BaseHarnessFilters {
14
+ /** Filters by disabled state. */
15
+ disabled?: boolean;
16
+ }
17
+ /**
18
+ * Message data returned from getMessages().
19
+ */
20
+ interface ChatMessageData {
21
+ /** Message text content. */
22
+ content: string;
23
+ /** Sender type: 'self', 'other', or 'system'. */
24
+ sender: 'self' | 'other' | 'system';
25
+ /** Sender name if available. */
26
+ senderName?: string;
27
+ }
28
+ /**
29
+ * Test harness for ChatComponent.
30
+ *
31
+ * Provides methods for:
32
+ * - Sending messages
33
+ * - Typing in the input
34
+ * - Querying message state
35
+ * - Checking component state
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const harness = await loader.getHarness(ChatHarness);
40
+ * await harness.typeMessage('Hello');
41
+ * await harness.sendMessage('Hello');
42
+ * const count = await harness.getMessageCount();
43
+ * ```
44
+ */
45
+ declare class ChatHarness extends ComponentHarness {
46
+ static hostSelector: string;
47
+ private readonly _textarea;
48
+ private readonly _sendButton;
49
+ private readonly _messagesList;
50
+ private readonly _messages;
51
+ private readonly _messageTexts;
52
+ private readonly _typingIndicator;
53
+ private readonly _loadingIndicator;
54
+ private readonly _emptyState;
55
+ /**
56
+ * Gets a `HarnessPredicate` that can be used to search for a chat harness
57
+ * that meets certain criteria.
58
+ * @param options Options for filtering which chat instances are considered a match.
59
+ * @returns A predicate for finding matching chat harnesses.
60
+ */
61
+ static with(options?: ChatHarnessFilters): HarnessPredicate<ChatHarness>;
62
+ /**
63
+ * Types a message and sends it.
64
+ * Combines typeMessage and clicking send button.
65
+ * @param content The message content to send.
66
+ */
67
+ sendMessage(content: string): Promise<void>;
68
+ /**
69
+ * Types content into the message input.
70
+ * Clears existing content first.
71
+ * @param content The content to type.
72
+ */
73
+ typeMessage(content: string): Promise<void>;
74
+ /**
75
+ * Clears the message input.
76
+ */
77
+ clearInput(): Promise<void>;
78
+ /**
79
+ * Focuses the message input.
80
+ */
81
+ focusInput(): Promise<void>;
82
+ /**
83
+ * Blurs the message input.
84
+ */
85
+ blurInput(): Promise<void>;
86
+ /**
87
+ * Gets the number of messages displayed.
88
+ * @returns The message count.
89
+ */
90
+ getMessageCount(): Promise<number>;
91
+ /**
92
+ * Gets all messages with their content and sender info.
93
+ * @returns Array of message data.
94
+ */
95
+ getMessages(): Promise<ChatMessageData[]>;
96
+ /**
97
+ * Gets the content of the last message.
98
+ * @returns The last message content, or null if no messages.
99
+ */
100
+ getLastMessageContent(): Promise<string | null>;
101
+ /**
102
+ * Gets the current value of the message input.
103
+ * @returns The input value.
104
+ */
105
+ getInputValue(): Promise<string>;
106
+ /**
107
+ * Checks if the chat is disabled.
108
+ * @returns True if disabled.
109
+ */
110
+ isDisabled(): Promise<boolean>;
111
+ /**
112
+ * Checks if the send button is enabled (can send a message).
113
+ * @returns True if can send.
114
+ */
115
+ canSend(): Promise<boolean>;
116
+ /**
117
+ * Checks if the typing indicator is visible.
118
+ * @returns True if typing indicator is shown.
119
+ */
120
+ isTypingIndicatorVisible(): Promise<boolean>;
121
+ /**
122
+ * Checks if the loading indicator is visible.
123
+ * @returns True if loading.
124
+ */
125
+ isLoading(): Promise<boolean>;
126
+ /**
127
+ * Checks if the empty state is visible.
128
+ * @returns True if showing empty state.
129
+ */
130
+ isEmpty(): Promise<boolean>;
131
+ /**
132
+ * Checks if any messages are displayed.
133
+ * @returns True if messages are visible.
134
+ */
135
+ hasMessages(): Promise<boolean>;
136
+ /**
137
+ * Gets the placeholder text of the input.
138
+ * @returns The placeholder text.
139
+ */
140
+ getPlaceholder(): Promise<string>;
141
+ /**
142
+ * Checks if the input has focus.
143
+ * @returns True if input is focused.
144
+ */
145
+ isInputFocused(): Promise<boolean>;
146
+ }
147
+
148
+ /**
149
+ * @fileoverview Mock data and test scenarios for ngx-chat testing.
150
+ * Provides pre-built scenarios and generator functions for comprehensive testing.
151
+ * @module ngx-chat/testing
152
+ */
153
+
154
+ /**
155
+ * Sample confirm action for testing.
156
+ */
157
+ declare const SAMPLE_CONFIRM_ACTION: ConfirmAction;
158
+ /**
159
+ * Sample select action for testing.
160
+ */
161
+ declare const SAMPLE_SELECT_ACTION: SelectAction;
162
+ /**
163
+ * Sample multi-select action for testing.
164
+ */
165
+ declare const SAMPLE_MULTI_SELECT_ACTION: MultiSelectAction;
166
+ /**
167
+ * Sample buttons action for testing.
168
+ */
169
+ declare const SAMPLE_BUTTONS_ACTION: ButtonsAction;
170
+ /**
171
+ * Sample image attachment.
172
+ */
173
+ declare const SAMPLE_IMAGE_ATTACHMENT: MessageAttachment;
174
+ /**
175
+ * Sample file attachment.
176
+ */
177
+ declare const SAMPLE_FILE_ATTACHMENT: MessageAttachment;
178
+ /**
179
+ * Sample video attachment.
180
+ */
181
+ declare const SAMPLE_VIDEO_ATTACHMENT: MessageAttachment;
182
+ /**
183
+ * Sample audio attachment.
184
+ */
185
+ declare const SAMPLE_AUDIO_ATTACHMENT: MessageAttachment;
186
+ /**
187
+ * Sample network error.
188
+ */
189
+ declare const SAMPLE_NETWORK_ERROR: ChatMessageError;
190
+ /**
191
+ * Sample timeout error.
192
+ */
193
+ declare const SAMPLE_TIMEOUT_ERROR: ChatMessageError;
194
+ /**
195
+ * Sample rate limit error.
196
+ */
197
+ declare const SAMPLE_RATE_LIMIT_ERROR: ChatMessageError;
198
+ /**
199
+ * Pre-built test scenarios for common testing needs.
200
+ * Each scenario provides a complete, valid ChatMessage[] array.
201
+ *
202
+ * @example
203
+ * ```typescript
204
+ * // In a test
205
+ * const messages = MOCK_SCENARIOS.simpleConversation;
206
+ * fixture.componentRef.setInput('messages', messages);
207
+ * ```
208
+ */
209
+ declare const MOCK_SCENARIOS: {
210
+ /**
211
+ * Empty message list for testing empty states.
212
+ */
213
+ readonly empty: readonly ChatMessage[];
214
+ /**
215
+ * Single message from self.
216
+ */
217
+ readonly singleMessage: readonly ChatMessage[];
218
+ /**
219
+ * Simple back-and-forth conversation.
220
+ */
221
+ readonly simpleConversation: readonly ChatMessage[];
222
+ /**
223
+ * Messages with various actions attached.
224
+ */
225
+ readonly withActions: readonly ChatMessage[];
226
+ /**
227
+ * Message with multi-select action.
228
+ */
229
+ readonly withMultiSelect: readonly ChatMessage[];
230
+ /**
231
+ * Message with buttons action.
232
+ */
233
+ readonly withButtons: readonly ChatMessage[];
234
+ /**
235
+ * Messages with error states.
236
+ */
237
+ readonly withErrors: readonly ChatMessage[];
238
+ /**
239
+ * Messages with file attachments.
240
+ */
241
+ readonly withAttachments: readonly ChatMessage[];
242
+ /**
243
+ * Long conversation with 100 messages for scroll testing.
244
+ */
245
+ readonly longConversation: readonly ChatMessage[];
246
+ /**
247
+ * Large dataset with 1000 messages for performance testing.
248
+ */
249
+ readonly performanceTest: readonly ChatMessage[];
250
+ /**
251
+ * RTL content for internationalization testing.
252
+ */
253
+ readonly rtlContent: readonly ChatMessage[];
254
+ /**
255
+ * Mixed content with markdown, code, and special characters.
256
+ */
257
+ readonly mixedContent: readonly ChatMessage[];
258
+ /**
259
+ * System messages for notifications and status updates.
260
+ */
261
+ readonly systemMessages: readonly ChatMessage[];
262
+ };
263
+ /**
264
+ * Generates a conversation with alternating self/other messages.
265
+ *
266
+ * @param count - Number of messages to generate
267
+ * @returns Array of ChatMessage objects
268
+ *
269
+ * @example
270
+ * ```typescript
271
+ * const messages = generateConversation(50);
272
+ * expect(messages.length).toBe(50);
273
+ * ```
274
+ */
275
+ declare function generateConversation(count: number): readonly ChatMessage[];
276
+ /**
277
+ * Generates messages with various action types attached.
278
+ *
279
+ * @param count - Number of messages to generate (each will have an action)
280
+ * @returns Array of ChatMessage objects with actions
281
+ *
282
+ * @example
283
+ * ```typescript
284
+ * const messages = generateWithActions(10);
285
+ * expect(messages.every(m => m.actions?.length)).toBe(true);
286
+ * ```
287
+ */
288
+ declare function generateWithActions(count: number): readonly ChatMessage[];
289
+ /**
290
+ * Generates messages with various attachment types.
291
+ *
292
+ * @param count - Number of messages to generate
293
+ * @returns Array of ChatMessage objects with attachments
294
+ */
295
+ declare function generateWithAttachments(count: number): readonly ChatMessage[];
296
+ /**
297
+ * Default timeout for wait operations in milliseconds.
298
+ */
299
+ declare const DEFAULT_WAIT_TIMEOUT = 5000;
300
+ /**
301
+ * Default polling interval for wait operations in milliseconds.
302
+ */
303
+ declare const DEFAULT_POLL_INTERVAL = 50;
304
+ /**
305
+ * Waits for the chat harness to display a specific number of messages.
306
+ *
307
+ * @param harness - The ChatHarness instance
308
+ * @param count - Expected number of messages
309
+ * @param timeout - Maximum wait time in milliseconds (default: 5000)
310
+ * @returns Promise that resolves when count is reached or rejects on timeout
311
+ *
312
+ * @example
313
+ * ```typescript
314
+ * const harness = await loader.getHarness(ChatHarness);
315
+ * fixture.componentRef.setInput('messages', generateConversation(5));
316
+ * await waitForMessages(harness, 5);
317
+ * ```
318
+ */
319
+ declare function waitForMessages(harness: ChatHarness, count: number, timeout?: number): Promise<void>;
320
+ /**
321
+ * Waits for the typing indicator to reach a specific visibility state.
322
+ *
323
+ * @param harness - The ChatHarness instance
324
+ * @param visible - Expected visibility state (true = visible, false = hidden)
325
+ * @param timeout - Maximum wait time in milliseconds (default: 5000)
326
+ * @returns Promise that resolves when state is reached or rejects on timeout
327
+ *
328
+ * @example
329
+ * ```typescript
330
+ * const harness = await loader.getHarness(ChatHarness);
331
+ * fixture.componentRef.setInput('isTyping', true);
332
+ * await waitForTypingIndicator(harness, true);
333
+ * ```
334
+ */
335
+ declare function waitForTypingIndicator(harness: ChatHarness, visible: boolean, timeout?: number): Promise<void>;
336
+ /**
337
+ * Waits for the loading indicator to reach a specific visibility state.
338
+ *
339
+ * @param harness - The ChatHarness instance
340
+ * @param visible - Expected visibility state
341
+ * @param timeout - Maximum wait time in milliseconds (default: 5000)
342
+ */
343
+ declare function waitForLoading(harness: ChatHarness, visible: boolean, timeout?: number): Promise<void>;
344
+ /**
345
+ * Waits for the empty state to reach a specific visibility state.
346
+ *
347
+ * @param harness - The ChatHarness instance
348
+ * @param visible - Expected visibility state
349
+ * @param timeout - Maximum wait time in milliseconds (default: 5000)
350
+ */
351
+ declare function waitForEmpty(harness: ChatHarness, visible: boolean, timeout?: number): Promise<void>;
352
+ /**
353
+ * Waits for the send button to become enabled or disabled.
354
+ *
355
+ * @param harness - The ChatHarness instance
356
+ * @param enabled - Expected enabled state
357
+ * @param timeout - Maximum wait time in milliseconds (default: 5000)
358
+ */
359
+ declare function waitForSendEnabled(harness: ChatHarness, enabled: boolean, timeout?: number): Promise<void>;
360
+
361
+ export { ChatHarness, DEFAULT_POLL_INTERVAL, DEFAULT_WAIT_TIMEOUT, MOCK_SCENARIOS, SAMPLE_AUDIO_ATTACHMENT, SAMPLE_BUTTONS_ACTION, SAMPLE_CONFIRM_ACTION, SAMPLE_FILE_ATTACHMENT, SAMPLE_IMAGE_ATTACHMENT, SAMPLE_MULTI_SELECT_ACTION, SAMPLE_NETWORK_ERROR, SAMPLE_RATE_LIMIT_ERROR, SAMPLE_SELECT_ACTION, SAMPLE_TIMEOUT_ERROR, SAMPLE_VIDEO_ATTACHMENT, generateConversation, generateWithActions, generateWithAttachments, waitForEmpty, waitForLoading, waitForMessages, waitForSendEnabled, waitForTypingIndicator };
362
+ export type { ChatHarnessFilters, ChatMessageData };