mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-09 08:42:15 +01:00
66 lines
2.1 KiB
TypeScript
66 lines
2.1 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { mount } from '@vue/test-utils';
|
|
import { nextTick } from 'vue';
|
|
import TimesheetCell from './TimesheetCell.vue';
|
|
import { formatHumanReadableDuration } from '@/packages/ui/src/utils/time';
|
|
import type { TimesheetCell as TimesheetCellType } from '@/utils/useTimesheetGrid';
|
|
|
|
function buildCell(totalSeconds: number): TimesheetCellType {
|
|
return {
|
|
dayIndex: 0,
|
|
date: '2026-04-13',
|
|
entries: [],
|
|
totalSeconds,
|
|
};
|
|
}
|
|
|
|
function mountTimesheetCell(totalSeconds = 2 * 3600) {
|
|
return mount(TimesheetCell, {
|
|
props: {
|
|
cell: buildCell(totalSeconds),
|
|
dayIndex: 0,
|
|
date: '2026-04-13',
|
|
isToday: false,
|
|
hasRunningEntry: false,
|
|
},
|
|
});
|
|
}
|
|
|
|
describe('TimesheetCell', () => {
|
|
it('emits 0 when the cleared value is committed on blur', async () => {
|
|
const wrapper = mountTimesheetCell();
|
|
const input = wrapper.get('input');
|
|
|
|
await input.trigger('focus');
|
|
await input.setValue('');
|
|
await input.trigger('blur');
|
|
|
|
expect(wrapper.emitted('update')).toEqual([[0]]);
|
|
});
|
|
|
|
it('emits 0 when the cleared value is committed with Enter', async () => {
|
|
const wrapper = mountTimesheetCell();
|
|
const input = wrapper.get('input');
|
|
|
|
await input.trigger('focus');
|
|
await input.setValue('');
|
|
await input.trigger('keydown', { key: 'Enter' });
|
|
|
|
expect(wrapper.emitted('update')).toEqual([[0]]);
|
|
});
|
|
|
|
it('restores the previous value and emits nothing on Escape', async () => {
|
|
const wrapper = mountTimesheetCell();
|
|
const input = wrapper.get('input');
|
|
const previousValue = formatHumanReadableDuration(2 * 3600, 'hours-minutes', 'point');
|
|
|
|
await input.trigger('focus');
|
|
await input.setValue('');
|
|
await input.trigger('keydown', { key: 'Escape' });
|
|
await nextTick();
|
|
|
|
expect(wrapper.emitted('update')).toBeUndefined();
|
|
expect((input.element as HTMLInputElement).value).toBe(previousValue);
|
|
});
|
|
});
|