package web
import (
"strings"
"testing"
)
// One press, one post. A composer's submit button stayed live while
// the request was in flight, so a slow page took a second tap as a
// second comment: two identical posts, seconds apart, on the same
// ticket. The guard ships in the composer asset, which every page
// carrying a composer loads.
func TestComposerRefusesASecondPress(t *testing.T) {
js := string(composerOut)
for _, want := range []string{"submit", "disabled", "pageshow"} {
if !strings.Contains(js, want) {
t.Errorf("FAIL: the served composer script has no one-press guard: missing %q", want)
}
}
// The guard must not disable before the event is dispatched, or the
// pressed button's own name and value never reach the server — a
// ticket's "Comment & close" is exactly that.
if !strings.Contains(string(composerJS), "setTimeout") {
t.Error("FAIL: the guard disables synchronously and would drop the submitter's value")
}
t.Log("ok: a second press cannot post a second copy, and the back button restores the form")
}