Skip to content
quarry Artifact [d0e7b9d16a]
Login

Artifact [d0e7b9d16a]

Artifact d0e7b9d16a471579127b12eb9a31d26d178078e2c00b8bbc04407c1dff5abe70:


package web

import (
	"bytes"
	"strings"
	"testing"
)

func renderResolve(t *testing.T, det *landingDetail) string {
	t.Helper()
	var b bytes.Buffer
	if err := noHooks.template(landingResolvePage).ExecuteTemplate(&b, "content", pageData{Repo: "alpha", Landing: det}); err != nil {
		t.Fatal(err)
	}
	return b.String()
}

// A conflicting landing's resolve page lists its files, each linking to
// its place in the three-pane merge, carries the merge itself and the
// checkout steps, and leads back to the record.
func TestResolvePageCarriesTheMergeAndItsFiles(t *testing.T) {
	m := buildMeld(meldFixture(), "/r/alpha")
	det := &landingDetail{landingRow: landingRow{ID: strings.Repeat("ab", 32), Number: 7, Branch: "work", Target: "trunk",
		State: "open", Title: "Rework the totals"}, Mergeable: "conflict", Meld: m}
	for _, f := range m.Files {
		det.Conflicts = append(det.Conflicts, f.Path)
	}
	h := renderResolve(t, det)
	for _, want := range []string{`data-hook="resolve-page" data-state="conflict"`, `data-hook="resolve-files"`,
		`href="#mf-` + m.Files[0].Path + `"`, `id="mf-` + m.Files[0].Path + `"`, `data-hook="meld"`,
		`data-hook="merge-steps"`, `data-hook="resolve-back"`, `href="/r/alpha/landing/abababababab"`} {
		if !strings.Contains(h, want) {
			t.Errorf("FAIL: the resolve page lacks %s", want)
		}
	}
}

// Nothing to resolve says so and offers the way back, with no editor.
func TestResolvePageWithNothingToResolve(t *testing.T) {
	h := renderResolve(t, &landingDetail{landingRow: landingRow{ID: strings.Repeat("cd", 32), Branch: "work", Target: "trunk",
		State: "open", Title: "Rework"}, Mergeable: "clean"})
	if strings.Contains(h, `data-hook="meld"`) || !strings.Contains(h, `data-hook="resolve-back"`) {
		t.Errorf("FAIL: a clean landing's resolve page is wrong:\n%.600s", h)
	}
}