mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-15 03:32:15 +01:00
add timesheet unit and e2e tests; add unit test CI setup
This commit is contained in:
65
resources/js/Components/Timesheet/TimesheetCell.test.ts
Normal file
65
resources/js/Components/Timesheet/TimesheetCell.test.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user