refactor(web-test): returnFormState в close.mjs + filter.mjs (7 веток)

closeForm: platform-dialogs, save=true/false, final-escape — теперь подмешивают
state.errors через returnFormState. Ветка save=undefined (hint-return)
осознанно оставлена без errors (юзер ещё не принял решение).

filterList: simple search, advanced search — закрывают R1/R2.
unfilterList: selective (field) + clear-all — аналогично.

Phase 1 / C2 из плана upload/returnFormState-audit.md. Точечный регресс зелёный
(02-crud, 06-document, 09-filter).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Nick Shirokov
2026-05-27 12:21:00 +03:00
parent 280df54fa6
commit a381fca0a1
2 changed files with 12 additions and 24 deletions
@@ -1,10 +1,11 @@
// web-test forms/close v1.17 — Close current form via Escape, handle save-changes confirmation. // web-test forms/close v1.18 — Close current form via Escape, handle save-changes confirmation.
// Source: https://github.com/Nikolay-Shirokov/cc-1c-skills // Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
import { page, recorder, ensureConnected } from '../core/state.mjs'; import { page, recorder, ensureConnected } from '../core/state.mjs';
import { detectFormScript } from '../../dom.mjs'; import { detectFormScript } from '../../dom.mjs';
import { dismissPendingErrors, checkForErrors, detectPlatformDialogs, closePlatformDialogs } from '../core/errors.mjs'; import { dismissPendingErrors, checkForErrors, detectPlatformDialogs, closePlatformDialogs } from '../core/errors.mjs';
import { waitForStable } from '../core/wait.mjs'; import { waitForStable } from '../core/wait.mjs';
import { returnFormState } from '../core/helpers.mjs';
import { getFormState } from './state.mjs'; import { getFormState } from './state.mjs';
/** /**
@@ -23,10 +24,7 @@ export async function closeForm({ save } = {}) {
if (pd.length) { if (pd.length) {
await closePlatformDialogs(); await closePlatformDialogs();
await page.waitForTimeout(300); await page.waitForTimeout(300);
const state = await getFormState(); return returnFormState({ closed: true, closedPlatformDialogs: pd });
state.closed = true;
state.closedPlatformDialogs = pd;
return state;
} }
const beforeForm = await page.evaluate(detectFormScript()); const beforeForm = await page.evaluate(detectFormScript());
await page.keyboard.press('Escape'); await page.keyboard.press('Escape');
@@ -47,14 +45,12 @@ export async function closeForm({ save } = {}) {
break; break;
} }
} }
const afterState = await getFormState(); const afterForm = await page.evaluate(detectFormScript());
afterState.closed = afterState.form !== beforeForm; return returnFormState({ closed: afterForm !== beforeForm });
return afterState;
} }
state.confirmation = err.confirmation; state.confirmation = err.confirmation;
state.hint = 'Confirmation dialog shown. Click "Да" to confirm or "Нет" to cancel'; state.hint = 'Confirmation dialog shown. Click "Да" to confirm or "Нет" to cancel';
return state; return state;
} }
state.closed = state.form !== beforeForm; return returnFormState({ closed: state.form !== beforeForm });
return state;
} }
@@ -1,4 +1,4 @@
// web-test table/filter v1.18 — filterList / unfilterList — simple search + advanced-column filter badges. // web-test table/filter v1.19 — filterList / unfilterList — simple search + advanced-column filter badges.
// Source: https://github.com/Nikolay-Shirokov/cc-1c-skills // Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
import { page, ensureConnected, normYo, highlightMode, ACTION_WAIT } from '../core/state.mjs'; import { page, ensureConnected, normYo, highlightMode, ACTION_WAIT } from '../core/state.mjs';
@@ -12,7 +12,7 @@ import {
import { dismissPendingErrors, checkForErrors } from '../core/errors.mjs'; import { dismissPendingErrors, checkForErrors } from '../core/errors.mjs';
import { waitForStable, waitForCondition } from '../core/wait.mjs'; import { waitForStable, waitForCondition } from '../core/wait.mjs';
import { highlight, unhighlight } from '../recording/highlight.mjs'; import { highlight, unhighlight } from '../recording/highlight.mjs';
import { safeClick } from '../core/helpers.mjs'; import { safeClick, returnFormState } from '../core/helpers.mjs';
import { selectValue, fillReferenceField } from '../forms/select-value.mjs'; import { selectValue, fillReferenceField } from '../forms/select-value.mjs';
import { pasteText } from '../core/clipboard.mjs'; import { pasteText } from '../core/clipboard.mjs';
import { getFormState } from '../forms/state.mjs'; import { getFormState } from '../forms/state.mjs';
@@ -51,9 +51,7 @@ export async function filterList(text, { field, exact } = {}) {
await page.keyboard.press('Enter'); await page.keyboard.press('Enter');
await waitForStable(formNum); await waitForStable(formNum);
const state = await getFormState(); return returnFormState({ filtered: { type: 'search', text } });
state.filtered = { type: 'search', text };
return state;
} }
// No search input — Ctrl+F opens advanced search on such forms. // No search input — Ctrl+F opens advanced search on such forms.
@@ -191,9 +189,7 @@ export async function filterList(text, { field, exact } = {}) {
} }
await waitForStable(formNum); await waitForStable(formNum);
const state = await getFormState(); return returnFormState({ filtered: { type: 'advanced', field, text, exact: !!exact } });
state.filtered = { type: 'advanced', field, text, exact: !!exact };
return state;
} }
/** /**
@@ -219,9 +215,7 @@ export async function unfilterList({ field } = {}) {
await page.mouse.click(closeBtn.x, closeBtn.y); await page.mouse.click(closeBtn.x, closeBtn.y);
await waitForStable(formNum); await waitForStable(formNum);
const state = await getFormState(); return returnFormState({ unfiltered: { field: closeBtn.field } });
state.unfiltered = { field: closeBtn.field };
return state;
} }
// --- Clear ALL filters --- // --- Clear ALL filters ---
@@ -250,7 +244,5 @@ export async function unfilterList({ field } = {}) {
await waitForStable(formNum); await waitForStable(formNum);
} }
const state = await getFormState(); return returnFormState({ unfiltered: true });
state.unfiltered = true;
return state;
} }