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