From 2ad377130bf517f41f9ce0beacc515e02d0c6682 Mon Sep 17 00:00:00 2001 From: 0ko <0ko@noreply.codeberg.org> Date: Sat, 27 Jul 2024 16:35:48 +0500 Subject: [PATCH] ui: refactor repo migration items --- templates/repo/migrate/codebase.tmpl | 22 ++-- templates/repo/migrate/gitbucket.tmpl | 18 ++- templates/repo/migrate/gitea.tmpl | 18 ++- templates/repo/migrate/github.tmpl | 18 ++- templates/repo/migrate/gitlab.tmpl | 18 ++- templates/repo/migrate/gogs.tmpl | 11 +- templates/repo/migrate/onedev.tmpl | 22 ++-- tests/integration/repo_migration_ui_test.go | 116 ++++++++++++++++++++ 8 files changed, 199 insertions(+), 44 deletions(-) create mode 100644 tests/integration/repo_migration_ui_test.go diff --git a/templates/repo/migrate/codebase.tmpl b/templates/repo/migrate/codebase.tmpl index 1b5e84067e..cf46c8daf3 100644 --- a/templates/repo/migrate/codebase.tmpl +++ b/templates/repo/migrate/codebase.tmpl @@ -34,9 +34,19 @@
- - + +
+
+
+ +
+ + +
+
+
+
@@ -45,12 +55,8 @@
- - -
-
- - + +
diff --git a/templates/repo/migrate/gitbucket.tmpl b/templates/repo/migrate/gitbucket.tmpl index 6d671777a4..e8d6b60dea 100644 --- a/templates/repo/migrate/gitbucket.tmpl +++ b/templates/repo/migrate/gitbucket.tmpl @@ -42,10 +42,6 @@ {{ctx.Locale.Tr "repo.migrate.migrate_items_options"}}
-
- - -
@@ -57,9 +53,12 @@
+
+
+
- - + +
@@ -69,6 +68,13 @@
+
+ +
+ + +
+
diff --git a/templates/repo/migrate/gitea.tmpl b/templates/repo/migrate/gitea.tmpl index 20d85c27c7..2f40d58bec 100644 --- a/templates/repo/migrate/gitea.tmpl +++ b/templates/repo/migrate/gitea.tmpl @@ -38,10 +38,6 @@ {{ctx.Locale.Tr "repo.migrate.migrate_items_options"}}
-
- - -
@@ -53,9 +49,12 @@
+
+
+
- - + +
@@ -65,6 +64,13 @@
+
+ +
+ + +
+
diff --git a/templates/repo/migrate/github.tmpl b/templates/repo/migrate/github.tmpl index 6e801b8c1d..91c1a272c7 100644 --- a/templates/repo/migrate/github.tmpl +++ b/templates/repo/migrate/github.tmpl @@ -40,10 +40,6 @@ {{ctx.Locale.Tr "repo.migrate.migrate_items_options"}}
-
- - -
@@ -55,9 +51,12 @@
+
+
+
- - + +
@@ -67,6 +66,13 @@
+
+ +
+ + +
+
diff --git a/templates/repo/migrate/gitlab.tmpl b/templates/repo/migrate/gitlab.tmpl index 164578222e..d93a00104a 100644 --- a/templates/repo/migrate/gitlab.tmpl +++ b/templates/repo/migrate/gitlab.tmpl @@ -37,10 +37,6 @@ {{ctx.Locale.Tr "repo.migrate.migrate_items_options"}}
-
- - -
@@ -52,9 +48,12 @@
+
+
+
- - + +
@@ -64,6 +63,13 @@
+
+ +
+ + +
+
diff --git a/templates/repo/migrate/gogs.tmpl b/templates/repo/migrate/gogs.tmpl index 312a4e9e9a..6c647be0ed 100644 --- a/templates/repo/migrate/gogs.tmpl +++ b/templates/repo/migrate/gogs.tmpl @@ -38,15 +38,18 @@ {{ctx.Locale.Tr "repo.migrate.migrate_items_options"}}
-
- - -
+
+ +
+ + +
+
diff --git a/templates/repo/migrate/onedev.tmpl b/templates/repo/migrate/onedev.tmpl index a5a216c6ec..ec155555d0 100644 --- a/templates/repo/migrate/onedev.tmpl +++ b/templates/repo/migrate/onedev.tmpl @@ -34,9 +34,19 @@
- - + +
+
+
+ +
+ + +
+
+
+
@@ -45,12 +55,8 @@
- - -
-
- - + +
diff --git a/tests/integration/repo_migration_ui_test.go b/tests/integration/repo_migration_ui_test.go new file mode 100644 index 0000000000..40688d4a60 --- /dev/null +++ b/tests/integration/repo_migration_ui_test.go @@ -0,0 +1,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) + } +}