diff --git a/internal/web/uploads_spots_handler_test.go b/internal/web/uploads_spots_handler_test.go new file mode 100644 index 0000000..fd2e44a --- /dev/null +++ b/internal/web/uploads_spots_handler_test.go @@ -0,0 +1,72 @@ +package web_test + +import ( + "fmt" + "strings" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// The stored judged spots include the ones the model kept as the base (ADR-035), for a +// later evaluation. The page lists only the ones a reader should check: changed and +// uncertain. + +func TestUploadStatus_OnlyChangedAndUncertainSpotsAreListedNotTheKeptOnes(t *testing.T) { + app, _ := newUploadApp(t, audioOK, 200<<20) + id := seedUpload(t, userID, "m", "done", "Synthetic transcript.") + setReconciliation(t, id, `{"status":"reconciled","base":"a","alt":"b","reconciler":"c","disputes":3,"adjudicated":3,"changed":1,"unsure":1, + "contested":[ + {"seconds":60,"base":"CHANGEDBASE","alt":"CHANGEDALT","used":"alt","unsure":false}, + {"seconds":120,"base":"KEPTBASE","alt":"KEPTALT","used":"base","unsure":false}, + {"seconds":180,"base":"UNSUREBASE","alt":"UNSUREALT","used":"base","unsure":true}]}`) + + b := body(t, do(t, app, get("/uploads/"+id+"/status"))) + + assert.Contains(t, b, "CHANGEDBASE") + assert.Contains(t, b, "UNSUREALT") + assert.NotContains(t, b, "KEPTBASE", "a spot the model confidently kept is not one for the reader to check") + assert.NotContains(t, b, "KEPTALT") +} + +func TestUploadStatus_TheMoreCountIgnoresKeptSpotsAndMatchesTheListedKind(t *testing.T) { + app, _ := newUploadApp(t, audioOK, 200<<20) + id := seedUpload(t, userID, "m", "done", "Synthetic transcript.") + var spots []string + for i := 0; i < 60; i++ { + spots = append(spots, fmt.Sprintf(`{"seconds":%d,"base":"b%d","alt":"a%d","used":"alt","unsure":false}`, i*10, i, i)) + spots = append(spots, fmt.Sprintf(`{"seconds":%d,"base":"k%d","alt":"j%d","used":"base","unsure":false}`, i*10+5, i, i)) + } + setReconciliation(t, id, `{"status":"reconciled","base":"a","alt":"b","reconciler":"c","disputes":400,"changed":60,"contested":[`+strings.Join(spots, ",")+`]}`) + + b := body(t, do(t, app, get("/uploads/"+id+"/status"))) + + assert.Contains(t, b, "10 more", "60 changed, 50 shown: the 60 kept ones do not count") + assert.NotContains(t, b, ">k0<") +} + +func TestUploadStatus_WhenNothingNeedsCheckingThereIsNoSpotsSection(t *testing.T) { + app, _ := newUploadApp(t, audioOK, 200<<20) + id := seedUpload(t, userID, "m", "done", "Synthetic transcript.") + setReconciliation(t, id, `{"status":"reconciled","base":"a","alt":"b","reconciler":"c","disputes":1,"adjudicated":1, + "contested":[{"seconds":60,"base":"KEPTBASE","alt":"KEPTALT","used":"base","unsure":false}]}`) + + b := body(t, do(t, app, get("/uploads/"+id+"/status"))) + + require.Contains(t, b, "Reconciled from two transcripts") + assert.NotContains(t, b, "Spots to check", "an empty list would invite checking nothing") +} + +func TestUploadStatus_ASpotShowsTheWordsJustBeforeIt(t *testing.T) { + app, _ := newUploadApp(t, audioOK, 200<<20) + id := seedUpload(t, userID, "m", "done", "Synthetic transcript.") + setReconciliation(t, id, `{"status":"reconciled","base":"a","alt":"b","reconciler":"c","disputes":1,"changed":1, + "contested":[{"seconds":2640,"base":"special","alt":"CAMT","used":"alt","unsure":false,"before":"vi skickar in ett"}]}`) + + b := body(t, do(t, app, get("/uploads/"+id+"/status"))) + + assert.Contains(t, b, "vi skickar in ett", "the words before the spot are how a reader finds it in the audio") + assert.Contains(t, b, "special") + assert.Contains(t, b, "CAMT") +}