detectSubmitActions function exported ✓ 100.0%
Last updated: 2026-03-01T23:25:47.080Z
Metrics
LOC: 79
Complexity: 12
Params: 0
Coverage: 100.0% (21/21 lines, 13x executed)
Signature
detectSubmitActions(): : CapturedAction[]
Summary
Detects submit buttons within or near the given form fields. Looks for: button[type=submit], input[type=submit], button with submit-like text.
Architecture violations
- [warning] max-cyclomatic-complexity: 'detectSubmitActions' has cyclomatic complexity 12 (max 10)
Source Code
export function detectSubmitActions(): CapturedAction[] {
const submitActions: CapturedAction[] = [];
const seen = new Set<Element>();
// 1. Explicit submit buttons/inputs
const submitElements = document.querySelectorAll(
'button[type="submit"], input[type="submit"]',
);
for (const el of submitElements) {
if (seen.has(el)) continue;
seen.add(el);
const label =
el instanceof HTMLInputElement
? el.value || "Submit"
: el.textContent?.trim() || "Submit";
submitActions.push({
selector: buildQuickSelector(el),
smartSelectors: extractSmartSelectors(el),
value: "",
actionType: "click",
label,
});
}
// 2. Buttons without explicit type inside forms (default to submit)
const forms = document.querySelectorAll("form");
for (const form of forms) {
const buttons = form.querySelectorAll(
"button:not([type]), button[type='submit']",
);
for (const btn of buttons) {
if (seen.has(btn)) continue;
seen.add(btn);
const label = btn.textContent?.trim() || "Submit";
const text = label.toLowerCase();
// Only capture buttons that look like submit actions
const submitKeywords = [
"submit",
"enviar",
"salvar",
"save",
"send",
"cadastrar",
"register",
"login",
"entrar",
"sign",
"criar",
"create",
"confirm",
"confirmar",
"next",
"próximo",
"continuar",
"continue",
];
if (
submitKeywords.some((kw) => text.includes(kw)) ||
!btn.getAttribute("type")
) {
submitActions.push({
selector: buildQuickSelector(btn),
smartSelectors: extractSmartSelectors(btn),
value: "",
actionType: "click",
label,
});
}
}
}
return submitActions;
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| buildQuickSelector | calls |
| extractSmartSelectors | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| FillableElement | uses |
| makeField | uses |