Skip to content
quarry Artifact [8d634d416f]
Login

Artifact [8d634d416f]

Artifact 8d634d416f1de46c6f906bd3540721377387052eb34f36e6736400da06254aa7:


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")
}