Repository navigation
feat(plannings): the day dialog lists each shift's pause start and stop times (#1741) #1749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
eform-client/playwright/e2e/plugins/time-planning-pn/s/day-dialog-pause-times.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { test, expect } from '@playwright/test'; | ||
| import { | ||
| closeDayWithoutChange, lastWeekMonday, openDay, useLastWeekDashboard, waitForSpinner, | ||
| } from './reconcile-helpers'; | ||
|
|
||
| /** | ||
| * #1741: the day dialog lists each shift's recorded pauses as clock ranges. | ||
| * | ||
| * The stamps come from the app, which this suite cannot drive, so the grid's index | ||
| * response is given two shift-1 pauses (the primary slot and a sub-slot, out of | ||
| * order) on one day, and every other pause slot of that day is emptied. Nothing is | ||
| * written to the database. That the backend serves the stamps is covered by the C# | ||
| * tests of the index; this covers what the web does with them. | ||
| */ | ||
|
|
||
| const INDEX_GLOB = '**/api/time-planning-pn/plannings/index'; | ||
| const DAY = 2; | ||
| const API_TIMEOUT = 30000; | ||
| const UI_TIMEOUT = 15000; | ||
|
|
||
| test.describe('Day dialog: recorded pause times', () => { | ||
| const session = useLastWeekDashboard(); | ||
|
|
||
| test('lists both pauses of shift 1 as clock ranges, in clock order', async ({ page }) => { | ||
| const worker = await session.pickWorker(page, 0); | ||
|
|
||
| // Set by the route, so a reload that patched nothing fails here and not as a | ||
| // missing list in the dialog. | ||
| let patchedRows = 0; | ||
| await page.route(INDEX_GLOB, async route => { | ||
| const response = await route.fetch(); | ||
| const body = await response.json(); | ||
| for (const row of body?.model ?? []) { | ||
| const day = row.planningPrDayModels?.[DAY]; | ||
| if (!day?.id) { | ||
| continue; | ||
| } | ||
| const date = `${day.date}`.slice(0, 10); | ||
| for (const key of Object.keys(day)) { | ||
| if (/^pause\d+(StartedAt|StoppedAt)$/.test(key)) { | ||
| day[key] = null; | ||
| } | ||
| } | ||
| day.pause1StartedAt = `${date}T12:30:00Z`; | ||
| day.pause1StoppedAt = `${date}T12:45:00Z`; | ||
| day.pause10StartedAt = `${date}T10:02:00Z`; | ||
| day.pause10StoppedAt = `${date}T10:17:00Z`; | ||
| day.pause1OverrideMinutes = null; | ||
| patchedRows++; | ||
| } | ||
| await route.fulfill({ response, json: body }); | ||
| }); | ||
|
|
||
| const monday = lastWeekMonday(); | ||
| const reload = page.waitForResponse(r => | ||
| r.url().includes('/api/time-planning-pn/plannings/index') | ||
| && r.request().method() === 'POST' | ||
| && `${r.request().postDataJSON()?.dateFrom ?? ''}`.startsWith(monday), | ||
| { timeout: API_TIMEOUT }); | ||
| await page.locator('#workingHoursReload').click(); | ||
| expect((await reload).status(), 'the grid reload (POST plannings/index)').toBeLessThan(400); | ||
| await waitForSpinner(page); | ||
| expect(patchedRows, `the reload must carry a registration on day ${DAY} to patch`).toBeGreaterThan(0); | ||
|
|
||
| await openDay(page, worker, DAY); | ||
|
|
||
| const segments = page.locator('mat-dialog-container [data-testid="pauseSegments1"] [data-testid="pauseSegment1"]'); | ||
| await expect(segments).toHaveCount(2, { timeout: UI_TIMEOUT }); | ||
| await expect(segments.nth(0)).toContainText('10:02–10:17'); | ||
| await expect(segments.nth(1)).toContainText('12:30–12:45'); | ||
| // Shift 2 recorded no pause, so it lists none. | ||
| await expect(page.locator('mat-dialog-container [data-testid="pauseSegments2"]')).toHaveCount(0); | ||
|
|
||
| await closeDayWithoutChange(page); | ||
| }); | ||
| }); |
59 changes: 59 additions & 0 deletions
59
...src/app/plugins/modules/time-planning-pn/components/plannings/pause-segments.util.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import { buildPauseSegments } from './pause-segments.util'; | ||
|
|
||
| describe('buildPauseSegments', () => { | ||
| it('lists nothing for a shift with no pause stamps', () => { | ||
| expect(buildPauseSegments([])).toEqual([]); | ||
| expect(buildPauseSegments([[null, null], [undefined, undefined]])).toEqual([]); | ||
| }); | ||
|
|
||
| it('lists the pauses in clock order whatever slot they were recorded in', () => { | ||
| expect(buildPauseSegments([ | ||
| ['2026-05-15T12:30:00Z', '2026-05-15T12:45:00Z'], | ||
| [null, null], | ||
| ['2026-05-15T10:02:40Z', '2026-05-15T10:17:10Z'], | ||
| ])).toEqual([ | ||
| { start: '10:02', stop: '10:17' }, | ||
| { start: '12:30', stop: '12:45' }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('reads Date stamps, which is how they reach the dialog, by their UTC fields', () => { | ||
| // The core DateInterceptor parses the API's zone-less wall-clock strings with | ||
| // date-fns parseJSON, i.e. as UTC. | ||
| expect(buildPauseSegments([ | ||
| [new Date(Date.UTC(2026, 4, 15, 10, 2)), new Date(Date.UTC(2026, 4, 15, 10, 17))], | ||
| ])).toEqual([{ start: '10:02', stop: '10:17' }]); | ||
| }); | ||
|
|
||
| it('merges overlapping and touching pauses, as the backend does before cutting them out', () => { | ||
| expect(buildPauseSegments([ | ||
| ['2026-05-15T10:00:00Z', '2026-05-15T10:20:00Z'], | ||
| ['2026-05-15T10:10:00Z', '2026-05-15T10:15:00Z'], | ||
| ['2026-05-15T10:20:00Z', '2026-05-15T10:30:00Z'], | ||
| ])).toEqual([{ start: '10:00', stop: '10:30' }]); | ||
| }); | ||
|
|
||
| it('lists a pause that is still running open-ended, and does not merge it', () => { | ||
| expect(buildPauseSegments([ | ||
| ['2026-05-15T14:05:00Z', null], | ||
| ['2026-05-15T10:00:00Z', '2026-05-15T10:15:00Z'], | ||
| ])).toEqual([ | ||
| { start: '10:00', stop: '10:15' }, | ||
| { start: '14:05', stop: null }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('clamps a pause running past midnight to 24:00, as the backend does', () => { | ||
| expect(buildPauseSegments([ | ||
| ['2026-05-15T23:50:00Z', '2026-05-16T00:10:00Z'], | ||
| ])).toEqual([{ start: '23:50', stop: '24:00' }]); | ||
| }); | ||
|
|
||
| it('skips a stop without a start and a pause that does not end after it starts', () => { | ||
| expect(buildPauseSegments([ | ||
| [null, '2026-05-15T10:15:00Z'], | ||
| ['2026-05-15T11:00:00Z', '2026-05-15T11:00:00Z'], | ||
| ['2026-05-15T12:00:00Z', '2026-05-15T11:50:00Z'], | ||
| ])).toEqual([]); | ||
| }); | ||
| }); |
95 changes: 95 additions & 0 deletions
95
...ient/src/app/plugins/modules/time-planning-pn/components/plannings/pause-segments.util.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /** One pause as shown on the web: wall-clock 'HH:mm', stop null while it is running. */ | ||
| export interface PauseSegment { | ||
| start: string; | ||
| stop: string | null; | ||
| } | ||
|
|
||
| const SECONDS_PER_DAY = 86400; | ||
|
|
||
| /** | ||
| * A pause stamp as the dialog receives it. The API sends the stored wall-clock time | ||
| * without a zone, and the core DateInterceptor turns it into a Date with date-fns | ||
| * parseJSON, which reads a zone-less string as UTC. So the stamp's UTC fields ARE | ||
| * the wall-clock time, the same reading the grid gives it through | ||
| * DatePipe(..., 'UTC'). A string is accepted too, but only with an explicit zone | ||
| * (e.g. a trailing Z); a zone-less string would be read as local time. | ||
| */ | ||
| export type PauseStamp = string | Date | null | undefined; | ||
|
|
||
| /** Seconds-of-day of a stamp, read from its UTC fields (see PauseStamp). */ | ||
| function secondOfDay(stamp: Date): number { | ||
| return stamp.getUTCHours() * 3600 + stamp.getUTCMinutes() * 60 + stamp.getUTCSeconds(); | ||
| } | ||
|
|
||
| function utcDay(stamp: Date): number { | ||
| return Date.UTC(stamp.getUTCFullYear(), stamp.getUTCMonth(), stamp.getUTCDate()); | ||
| } | ||
|
|
||
| function toHhmm(seconds: number): string { | ||
| const minutes = Math.floor(seconds / 60); | ||
| return `${String(Math.floor(minutes / 60)).padStart(2, '0')}:${String(minutes % 60).padStart(2, '0')}`; | ||
| } | ||
|
|
||
| function parse(value: PauseStamp): Date | null { | ||
| if (!value) { | ||
| return null; | ||
| } | ||
| const date = new Date(value); | ||
| return isNaN(date.getTime()) ? null : date; | ||
| } | ||
|
|
||
| /** | ||
| * The pauses of one shift as the web shows them, built from its | ||
| * Pause{N}StartedAt / Pause{N}StoppedAt slot pairs. | ||
| * | ||
| * Closed pauses follow the rules of the backend's BuildMergedPauseSegments | ||
| * (TimePlanningWorkingHoursService), applied per shift rather than across the whole | ||
| * day as the backend does, because the dialog shows them under each shift: | ||
| * - each pair resolves like ResolveShiftSeconds: a stop on a later day is clamped to | ||
| * 24:00, and a pair whose stop is not after its start is dropped; | ||
| * - the rest are sorted by start, and overlapping or touching pauses are merged. | ||
| * | ||
| * A pause with a start and no stop is still running. The backend has nothing to cut | ||
| * for it, but the admin should see it, so it is listed open-ended and never merged. | ||
| * A stop with no start says nothing and is skipped. | ||
| */ | ||
| export function buildPauseSegments( | ||
| pairs: ReadonlyArray<readonly [PauseStamp, PauseStamp]>, | ||
| ): PauseSegment[] { | ||
| const closed: Array<{ start: number; stop: number }> = []; | ||
| const open: number[] = []; | ||
|
|
||
| for (const [rawStart, rawStop] of pairs) { | ||
| const start = parse(rawStart); | ||
| if (!start) { | ||
| continue; | ||
| } | ||
| const startSec = secondOfDay(start); | ||
| const stop = parse(rawStop); | ||
| if (!stop) { | ||
| open.push(startSec); | ||
| continue; | ||
| } | ||
| const stopSec = utcDay(stop) > utcDay(start) ? SECONDS_PER_DAY : secondOfDay(stop); | ||
| if (stopSec > startSec) { | ||
| closed.push({ start: startSec, stop: stopSec }); | ||
| } | ||
| } | ||
|
|
||
| closed.sort((a, b) => a.start - b.start); | ||
| const merged: Array<{ start: number; stop: number }> = []; | ||
| for (const current of closed) { | ||
| const last = merged[merged.length - 1]; | ||
| if (last && current.start <= last.stop) { | ||
| last.stop = Math.max(last.stop, current.stop); | ||
| } else { | ||
| merged.push({ ...current }); | ||
| } | ||
| } | ||
|
|
||
| const segments: Array<{ start: number; stop: number | null }> = | ||
| [...merged, ...open.map(start => ({ start, stop: null }))]; | ||
| return segments | ||
| .sort((a, b) => a.start - b.start) | ||
| .map(s => ({ start: toHhmm(s.start), stop: s.stop === null ? null : toHhmm(s.stop) })); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.