From 5dd3b2e8238fbbb4d142df481f6072e4a5b8f9da Mon Sep 17 00:00:00 2001 From: Johannes Millan Date: Tue, 16 Sep 2025 18:03:43 +0200 Subject: [PATCH] test: update tests for mention and focus mode improvements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update focus-mode reducer test to match simplified unPauseFocusSession action - Improve mention-utils type definitions to support HTMLTextAreaElement - Add comprehensive test coverage for mention directive stopEvent method 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../store/focus-mode.reducer.spec.ts | 2 +- src/app/ui/mentions/mention.directive.spec.ts | 100 ++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) diff --git a/src/app/features/focus-mode/store/focus-mode.reducer.spec.ts b/src/app/features/focus-mode/store/focus-mode.reducer.spec.ts index 6dcebf6d61..18d89356e0 100644 --- a/src/app/features/focus-mode/store/focus-mode.reducer.spec.ts +++ b/src/app/features/focus-mode/store/focus-mode.reducer.spec.ts @@ -175,7 +175,7 @@ describe('FocusModeReducer', () => { }, }; - const action = a.unPauseFocusSession({ idleTime: 5000 }); + const action = a.unPauseFocusSession(); const result = focusModeReducer(pausedState, action); expect(result.timer.isRunning).toBe(true); diff --git a/src/app/ui/mentions/mention.directive.spec.ts b/src/app/ui/mentions/mention.directive.spec.ts index 12229b67a7..54d2c913cc 100644 --- a/src/app/ui/mentions/mention.directive.spec.ts +++ b/src/app/ui/mentions/mention.directive.spec.ts @@ -4,6 +4,7 @@ import { By } from '@angular/platform-browser'; import { MentionDirective } from './mention.directive'; import { MentionConfig } from './mention-config'; import { Log } from '../../core/log'; +import { MentionEvent } from './mention-types'; @Component({ template: ``, @@ -243,4 +244,103 @@ describe('MentionDirective', () => { expect(result).toEqual(items); }); }); + + describe('stopEvent', () => { + it('should handle standard event with all methods', () => { + const mockEvent: MentionEvent = { + wasClick: false, + preventDefault: jasmine.createSpy('preventDefault'), + stopPropagation: jasmine.createSpy('stopPropagation'), + stopImmediatePropagation: jasmine.createSpy('stopImmediatePropagation'), + }; + + directive.stopEvent(mockEvent); + + expect(mockEvent.preventDefault).toHaveBeenCalled(); + expect(mockEvent.stopPropagation).toHaveBeenCalled(); + expect(mockEvent.stopImmediatePropagation).toHaveBeenCalled(); + }); + + it('should handle event with missing preventDefault method', () => { + const mockEvent: MentionEvent = { + wasClick: false, + stopPropagation: jasmine.createSpy('stopPropagation'), + stopImmediatePropagation: jasmine.createSpy('stopImmediatePropagation'), + }; + + // Should not throw error + expect(() => directive.stopEvent(mockEvent)).not.toThrow(); + expect(mockEvent.stopPropagation).toHaveBeenCalled(); + expect(mockEvent.stopImmediatePropagation).toHaveBeenCalled(); + }); + + it('should handle event with missing stopPropagation method', () => { + const mockEvent: MentionEvent = { + wasClick: false, + preventDefault: jasmine.createSpy('preventDefault'), + stopImmediatePropagation: jasmine.createSpy('stopImmediatePropagation'), + }; + + expect(() => directive.stopEvent(mockEvent)).not.toThrow(); + expect(mockEvent.preventDefault).toHaveBeenCalled(); + expect(mockEvent.stopImmediatePropagation).toHaveBeenCalled(); + }); + + it('should handle event with missing stopImmediatePropagation method', () => { + const mockEvent: MentionEvent = { + wasClick: false, + preventDefault: jasmine.createSpy('preventDefault'), + stopPropagation: jasmine.createSpy('stopPropagation'), + }; + + expect(() => directive.stopEvent(mockEvent)).not.toThrow(); + expect(mockEvent.preventDefault).toHaveBeenCalled(); + expect(mockEvent.stopPropagation).toHaveBeenCalled(); + }); + + it('should handle event with all methods missing', () => { + const mockEvent: MentionEvent = { + wasClick: false, + }; + + // Should not throw error + expect(() => directive.stopEvent(mockEvent)).not.toThrow(); + }); + + it('should handle event with non-function preventDefault property', () => { + const mockEvent: MentionEvent = { + wasClick: false, + preventDefault: 'not-a-function' as any, // intentionally invalid for test + stopPropagation: jasmine.createSpy('stopPropagation'), + stopImmediatePropagation: jasmine.createSpy('stopImmediatePropagation'), + }; + + expect(() => directive.stopEvent(mockEvent)).not.toThrow(); + expect(mockEvent.stopPropagation).toHaveBeenCalled(); + expect(mockEvent.stopImmediatePropagation).toHaveBeenCalled(); + }); + + it('should not stop event when wasClick is true', () => { + const mockEvent: MentionEvent = { + wasClick: true, + preventDefault: jasmine.createSpy('preventDefault'), + stopPropagation: jasmine.createSpy('stopPropagation'), + stopImmediatePropagation: jasmine.createSpy('stopImmediatePropagation'), + }; + + directive.stopEvent(mockEvent); + + expect(mockEvent.preventDefault).not.toHaveBeenCalled(); + expect(mockEvent.stopPropagation).not.toHaveBeenCalled(); + expect(mockEvent.stopImmediatePropagation).not.toHaveBeenCalled(); + }); + + it('should handle null event gracefully', () => { + expect(() => directive.stopEvent(null)).not.toThrow(); + }); + + it('should handle undefined event gracefully', () => { + expect(() => directive.stopEvent(undefined as any)).not.toThrow(); + }); + }); });