mirror of
https://github.com/Nikolay-Shirokov/cc-1c-skills.git
synced 2026-07-20 01:20:59 +03:00
refactor(web-test): этап B.5.5 — ввести returnFormState (выборочно применить)
core/helpers.mjs: returnFormState(extras) — стандартный хвост action-функций: getFormState + Object.assign(extras) + checkForErrors → state.errors. Унифицирует ~15 hand-written копий и закрывает R1/R2/R3 (state.errors теперь добавляется автоматически у любого пользователя хелпера). В этом коммите конвертированы только 2 простейших P1-сайта (openCommand, второй handle в navigateLink) — без extras между getFormState и err-проверкой. Остальные 30+ сайтов сложнее (state.X между, разные return-shape, wrapped fillFields) — будут мигрированы органически при переносе clickElement/ selectValue/closeForm в forms/* на этапе C. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
e215957344
commit
9ac0cb3b87
@@ -3,7 +3,8 @@
|
||||
// Source: https://github.com/Nikolay-Shirokov/cc-1c-skills
|
||||
|
||||
import { page } from './state.mjs';
|
||||
import { dismissPendingErrors } from './errors.mjs';
|
||||
import { dismissPendingErrors, checkForErrors } from './errors.mjs';
|
||||
import { getFormState } from '../browser.mjs';
|
||||
|
||||
/**
|
||||
* page.click with the standard "intercepts pointer events" retry ladder:
|
||||
@@ -105,3 +106,23 @@ export async function readEdd() {
|
||||
};
|
||||
})()`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard "tail" of action functions: fetch current form state, attach
|
||||
* caller-specified extras (e.g. `{ clicked: {...} }`) and the result of
|
||||
* `checkForErrors()` if any. Returns the flat state object.
|
||||
*
|
||||
* Unifies ~15 hand-written copies in clickElement, selectValue, closeForm,
|
||||
* navigation functions, etc. Also closes R1/R2/R3 from the refactor plan —
|
||||
* any caller using this helper gets `state.errors` for free.
|
||||
*
|
||||
* @param {object} [extras] — merged into the state object via Object.assign.
|
||||
* @returns {Promise<object>} form state (flat) with optional `errors`.
|
||||
*/
|
||||
export async function returnFormState(extras = {}) {
|
||||
const state = await getFormState();
|
||||
Object.assign(state, extras);
|
||||
const err = await checkForErrors();
|
||||
if (err) state.errors = err;
|
||||
return state;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user