test(actions): make TestFindFavLinks resilient to capture state
Asserts exactly one of fav/unfav is set with a well-formed URL, instead of hardcoding the +Fav direction. The previous test broke whenever the capturing account favourited the target submission. Also points the test at submission 12345678 (the documented default FA_TEST_SUB_ID) so it matches what TestRefreshFixtures captures by default.
This commit is contained in:
@@ -364,16 +364,25 @@ func TestFindFavLinks_RealFixture(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("read doc: %v", err)
|
||||
}
|
||||
// submission.html was captured for submission 65052636 (a "+Fav" page).
|
||||
favURL, unfavURL := findFavLinks(doc, 65052636)
|
||||
if favURL == "" {
|
||||
t.Error("findFavLinks: favURL empty +Fav anchor not found in real markup")
|
||||
}
|
||||
if !strings.Contains(favURL, "/fav/65052636/") || !strings.Contains(favURL, "key=") {
|
||||
t.Errorf("findFavLinks: favURL = %q; want a /fav/65052636/?key=... URL", favURL)
|
||||
}
|
||||
if unfavURL != "" {
|
||||
t.Errorf("findFavLinks: unfavURL = %q; want empty on a not-yet-faved page", unfavURL)
|
||||
// submission.html was captured for submission 12345678. FA renders either
|
||||
// a +Fav or a -Fav anchor depending on the capturing account's current
|
||||
// state never both, never neither (when authenticated). The test stays
|
||||
// direction-agnostic so it doesn't break when the capturing account
|
||||
// favourites/unfavourites this submission.
|
||||
favURL, unfavURL := findFavLinks(doc, 12345678)
|
||||
switch {
|
||||
case favURL == "" && unfavURL == "":
|
||||
t.Error("findFavLinks: both URLs empty fav/unfav anchor not found in real markup")
|
||||
case favURL != "" && unfavURL != "":
|
||||
t.Errorf("findFavLinks: both URLs set (fav=%q unfav=%q); expected exactly one", favURL, unfavURL)
|
||||
case favURL != "":
|
||||
if !strings.Contains(favURL, "/fav/12345678/") || !strings.Contains(favURL, "key=") {
|
||||
t.Errorf("findFavLinks: favURL = %q; want a /fav/12345678/?key=... URL", favURL)
|
||||
}
|
||||
case unfavURL != "":
|
||||
if !strings.Contains(unfavURL, "/unfav/12345678/") || !strings.Contains(unfavURL, "key=") {
|
||||
t.Errorf("findFavLinks: unfavURL = %q; want a /unfav/12345678/?key=... URL", unfavURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user