summaryrefslogtreecommitdiffstats
path: root/tests/integration/repo_migration_ui_test.go
blob: 40688d4a603d06fb7fd0287c191c476bcbdbfbb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package integration

import (
	"net/http"
	"net/url"
	"testing"

	"github.com/PuerkitoBio/goquery"
	"github.com/stretchr/testify/assert"
)

func TestRepoMigrationUI(t *testing.T) {
	onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
		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.EqualValues(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.EqualValues(t, expectedName, name)
	}
}