fix(fg_trace): handle date column index out of range error

Improve robustness by checking if the requested dateIndex is within the available day columns before attempting to locate the element. This prevents a silent failure and provides a clear error message.
This commit is contained in:
duanshuwen
2026-04-06 20:17:06 +08:00
parent f8ddecc6dd
commit 2b250a58ea
2 changed files with 11 additions and 7 deletions

File diff suppressed because one or more lines are too long

View File

@@ -104,13 +104,17 @@ const toggleRoomByDateIndex = async (container, { roomType, dateIndex, operation
}
await roomAnchor.scrollIntoViewIfNeeded();
const row = roomAnchor.locator(
"xpath=ancestor::*[.//div[contains(@class,'boardRow')]][1]",
const boardRow = roomAnchor.locator("xpath=ancestor::div[contains(@class,'boardRow')][1]");
const dayColumns = boardRow.locator(
"xpath=.//div[contains(@class,'switchbar')]/ancestor::div[contains(@class,'flex-col')][1]",
);
const boardRow = row.locator("xpath=.//div[contains(@class,'boardRow')]").first();
const boardColPosition = dateIndex + 2;
const dayColumn = boardRow.locator(`xpath=./div[${boardColPosition}]`);
const dayColumnCount = await dayColumns.count();
if (dateIndex >= dayColumnCount) {
throw new Error(
`Date column out of range for room ${roomType}: index=${dateIndex}, available=${dayColumnCount}`,
);
}
const dayColumn = dayColumns.nth(dateIndex);
const targetStateClass = operation === 'open' ? 'error' : 'success';
const expectedCurrentLabel = operation === 'open' ? '满' : '有';