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:
File diff suppressed because one or more lines are too long
@@ -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' ? '满' : '有';
|
||||
|
||||
Reference in New Issue
Block a user