test(focus-mode): add comprehensive tests for break pause Bug #5995 fix

Add unit tests for Bug #2 fix from issue #5995:
- Test pauseBreak() uses currentTaskId when tracking is active
- Test fallback to stored pausedTaskId when tracking is stopped
- Ensures overlay pause correctly stops tracking during breaks

Related to fixes in a0719c15c and 92fdcc6a1
This commit is contained in:
Johannes Millan 2026-01-19 18:46:33 +01:00
parent 587ba76bdb
commit 3a58eda3db

View file

@ -17,10 +17,12 @@ import {
} from '@angular/core';
import { T } from '../../../t.const';
import { of } from 'rxjs';
import { TaskService } from '../../tasks/task.service';
describe('FocusModeBreakComponent', () => {
let component: FocusModeBreakComponent;
let mockStore: jasmine.SpyObj<Store>;
let mockTaskService: jasmine.SpyObj<any>;
let mockFocusModeService: {
timeRemaining: Signal<number>;
progress: Signal<number>;
@ -29,11 +31,15 @@ describe('FocusModeBreakComponent', () => {
};
let environmentInjector: EnvironmentInjector;
const mockPausedTaskId = 'test-task-id';
const mockCurrentTaskId = 'current-task-id';
beforeEach(() => {
mockStore = jasmine.createSpyObj('Store', ['dispatch', 'select']);
mockStore.select.and.returnValue(of(mockPausedTaskId));
mockTaskService = jasmine.createSpyObj('TaskService', ['currentTaskId']);
mockTaskService.currentTaskId.and.returnValue(mockCurrentTaskId);
mockFocusModeService = {
timeRemaining: signal(300000),
progress: signal(0.5),
@ -45,6 +51,7 @@ describe('FocusModeBreakComponent', () => {
providers: [
{ provide: Store, useValue: mockStore },
{ provide: FocusModeService, useValue: mockFocusModeService },
{ provide: TaskService, useValue: mockTaskService },
],
});
@ -109,9 +116,25 @@ describe('FocusModeBreakComponent', () => {
});
describe('pauseBreak', () => {
it('should dispatch pauseFocusSession action with pausedTaskId', () => {
it('should dispatch pauseFocusSession with currentTaskId when tracking is active (Bug #5995 fix)', () => {
// Scenario: Tracking continues during break (isPauseTrackingDuringBreak=FALSE)
mockTaskService.currentTaskId.and.returnValue(mockCurrentTaskId);
component.pauseBreak();
expect(mockTaskService.currentTaskId).toHaveBeenCalled();
expect(mockStore.dispatch).toHaveBeenCalledWith(
pauseFocusSession({ pausedTaskId: mockCurrentTaskId }),
);
});
it('should fall back to stored pausedTaskId when tracking is stopped', () => {
// Scenario: Tracking was auto-paused during break (isPauseTrackingDuringBreak=TRUE)
mockTaskService.currentTaskId.and.returnValue(null);
component.pauseBreak();
expect(mockTaskService.currentTaskId).toHaveBeenCalled();
expect(mockStore.dispatch).toHaveBeenCalledWith(
pauseFocusSession({ pausedTaskId: mockPausedTaskId }),
);