Skip to content

Commit 0221af8

Browse files
committed
chore: add unit tests for isComposing
1 parent fd95fc4 commit 0221af8

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

projects/stream-chat-angular/src/lib/message-input/autocomplete-textarea/autocomplete-textarea.component.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ describe('AutocompleteTextareaComponent', () => {
125125
expect(event.preventDefault).toHaveBeenCalledWith();
126126
});
127127

128+
it(`should emit #send if enter is hit and #inputMode is desktop, but isComposing is true`, () => {
129+
const spy = jasmine.createSpy();
130+
component.send.subscribe(spy);
131+
const textarea = queryTextarea();
132+
const message = 'This is my message';
133+
textarea!.value = message;
134+
const event = new KeyboardEvent('keydown', {
135+
key: 'Enter',
136+
isComposing: true,
137+
});
138+
spyOn(event, 'preventDefault');
139+
textarea?.dispatchEvent(event);
140+
fixture.detectChanges();
141+
142+
expect(spy).not.toHaveBeenCalledWith();
143+
expect(event.preventDefault).not.toHaveBeenCalledWith();
144+
});
145+
128146
it(`shouldn't emit #send if enter is hit and #inputMode is mobile`, () => {
129147
component.inputMode = 'mobile';
130148
const spy = jasmine.createSpy();

projects/stream-chat-angular/src/lib/message-input/textarea/textarea.component.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,20 @@ describe('TextareaComponent', () => {
166166

167167
expect(height).toBeGreaterThan(0);
168168
});
169+
170+
it(`shouldn't emit #send if enter is hit and #inputMode is mobile`, () => {
171+
component.inputMode = 'mobile';
172+
const spy = jasmine.createSpy();
173+
component.send.subscribe(spy);
174+
const textarea = queryTextarea();
175+
const message = 'This is my message';
176+
textarea!.value = message;
177+
const event = new KeyboardEvent('keydown', { key: 'Enter' });
178+
spyOn(event, 'preventDefault');
179+
textarea?.dispatchEvent(event);
180+
fixture.detectChanges();
181+
182+
expect(spy).not.toHaveBeenCalled();
183+
expect(event.preventDefault).not.toHaveBeenCalled();
184+
});
169185
});

0 commit comments

Comments
 (0)