forgejo/tests/integration/repo_migration_ui_test.go
Renovate Bot fed2d81c44
Some checks failed
/ release (push) Waiting to run
testing / backend-checks (push) Has been skipped
testing / frontend-checks (push) Has been skipped
testing / test-unit (push) Has been skipped
testing / test-e2e (push) Has been skipped
testing / test-mysql (push) Has been skipped
testing / test-pgsql (push) Has been skipped
testing / test-sqlite (push) Has been skipped
testing / test-remote-cacher (redis) (push) Has been skipped
testing / test-remote-cacher (valkey) (push) Has been skipped
testing / test-remote-cacher (garnet) (push) Has been skipped
testing / test-remote-cacher (redict) (push) Has been skipped
testing / security-check (push) Has been skipped
Integration tests for the release process / release-simulation (push) Has been cancelled
Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367)
Co-authored-by: Renovate Bot <forgejo-renovate-action@forgejo.org>
Co-committed-by: Renovate Bot <forgejo-renovate-action@forgejo.org>
2025-03-28 22:22:21 +00:00

116 lines
4.6 KiB
Go

// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package integration
import (
"net/http"
"testing"
"forgejo.org/tests"
"github.com/PuerkitoBio/goquery"
"github.com/stretchr/testify/assert"
)
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)
}
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)
items := page.Find("#migrate_items .field .checkbox input")
expectedItems := []string{"issues", "pull_requests", "labels", "milestones", "releases"}
testRepoMigrationFormItems(t, items, expectedItems)
}
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)
items := page.Find("#migrate_items .field .checkbox input")
expectedItems := []string{"issues", "pull_requests", "labels", "milestones", "releases"}
testRepoMigrationFormItems(t, items, 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)
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)
}
func testRepoMigrationFormItems(t *testing.T, items *goquery.Selection, expectedItems []string) {
t.Helper()
// Compare lengths of item lists
assert.Equal(t, len(expectedItems), items.Length())
// Compare contents of item lists
for index, expectedName := range expectedItems {
name, exists := items.Eq(index).Attr("name")
assert.True(t, exists)
assert.Equal(t, expectedName, name)
}
}