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

View all

  • [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)

graph LR detectSubmitActions["detectSubmitActions"] buildQuickSelector["buildQuickSelector"] extractSmartSelectors["extractSmartSelectors"] detectSubmitActions -->|calls| buildQuickSelector detectSubmitActions -->|calls| extractSmartSelectors style detectSubmitActions fill:#dbeafe,stroke:#2563eb,stroke-width:2px click detectSubmitActions "b33db39bc3e0f928.html" click buildQuickSelector "077a2e134af1a6be.html" click extractSmartSelectors "6f96c46b2e3fc740.html"
TargetType
buildQuickSelector calls
extractSmartSelectors calls

Impact (Incoming)

graph LR detectSubmitActions["detectSubmitActions"] FillableElement["FillableElement"] makeField["makeField"] FillableElement -->|uses| detectSubmitActions makeField -->|uses| detectSubmitActions style detectSubmitActions fill:#dbeafe,stroke:#2563eb,stroke-width:2px click detectSubmitActions "b33db39bc3e0f928.html" click FillableElement "2ecf5aaac3f668a8.html" click makeField "48507f7d1379ed8e.html"
SourceType
FillableElement uses
makeField uses