chore(tests): refactor migration form test (#7374)

Ref https://codeberg.org/forgejo/forgejo/pulls/7373.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7374
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
0ko 2025-03-29 09:06:03 +00:00
parent 49ea851da9
commit bf8bdf12df

View file

@ -1,9 +1,10 @@
// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: GPL-3.0-or-later
package integration
import (
"fmt"
"net/http"
"testing"
@ -13,92 +14,78 @@ import (
"github.com/stretchr/testify/assert"
)
// TestRepoMigrationUI is used to test various form properties of different migration types
func TestRepoMigrationUI(t *testing.T) {
defer tests.PrepareTestEnv(t)()
sessionUser1 := loginUser(t, "user1")
// Nothing is tested in plain Git migration form right now
testRepoMigrationFormGitHub(t, sessionUser1)
testRepoMigrationFormGitea(t, sessionUser1)
testRepoMigrationFormGitLab(t, sessionUser1)
testRepoMigrationFormGogs(t, sessionUser1)
testRepoMigrationFormOneDev(t, sessionUser1)
testRepoMigrationFormGitBucket(t, sessionUser1)
testRepoMigrationFormCodebase(t, sessionUser1)
testRepoMigrationFormForgejo(t, sessionUser1)
}
session := loginUser(t, "user1")
// Note: nothing is tested in plain Git migration form right now
func testRepoMigrationFormGitHub(t *testing.T, session *TestSession) {
response := session.MakeRequest(t, NewRequest(t, "GET", "/repo/migrate?service_type=2"), http.StatusOK)
page := NewHTMLParser(t, response.Body)
type Migration struct {
Name string
ExpectedItems []string
DescriptionHasPlaceholder bool
}
items := page.Find("#migrate_items .field .checkbox input")
expectedItems := []string{"issues", "pull_requests", "labels", "milestones", "releases"}
testRepoMigrationFormItems(t, items, expectedItems)
}
migrations := map[int]Migration{
2: {
"GitHub",
[]string{"issues", "pull_requests", "labels", "milestones", "releases"},
false,
},
3: {
"Gitea",
[]string{"issues", "pull_requests", "labels", "milestones", "releases"},
false,
},
4: {
"GitLab",
// Note: the checkbox "Merge requests" has name "pull_requests"
[]string{"issues", "pull_requests", "labels", "milestones", "releases"},
false,
},
5: {
"Gogs",
[]string{"issues", "labels", "milestones"},
false,
},
6: {
"OneDev",
[]string{"issues", "pull_requests", "labels", "milestones"},
false,
},
7: {
"GitBucket",
[]string{"issues", "pull_requests", "labels", "milestones", "releases"},
false,
},
8: {
"Codebase",
// Note: the checkbox "Merge requests" has name "pull_requests"
[]string{"issues", "pull_requests", "labels", "milestones"},
false,
},
9: {
"Forgejo",
[]string{"issues", "pull_requests", "labels", "milestones", "releases"},
false,
},
}
func testRepoMigrationFormGitea(t *testing.T, session *TestSession) {
response := session.MakeRequest(t, NewRequest(t, "GET", "/repo/migrate?service_type=3"), http.StatusOK)
page := NewHTMLParser(t, response.Body)
for id, migration := range migrations {
t.Run(migration.Name, func(t *testing.T) {
response := session.MakeRequest(t, NewRequest(t, "GET", fmt.Sprintf("/repo/migrate?service_type=%d", id)), http.StatusOK)
page := NewHTMLParser(t, response.Body)
items := page.Find("#migrate_items .field .checkbox input")
expectedItems := []string{"issues", "pull_requests", "labels", "milestones", "releases"}
testRepoMigrationFormItems(t, items, expectedItems)
}
items := page.Find("#migrate_items .field .checkbox input")
testRepoMigrationFormItems(t, items, migration.ExpectedItems)
func testRepoMigrationFormGitLab(t *testing.T, session *TestSession) {
response := session.MakeRequest(t, NewRequest(t, "GET", "/repo/migrate?service_type=4"), http.StatusOK)
page := NewHTMLParser(t, response.Body)
descriptionInput := page.Find("#description")
assert.Equal(t, 1, descriptionInput.Length())
items := page.Find("#migrate_items .field .checkbox input")
// Note: the checkbox "Merge requests" has name "pull_requests"
expectedItems := []string{"issues", "pull_requests", "labels", "milestones", "releases"}
testRepoMigrationFormItems(t, items, expectedItems)
}
func testRepoMigrationFormGogs(t *testing.T, session *TestSession) {
response := session.MakeRequest(t, NewRequest(t, "GET", "/repo/migrate?service_type=5"), http.StatusOK)
page := NewHTMLParser(t, response.Body)
items := page.Find("#migrate_items .field .checkbox input")
expectedItems := []string{"issues", "labels", "milestones"}
testRepoMigrationFormItems(t, items, expectedItems)
}
func testRepoMigrationFormOneDev(t *testing.T, session *TestSession) {
response := session.MakeRequest(t, NewRequest(t, "GET", "/repo/migrate?service_type=6"), http.StatusOK)
page := NewHTMLParser(t, response.Body)
items := page.Find("#migrate_items .field .checkbox input")
expectedItems := []string{"issues", "pull_requests", "labels", "milestones"}
testRepoMigrationFormItems(t, items, expectedItems)
}
func testRepoMigrationFormGitBucket(t *testing.T, session *TestSession) {
response := session.MakeRequest(t, NewRequest(t, "GET", "/repo/migrate?service_type=7"), http.StatusOK)
page := NewHTMLParser(t, response.Body)
items := page.Find("#migrate_items .field .checkbox input")
expectedItems := []string{"issues", "pull_requests", "labels", "milestones", "releases"}
testRepoMigrationFormItems(t, items, expectedItems)
}
func testRepoMigrationFormCodebase(t *testing.T, session *TestSession) {
response := session.MakeRequest(t, NewRequest(t, "GET", "/repo/migrate?service_type=8"), http.StatusOK)
page := NewHTMLParser(t, response.Body)
items := page.Find("#migrate_items .field .checkbox input")
// Note: the checkbox "Merge requests" has name "pull_requests"
expectedItems := []string{"issues", "pull_requests", "labels", "milestones"}
testRepoMigrationFormItems(t, items, expectedItems)
}
func testRepoMigrationFormForgejo(t *testing.T, session *TestSession) {
response := session.MakeRequest(t, NewRequest(t, "GET", "/repo/migrate?service_type=9"), http.StatusOK)
page := NewHTMLParser(t, response.Body)
items := page.Find("#migrate_items .field .checkbox input")
expectedItems := []string{"issues", "pull_requests", "labels", "milestones", "releases"}
testRepoMigrationFormItems(t, items, expectedItems)
_, descriptionHasPlaceholder := descriptionInput.Attr("placeholder")
assert.Equal(t, migration.DescriptionHasPlaceholder, descriptionHasPlaceholder)
})
}
}
func testRepoMigrationFormItems(t *testing.T, items *goquery.Selection, expectedItems []string) {