loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

0ko bf8bdf12 49ea851d

+66 -79
+66 -79
tests/integration/repo_migration_ui_test.go
··· 1 1 // Copyright 2024 The Forgejo Authors. All rights reserved. 2 - // SPDX-License-Identifier: MIT 2 + // SPDX-License-Identifier: GPL-3.0-or-later 3 3 4 4 package integration 5 5 6 6 import ( 7 + "fmt" 7 8 "net/http" 8 9 "testing" 9 10 ··· 13 14 "github.com/stretchr/testify/assert" 14 15 ) 15 16 17 + // TestRepoMigrationUI is used to test various form properties of different migration types 16 18 func TestRepoMigrationUI(t *testing.T) { 17 19 defer tests.PrepareTestEnv(t)() 18 - sessionUser1 := loginUser(t, "user1") 19 - // Nothing is tested in plain Git migration form right now 20 - testRepoMigrationFormGitHub(t, sessionUser1) 21 - testRepoMigrationFormGitea(t, sessionUser1) 22 - testRepoMigrationFormGitLab(t, sessionUser1) 23 - testRepoMigrationFormGogs(t, sessionUser1) 24 - testRepoMigrationFormOneDev(t, sessionUser1) 25 - testRepoMigrationFormGitBucket(t, sessionUser1) 26 - testRepoMigrationFormCodebase(t, sessionUser1) 27 - testRepoMigrationFormForgejo(t, sessionUser1) 28 - } 20 + session := loginUser(t, "user1") 21 + // Note: nothing is tested in plain Git migration form right now 29 22 30 - func testRepoMigrationFormGitHub(t *testing.T, session *TestSession) { 31 - response := session.MakeRequest(t, NewRequest(t, "GET", "/repo/migrate?service_type=2"), http.StatusOK) 32 - page := NewHTMLParser(t, response.Body) 23 + type Migration struct { 24 + Name string 25 + ExpectedItems []string 26 + DescriptionHasPlaceholder bool 27 + } 33 28 34 - items := page.Find("#migrate_items .field .checkbox input") 35 - expectedItems := []string{"issues", "pull_requests", "labels", "milestones", "releases"} 36 - testRepoMigrationFormItems(t, items, expectedItems) 37 - } 29 + migrations := map[int]Migration{ 30 + 2: { 31 + "GitHub", 32 + []string{"issues", "pull_requests", "labels", "milestones", "releases"}, 33 + false, 34 + }, 35 + 3: { 36 + "Gitea", 37 + []string{"issues", "pull_requests", "labels", "milestones", "releases"}, 38 + false, 39 + }, 40 + 4: { 41 + "GitLab", 42 + // Note: the checkbox "Merge requests" has name "pull_requests" 43 + []string{"issues", "pull_requests", "labels", "milestones", "releases"}, 44 + false, 45 + }, 46 + 5: { 47 + "Gogs", 48 + []string{"issues", "labels", "milestones"}, 49 + false, 50 + }, 51 + 6: { 52 + "OneDev", 53 + []string{"issues", "pull_requests", "labels", "milestones"}, 54 + false, 55 + }, 56 + 7: { 57 + "GitBucket", 58 + []string{"issues", "pull_requests", "labels", "milestones", "releases"}, 59 + false, 60 + }, 61 + 8: { 62 + "Codebase", 63 + // Note: the checkbox "Merge requests" has name "pull_requests" 64 + []string{"issues", "pull_requests", "labels", "milestones"}, 65 + false, 66 + }, 67 + 9: { 68 + "Forgejo", 69 + []string{"issues", "pull_requests", "labels", "milestones", "releases"}, 70 + false, 71 + }, 72 + } 38 73 39 - func testRepoMigrationFormGitea(t *testing.T, session *TestSession) { 40 - response := session.MakeRequest(t, NewRequest(t, "GET", "/repo/migrate?service_type=3"), http.StatusOK) 41 - page := NewHTMLParser(t, response.Body) 42 - 43 - items := page.Find("#migrate_items .field .checkbox input") 44 - expectedItems := []string{"issues", "pull_requests", "labels", "milestones", "releases"} 45 - testRepoMigrationFormItems(t, items, expectedItems) 46 - } 47 - 48 - func testRepoMigrationFormGitLab(t *testing.T, session *TestSession) { 49 - response := session.MakeRequest(t, NewRequest(t, "GET", "/repo/migrate?service_type=4"), http.StatusOK) 50 - page := NewHTMLParser(t, response.Body) 51 - 52 - items := page.Find("#migrate_items .field .checkbox input") 53 - // Note: the checkbox "Merge requests" has name "pull_requests" 54 - expectedItems := []string{"issues", "pull_requests", "labels", "milestones", "releases"} 55 - testRepoMigrationFormItems(t, items, expectedItems) 56 - } 57 - 58 - func testRepoMigrationFormGogs(t *testing.T, session *TestSession) { 59 - response := session.MakeRequest(t, NewRequest(t, "GET", "/repo/migrate?service_type=5"), http.StatusOK) 60 - page := NewHTMLParser(t, response.Body) 61 - 62 - items := page.Find("#migrate_items .field .checkbox input") 63 - expectedItems := []string{"issues", "labels", "milestones"} 64 - testRepoMigrationFormItems(t, items, expectedItems) 65 - } 66 - 67 - func testRepoMigrationFormOneDev(t *testing.T, session *TestSession) { 68 - response := session.MakeRequest(t, NewRequest(t, "GET", "/repo/migrate?service_type=6"), http.StatusOK) 69 - page := NewHTMLParser(t, response.Body) 70 - 71 - items := page.Find("#migrate_items .field .checkbox input") 72 - expectedItems := []string{"issues", "pull_requests", "labels", "milestones"} 73 - testRepoMigrationFormItems(t, items, expectedItems) 74 - } 75 - 76 - func testRepoMigrationFormGitBucket(t *testing.T, session *TestSession) { 77 - response := session.MakeRequest(t, NewRequest(t, "GET", "/repo/migrate?service_type=7"), http.StatusOK) 78 - page := NewHTMLParser(t, response.Body) 79 - 80 - items := page.Find("#migrate_items .field .checkbox input") 81 - expectedItems := []string{"issues", "pull_requests", "labels", "milestones", "releases"} 82 - testRepoMigrationFormItems(t, items, expectedItems) 83 - } 74 + for id, migration := range migrations { 75 + t.Run(migration.Name, func(t *testing.T) { 76 + response := session.MakeRequest(t, NewRequest(t, "GET", fmt.Sprintf("/repo/migrate?service_type=%d", id)), http.StatusOK) 77 + page := NewHTMLParser(t, response.Body) 84 78 85 - func testRepoMigrationFormCodebase(t *testing.T, session *TestSession) { 86 - response := session.MakeRequest(t, NewRequest(t, "GET", "/repo/migrate?service_type=8"), http.StatusOK) 87 - page := NewHTMLParser(t, response.Body) 88 - 89 - items := page.Find("#migrate_items .field .checkbox input") 90 - // Note: the checkbox "Merge requests" has name "pull_requests" 91 - expectedItems := []string{"issues", "pull_requests", "labels", "milestones"} 92 - testRepoMigrationFormItems(t, items, expectedItems) 93 - } 79 + items := page.Find("#migrate_items .field .checkbox input") 80 + testRepoMigrationFormItems(t, items, migration.ExpectedItems) 94 81 95 - func testRepoMigrationFormForgejo(t *testing.T, session *TestSession) { 96 - response := session.MakeRequest(t, NewRequest(t, "GET", "/repo/migrate?service_type=9"), http.StatusOK) 97 - page := NewHTMLParser(t, response.Body) 82 + descriptionInput := page.Find("#description") 83 + assert.Equal(t, 1, descriptionInput.Length()) 98 84 99 - items := page.Find("#migrate_items .field .checkbox input") 100 - expectedItems := []string{"issues", "pull_requests", "labels", "milestones", "releases"} 101 - testRepoMigrationFormItems(t, items, expectedItems) 85 + _, descriptionHasPlaceholder := descriptionInput.Attr("placeholder") 86 + assert.Equal(t, migration.DescriptionHasPlaceholder, descriptionHasPlaceholder) 87 + }) 88 + } 102 89 } 103 90 104 91 func testRepoMigrationFormItems(t *testing.T, items *goquery.Selection, expectedItems []string) {