mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-04 18:04:18 +00:00
test(vacay): catch the suites up with the comp/flex column
The kind column changed four things the tests still asserted the old way: toggleEntry gained a parameter, the toolbar gained the comp modifier, shared calendar rows carry kind, and a multi-person cell is now segment overlays instead of one split gradient. splitBackground went with it — nothing but the test still referenced it. The toolbar tests picked the half-day button by index, which the new button shifted; they select by name now so the next modifier does not break them.
This commit is contained in:
@@ -7,8 +7,8 @@ import { useVacayStore } from '../../store/vacayStore'
|
||||
import VacayCalendar from './VacayCalendar'
|
||||
|
||||
vi.mock('./VacayMonthCard', () => ({
|
||||
default: ({ month, onCellClick }: any) => (
|
||||
<div data-testid={`month-card-${month}`}>
|
||||
default: ({ year, month, onCellClick }: any) => (
|
||||
<div data-testid={`month-card-${month}`} data-year={year}>
|
||||
<button onClick={() => onCellClick(`2025-01-${String(month + 1).padStart(2, '0')}`)}>
|
||||
click-{month}
|
||||
</button>
|
||||
@@ -16,6 +16,8 @@ vi.mock('./VacayMonthCard', () => ({
|
||||
),
|
||||
}))
|
||||
|
||||
const fiscalJuly = { year_type: 'fiscal' as const, year_start_month: 7, year_start_day: 1, hire_date: null }
|
||||
|
||||
const basePlan = {
|
||||
id: 1,
|
||||
holidays_enabled: false,
|
||||
@@ -47,6 +49,51 @@ describe('VacayCalendar', () => {
|
||||
expect(screen.getAllByTestId(/^month-card-/)).toHaveLength(12)
|
||||
})
|
||||
|
||||
it('FE-COMP-VACAYCALENDAR-001a: renders January to December of the selected year by default', () => {
|
||||
seedStore(useVacayStore, {
|
||||
selectedYear: 2025,
|
||||
entries: [],
|
||||
companyHolidays: [],
|
||||
holidays: {},
|
||||
plan: basePlan,
|
||||
users: [],
|
||||
selectedUserId: null,
|
||||
})
|
||||
|
||||
render(<VacayCalendar />)
|
||||
|
||||
const cards = screen.getAllByTestId(/^month-card-/)
|
||||
expect(cards[0]).toHaveAttribute('data-testid', 'month-card-0')
|
||||
expect(cards[0]).toHaveAttribute('data-year', '2025')
|
||||
expect(cards[11]).toHaveAttribute('data-testid', 'month-card-11')
|
||||
expect(cards[11]).toHaveAttribute('data-year', '2025')
|
||||
})
|
||||
|
||||
it('FE-COMP-VACAYCALENDAR-001b: rolls the grid over the calendar year for a fiscal window (#737)', () => {
|
||||
seedStore(useVacayStore, {
|
||||
selectedYear: 2026,
|
||||
entries: [],
|
||||
companyHolidays: [],
|
||||
holidays: {},
|
||||
plan: basePlan,
|
||||
users: [],
|
||||
selectedUserId: null,
|
||||
yearSettings: fiscalJuly,
|
||||
})
|
||||
|
||||
render(<VacayCalendar />)
|
||||
|
||||
const cards = screen.getAllByTestId(/^month-card-/)
|
||||
expect(cards).toHaveLength(12)
|
||||
// Jul 2026 first, Jan 2027 in the middle, Jun 2027 last.
|
||||
expect(cards[0]).toHaveAttribute('data-testid', 'month-card-6')
|
||||
expect(cards[0]).toHaveAttribute('data-year', '2026')
|
||||
expect(cards[6]).toHaveAttribute('data-testid', 'month-card-0')
|
||||
expect(cards[6]).toHaveAttribute('data-year', '2027')
|
||||
expect(cards[11]).toHaveAttribute('data-testid', 'month-card-5')
|
||||
expect(cards[11]).toHaveAttribute('data-year', '2027')
|
||||
})
|
||||
|
||||
it('FE-COMP-VACAYCALENDAR-002: shows vacation mode button by default with username', () => {
|
||||
seedStore(useVacayStore, {
|
||||
selectedYear: 2025,
|
||||
@@ -97,10 +144,10 @@ describe('VacayCalendar', () => {
|
||||
|
||||
render(<VacayCalendar />)
|
||||
|
||||
// Vacation + half-day buttons stay; only the company button is hidden.
|
||||
// Vacation + the comp and half-day modifiers stay; only the company button is hidden.
|
||||
const buttons = screen.getAllByRole('button')
|
||||
const toolbarButtons = buttons.filter(b => !b.textContent?.startsWith('click-'))
|
||||
expect(toolbarButtons).toHaveLength(2)
|
||||
expect(toolbarButtons).toHaveLength(3)
|
||||
})
|
||||
|
||||
it('FE-COMP-VACAYCALENDAR-005: switching to company mode highlights company button', async () => {
|
||||
@@ -149,7 +196,7 @@ describe('VacayCalendar', () => {
|
||||
// Click the first month card cell button (month 0 → date '2025-01-01')
|
||||
await user.click(screen.getByText('click-0'))
|
||||
|
||||
expect(toggleEntry).toHaveBeenCalledWith('2025-01-01', 42, 1)
|
||||
expect(toggleEntry).toHaveBeenCalledWith('2025-01-01', 42, 1, 'vacation')
|
||||
})
|
||||
|
||||
it('FE-COMP-VACAYCALENDAR-006b: half-day mode logs the day as 0.5', async () => {
|
||||
@@ -169,13 +216,58 @@ describe('VacayCalendar', () => {
|
||||
|
||||
render(<VacayCalendar />)
|
||||
|
||||
// toolbarButtons[0] = vacation, [1] = half day
|
||||
const buttons = screen.getAllByRole('button')
|
||||
const toolbarButtons = buttons.filter(b => !b.textContent?.startsWith('click-'))
|
||||
await user.click(toolbarButtons[1])
|
||||
// Comp and half-day are both modifiers in the toolbar — pick by name, not position.
|
||||
await user.click(screen.getByRole('button', { name: 'Half day' }))
|
||||
await user.click(screen.getByText('click-0'))
|
||||
|
||||
expect(toggleEntry).toHaveBeenCalledWith('2025-01-01', 42, 0.5)
|
||||
expect(toggleEntry).toHaveBeenCalledWith('2025-01-01', 42, 0.5, 'vacation')
|
||||
})
|
||||
|
||||
it('FE-COMP-VACAYCALENDAR-006c: the comp modifier logs the day as a comp/flex day (#1074)', async () => {
|
||||
const user = userEvent.setup()
|
||||
const toggleEntry = vi.fn().mockResolvedValue(undefined)
|
||||
|
||||
seedStore(useVacayStore, {
|
||||
selectedYear: 2025,
|
||||
entries: [],
|
||||
companyHolidays: [],
|
||||
holidays: {},
|
||||
plan: { ...basePlan, block_weekends: false, company_holidays_enabled: false },
|
||||
users: [],
|
||||
selectedUserId: 42,
|
||||
toggleEntry,
|
||||
})
|
||||
|
||||
render(<VacayCalendar />)
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Comp / Flex' }))
|
||||
await user.click(screen.getByText('click-0'))
|
||||
|
||||
expect(toggleEntry).toHaveBeenCalledWith('2025-01-01', 42, 1, 'comp')
|
||||
})
|
||||
|
||||
it('FE-COMP-VACAYCALENDAR-006d: comp and half-day stack into a half comp day (#1074)', async () => {
|
||||
const user = userEvent.setup()
|
||||
const toggleEntry = vi.fn().mockResolvedValue(undefined)
|
||||
|
||||
seedStore(useVacayStore, {
|
||||
selectedYear: 2025,
|
||||
entries: [],
|
||||
companyHolidays: [],
|
||||
holidays: {},
|
||||
plan: { ...basePlan, block_weekends: false, company_holidays_enabled: false },
|
||||
users: [],
|
||||
selectedUserId: 42,
|
||||
toggleEntry,
|
||||
})
|
||||
|
||||
render(<VacayCalendar />)
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Comp / Flex' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Half day' }))
|
||||
await user.click(screen.getByText('click-0'))
|
||||
|
||||
expect(toggleEntry).toHaveBeenCalledWith('2025-01-01', 42, 0.5, 'comp')
|
||||
})
|
||||
|
||||
it('FE-COMP-VACAYCALENDAR-007: cell click on public holiday toggles vacation entry', async () => {
|
||||
@@ -198,7 +290,7 @@ describe('VacayCalendar', () => {
|
||||
// Month 0, button emits '2025-01-01' which is a holiday — should still toggle vacation
|
||||
await user.click(screen.getByText('click-0'))
|
||||
|
||||
expect(toggleEntry).toHaveBeenCalledWith('2025-01-01', undefined, 1)
|
||||
expect(toggleEntry).toHaveBeenCalledWith('2025-01-01', undefined, 1, 'vacation')
|
||||
})
|
||||
|
||||
it('FE-COMP-VACAYCALENDAR-008: cell click in company mode calls toggleCompanyHoliday', async () => {
|
||||
|
||||
@@ -150,18 +150,87 @@ describe('VacayMonthCard', () => {
|
||||
expect(getFirstWeekLabels()).toEqual(['', '', '', '1', '2', '3', '4'])
|
||||
})
|
||||
|
||||
it('FE-COMP-VACAYMONTHCARD-011: Two vacation entries fill the cell with a split gradient', () => {
|
||||
it('FE-COMP-VACAYMONTHCARD-011: Two vacation entries split the cell into two clipped halves', () => {
|
||||
const props = {
|
||||
...baseProps,
|
||||
entryMap: {
|
||||
'2025-01-15': [{ date: '2025-01-15', user_id: 1, person_color: '#6366f1' }, { date: '2025-01-15', user_id: 1, person_color: '#f43f5e' }],
|
||||
'2025-01-15': [{ date: '2025-01-15', user_id: 1, person_color: '#6366f1' }, { date: '2025-01-15', user_id: 2, person_color: '#f43f5e' }],
|
||||
},
|
||||
}
|
||||
render(<VacayMonthCard {...props} />)
|
||||
const daySpan = screen.getByText('15')
|
||||
const cell = daySpan.closest('div') as HTMLElement
|
||||
// The split gradient is the cell background itself (glass facelift).
|
||||
expect(cell.style.background).toContain('linear-gradient')
|
||||
// Each half is its own clipped overlay so it can be solid or hatched on its
|
||||
// own (#1074) — the diagonal is no longer one gradient on the cell itself.
|
||||
// jsdom normalises the hex inside color-mix() to rgb().
|
||||
const halves = [...cell.querySelectorAll<HTMLElement>('div')].filter(d => d.style.clipPath)
|
||||
expect(halves).toHaveLength(2)
|
||||
expect(halves[0].style.background).toContain('rgb(99, 102, 241)')
|
||||
expect(halves[1].style.background).toContain('rgb(244, 63, 94)')
|
||||
expect(halves.map(h => h.style.background).join()).not.toContain('repeating-linear-gradient')
|
||||
})
|
||||
|
||||
it('FE-COMP-VACAYMONTHCARD-011a: a comp day hatches only its own half of the split (#1074)', () => {
|
||||
const props = {
|
||||
...baseProps,
|
||||
entryMap: {
|
||||
'2025-01-15': [
|
||||
{ date: '2025-01-15', user_id: 1, person_color: '#6366f1', kind: 'comp' as const },
|
||||
{ date: '2025-01-15', user_id: 2, person_color: '#f43f5e' },
|
||||
],
|
||||
},
|
||||
}
|
||||
render(<VacayMonthCard {...props} />)
|
||||
const cell = screen.getByText('15').closest('div') as HTMLElement
|
||||
const halves = [...cell.querySelectorAll<HTMLElement>('div')].filter(d => d.style.clipPath)
|
||||
expect(halves[0].style.background).toContain('repeating-linear-gradient')
|
||||
expect(halves[1].style.background).not.toContain('repeating-linear-gradient')
|
||||
})
|
||||
|
||||
it('FE-COMP-VACAYMONTHCARD-011b: a single comp day hatches the whole cell (#1074)', () => {
|
||||
const props = {
|
||||
...baseProps,
|
||||
entryMap: {
|
||||
'2025-01-15': [{ date: '2025-01-15', user_id: 1, person_color: '#6366f1', kind: 'comp' as const }],
|
||||
},
|
||||
}
|
||||
render(<VacayMonthCard {...props} />)
|
||||
const cell = screen.getByText('15').closest('div') as HTMLElement
|
||||
expect(cell.style.background).toContain('repeating-linear-gradient')
|
||||
})
|
||||
|
||||
it('FE-COMP-VACAYMONTHCARD-011c: an all-comp day keeps the white digit and gains a shadow to carry it (#1074)', () => {
|
||||
const props = {
|
||||
...baseProps,
|
||||
entryMap: {
|
||||
'2025-01-15': [{ date: '2025-01-15', user_id: 1, person_color: '#6366f1', kind: 'comp' as const }],
|
||||
// A solid vacation fill needs no shadow — the fill itself is the contrast.
|
||||
'2025-01-16': [{ date: '2025-01-16', user_id: 1, person_color: '#6366f1' }],
|
||||
},
|
||||
}
|
||||
render(<VacayMonthCard {...props} />)
|
||||
const comp = screen.getByText('15')
|
||||
const vacation = screen.getByText('16')
|
||||
expect(comp).toHaveStyle({ color: '#fff' })
|
||||
// Only that the shadow is there — its exact strength is a design value.
|
||||
expect(comp.style.textShadow).not.toBe('')
|
||||
expect(vacation).toHaveStyle({ color: '#fff' })
|
||||
expect(vacation.style.textShadow).toBe('')
|
||||
})
|
||||
|
||||
it('FE-COMP-VACAYMONTHCARD-011d: a mixed comp/vacation day needs no shadow — a solid half sits under the digit (#1074)', () => {
|
||||
const props = {
|
||||
...baseProps,
|
||||
entryMap: {
|
||||
'2025-01-15': [
|
||||
{ date: '2025-01-15', user_id: 1, person_color: '#6366f1', kind: 'comp' as const },
|
||||
{ date: '2025-01-15', user_id: 2, person_color: '#f43f5e' },
|
||||
],
|
||||
},
|
||||
}
|
||||
render(<VacayMonthCard {...props} />)
|
||||
expect(screen.getByText('15')).toHaveStyle({ color: '#fff' })
|
||||
expect(screen.getByText('15').style.textShadow).toBe('')
|
||||
})
|
||||
|
||||
it('FE-COMP-VACAYMONTHCARD-012: Four vacation entries render quadrant overlay', () => {
|
||||
|
||||
Reference in New Issue
Block a user