Skip to content

Commit

Permalink
chore: add unit tests for isComposing
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed Sep 5, 2024
1 parent fd95fc4 commit 0221af8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,24 @@ describe('AutocompleteTextareaComponent', () => {
expect(event.preventDefault).toHaveBeenCalledWith();
});

it(`should emit #send if enter is hit and #inputMode is desktop, but isComposing is true`, () => {
const spy = jasmine.createSpy();
component.send.subscribe(spy);
const textarea = queryTextarea();
const message = 'This is my message';
textarea!.value = message;
const event = new KeyboardEvent('keydown', {
key: 'Enter',
isComposing: true,
});
spyOn(event, 'preventDefault');
textarea?.dispatchEvent(event);
fixture.detectChanges();

expect(spy).not.toHaveBeenCalledWith();
expect(event.preventDefault).not.toHaveBeenCalledWith();
});

it(`shouldn't emit #send if enter is hit and #inputMode is mobile`, () => {
component.inputMode = 'mobile';
const spy = jasmine.createSpy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,20 @@ describe('TextareaComponent', () => {

expect(height).toBeGreaterThan(0);
});

it(`shouldn't emit #send if enter is hit and #inputMode is mobile`, () => {
component.inputMode = 'mobile';
const spy = jasmine.createSpy();
component.send.subscribe(spy);
const textarea = queryTextarea();
const message = 'This is my message';
textarea!.value = message;
const event = new KeyboardEvent('keydown', { key: 'Enter' });
spyOn(event, 'preventDefault');
textarea?.dispatchEvent(event);
fixture.detectChanges();

expect(spy).not.toHaveBeenCalled();
expect(event.preventDefault).not.toHaveBeenCalled();
});
});

0 comments on commit 0221af8

Please sign in to comment.