mirror of
https://github.com/johannesjo/super-productivity.git
synced 2026-01-23 02:36:05 +00:00
test: make them run again
This commit is contained in:
parent
88ff5a2b7a
commit
cceb7fd95a
4 changed files with 55 additions and 48 deletions
|
|
@ -138,6 +138,7 @@ describe('AddTaskBarActionsComponent', () => {
|
|||
|
||||
fixture = TestBed.createComponent(AddTaskBarActionsComponent);
|
||||
component = fixture.componentInstance;
|
||||
spyOn(component.refocus, 'emit');
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
|
|
@ -406,35 +407,42 @@ describe('AddTaskBarActionsComponent', () => {
|
|||
|
||||
component.openScheduleDialog();
|
||||
|
||||
expect(mockStateService.updateDate).toHaveBeenCalledWith(resultDate, resultTime);
|
||||
expect(mockStateService.updateDate).toHaveBeenCalledWith(
|
||||
resultDate as any,
|
||||
resultTime,
|
||||
);
|
||||
});
|
||||
|
||||
it('should handle dialog cancellation', () => {
|
||||
mockDialogRef.afterClosed.and.returnValue(of(false));
|
||||
const currentState = { ...mockState, date: new Date(), time: '10:00' };
|
||||
const currentState = {
|
||||
...mockState,
|
||||
date: getDbDateStr(new Date()),
|
||||
time: '10:00',
|
||||
};
|
||||
(mockStateService as any)._mockStateSignal.set(currentState);
|
||||
fixture.detectChanges();
|
||||
|
||||
component.openScheduleDialog();
|
||||
|
||||
expect(mockStateService.updateDate).toHaveBeenCalledWith(
|
||||
currentState.date,
|
||||
currentState.time,
|
||||
);
|
||||
expect(mockStateService.updateDate).not.toHaveBeenCalled();
|
||||
expect(component.refocus.emit).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should handle dialog result without proper data', () => {
|
||||
mockDialogRef.afterClosed.and.returnValue(of('invalid'));
|
||||
const currentState = { ...mockState, date: new Date(), time: '10:00' };
|
||||
const currentState = {
|
||||
...mockState,
|
||||
date: getDbDateStr(new Date()),
|
||||
time: '10:00',
|
||||
};
|
||||
(mockStateService as any)._mockStateSignal.set(currentState);
|
||||
fixture.detectChanges();
|
||||
|
||||
component.openScheduleDialog();
|
||||
|
||||
expect(mockStateService.updateDate).toHaveBeenCalledWith(
|
||||
currentState.date,
|
||||
currentState.time,
|
||||
);
|
||||
expect(mockStateService.updateDate).not.toHaveBeenCalled();
|
||||
expect(component.refocus.emit).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should pass time to dialog even when no date is selected', () => {
|
||||
|
|
|
|||
|
|
@ -134,13 +134,13 @@ describe('AddTaskBarParserService', () => {
|
|||
|
||||
expect(mockStateService.updateDate).toHaveBeenCalled();
|
||||
const [date, time] = mockStateService.updateDate.calls.mostRecent().args;
|
||||
expect(date).toBeInstanceOf(Date);
|
||||
expect(date?.toISOString().split('T')[0]).toBe(defaultDate);
|
||||
expect(typeof date).toBe('string');
|
||||
expect(date).toBe(defaultDate);
|
||||
expect(time).toBe(defaultTime);
|
||||
});
|
||||
|
||||
it('should preserve current date/time when no syntax present', () => {
|
||||
const currentDate = new Date('2024-02-20');
|
||||
const currentDate = '2024-02-20';
|
||||
const currentTime = '14:30';
|
||||
|
||||
// Mock state to return current user-selected values
|
||||
|
|
@ -170,7 +170,7 @@ describe('AddTaskBarParserService', () => {
|
|||
});
|
||||
|
||||
it('should preserve current date but use default time when no current time', () => {
|
||||
const currentDate = new Date('2024-02-20');
|
||||
const currentDate = '2024-02-20';
|
||||
const defaultTime = '09:00';
|
||||
|
||||
// Mock state with date but no time
|
||||
|
|
@ -247,7 +247,7 @@ describe('AddTaskBarParserService', () => {
|
|||
|
||||
expect(mockStateService.updateDate).toHaveBeenCalled();
|
||||
const [date, time] = mockStateService.updateDate.calls.mostRecent().args;
|
||||
expect(date).toBeInstanceOf(Date);
|
||||
expect(typeof date).toBe('string');
|
||||
expect(time).toBe(defaultTime);
|
||||
});
|
||||
});
|
||||
|
|
@ -541,32 +541,31 @@ describe('AddTaskBarParserService', () => {
|
|||
});
|
||||
|
||||
describe('_datesEqual', () => {
|
||||
it('should return true for equal dates', () => {
|
||||
const date1 = new Date('2024-01-15T10:30:00Z');
|
||||
const date2 = new Date('2024-01-15T10:30:00Z');
|
||||
expect(serviceAny._datesEqual(date1, date2)).toBe(true);
|
||||
it('should return true for equal date strings', () => {
|
||||
const dateStr1 = '2024-01-15';
|
||||
const dateStr2 = '2024-01-15';
|
||||
expect(serviceAny._datesEqual(dateStr1, dateStr2)).toBe(true);
|
||||
expect(serviceAny._datesEqual(null, null)).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for different dates', () => {
|
||||
const date1 = new Date('2024-01-15T10:30:00Z');
|
||||
const date2 = new Date('2024-01-16T10:30:00Z');
|
||||
expect(serviceAny._datesEqual(date1, date2)).toBe(false);
|
||||
expect(serviceAny._datesEqual(date1, null)).toBe(false);
|
||||
expect(serviceAny._datesEqual(null, date1)).toBe(false);
|
||||
it('should return false for different date strings', () => {
|
||||
const dateStr1 = '2024-01-15';
|
||||
const dateStr2 = '2024-01-16';
|
||||
expect(serviceAny._datesEqual(dateStr1, dateStr2)).toBe(false);
|
||||
expect(serviceAny._datesEqual(dateStr1, null)).toBe(false);
|
||||
expect(serviceAny._datesEqual(null, dateStr1)).toBe(false);
|
||||
});
|
||||
|
||||
it('should handle same timestamp different date objects', () => {
|
||||
const timestamp = new Date('2024-01-15T10:30:00Z').getTime();
|
||||
const date1 = new Date(timestamp);
|
||||
const date2 = new Date(timestamp);
|
||||
expect(serviceAny._datesEqual(date1, date2)).toBe(true);
|
||||
it('should handle same date strings', () => {
|
||||
const dateStr1 = '2024-01-15';
|
||||
const dateStr2 = '2024-01-15';
|
||||
expect(serviceAny._datesEqual(dateStr1, dateStr2)).toBe(true);
|
||||
});
|
||||
|
||||
it('should handle millisecond differences', () => {
|
||||
const date1 = new Date('2024-01-15T10:30:00.000Z');
|
||||
const date2 = new Date('2024-01-15T10:30:00.001Z');
|
||||
expect(serviceAny._datesEqual(date1, date2)).toBe(false);
|
||||
it('should handle different date strings', () => {
|
||||
const dateStr1 = '2024-01-15';
|
||||
const dateStr2 = '2024-01-16';
|
||||
expect(serviceAny._datesEqual(dateStr1, dateStr2)).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { Project } from '../../project/project.model';
|
|||
import { Tag } from '../../tag/tag.model';
|
||||
import { INITIAL_ADD_TASK_BAR_STATE } from './add-task-bar.const';
|
||||
import { SS } from '../../../core/persistence/storage-keys.const';
|
||||
import { getDbDateStr } from '../../../util/get-db-date-str';
|
||||
|
||||
describe('AddTaskBarStateService', () => {
|
||||
let service: AddTaskBarStateService;
|
||||
|
|
@ -69,18 +70,18 @@ describe('AddTaskBarStateService', () => {
|
|||
it('should update date in state', () => {
|
||||
const testDate = new Date('2024-01-15');
|
||||
|
||||
service.updateDate(testDate);
|
||||
service.updateDate(getDbDateStr(testDate));
|
||||
|
||||
expect(service.state().date).toEqual(testDate);
|
||||
expect(service.state().date).toEqual(getDbDateStr(testDate));
|
||||
});
|
||||
|
||||
it('should update date and time when both provided', () => {
|
||||
const testDate = new Date('2024-01-15');
|
||||
const testTime = '10:30';
|
||||
|
||||
service.updateDate(testDate, testTime);
|
||||
service.updateDate(getDbDateStr(testDate), testTime);
|
||||
|
||||
expect(service.state().date).toEqual(testDate);
|
||||
expect(service.state().date).toEqual(getDbDateStr(testDate));
|
||||
expect(service.state().time).toBe(testTime);
|
||||
});
|
||||
|
||||
|
|
@ -88,9 +89,9 @@ describe('AddTaskBarStateService', () => {
|
|||
const testDate = new Date('2024-01-15');
|
||||
service.updateTime('09:00');
|
||||
|
||||
service.updateDate(testDate);
|
||||
service.updateDate(getDbDateStr(testDate));
|
||||
|
||||
expect(service.state().date).toEqual(testDate);
|
||||
expect(service.state().date).toEqual(getDbDateStr(testDate));
|
||||
expect(service.state().time).toBe('09:00');
|
||||
});
|
||||
|
||||
|
|
@ -98,15 +99,15 @@ describe('AddTaskBarStateService', () => {
|
|||
service.updateTime('09:00');
|
||||
const testDate = new Date('2024-01-15');
|
||||
|
||||
service.updateDate(testDate, null);
|
||||
service.updateDate(getDbDateStr(testDate), null);
|
||||
|
||||
expect(service.state().date).toEqual(testDate);
|
||||
expect(service.state().date).toEqual(getDbDateStr(testDate));
|
||||
expect(service.state().time).toBe(null);
|
||||
});
|
||||
|
||||
it('should clear date when null passed', () => {
|
||||
const testDate = new Date('2024-01-15');
|
||||
service.updateDate(testDate);
|
||||
service.updateDate(getDbDateStr(testDate));
|
||||
|
||||
service.updateDate(null);
|
||||
|
||||
|
|
@ -296,7 +297,7 @@ describe('AddTaskBarStateService', () => {
|
|||
|
||||
describe('clearDate', () => {
|
||||
it('should clear date and time', () => {
|
||||
service.updateDate(new Date(), '10:30');
|
||||
service.updateDate(getDbDateStr(new Date()), '10:30');
|
||||
|
||||
service.clearDate();
|
||||
|
||||
|
|
@ -340,7 +341,7 @@ describe('AddTaskBarStateService', () => {
|
|||
|
||||
// Set up initial state
|
||||
service.updateProject(mockProject);
|
||||
service.updateDate(testDate, '10:30');
|
||||
service.updateDate(getDbDateStr(testDate), '10:30');
|
||||
service.updateEstimate(testEstimate);
|
||||
service.updateTags(mockTags);
|
||||
service.updateNewTagTitles(['new-tag']);
|
||||
|
|
@ -357,7 +358,7 @@ describe('AddTaskBarStateService', () => {
|
|||
|
||||
// These should be preserved
|
||||
expect(service.state().project).toEqual(mockProject);
|
||||
expect(service.state().date).toEqual(testDate);
|
||||
expect(service.state().date).toEqual(getDbDateStr(testDate));
|
||||
expect(service.state().time).toBe('10:30');
|
||||
expect(service.state().estimate).toBe(testEstimate);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import {
|
|||
Component,
|
||||
computed,
|
||||
DestroyRef,
|
||||
effect,
|
||||
ElementRef,
|
||||
HostListener,
|
||||
inject,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue