forgejo/tests/integration/repo_migration_ui_test.go
Mat 8df8381f51
Some checks are pending
/ 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
feat(ui/migrations): add placeholder to clarify empty description behavior (#7373)
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7373
Reviewed-by: 0ko <0ko@noreply.codeberg.org>
Co-authored-by: Mat <m.falkowski@dotmat.de>
Co-committed-by: Mat <m.falkowski@dotmat.de>
2025-03-29 10:21:07 +00:00

103 lines
2.7 KiB
Go

// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: GPL-3.0-or-later
package integration
import (
"fmt"
"net/http"
"testing"
"forgejo.org/tests"
"github.com/PuerkitoBio/goquery"
"github.com/stretchr/testify/assert"
)
// TestRepoMigrationUI is used to test various form properties of different migration types
func TestRepoMigrationUI(t *testing.T) {
defer tests.PrepareTestEnv(t)()
session := loginUser(t, "user1")
// Note: nothing is tested in plain Git migration form right now
type Migration struct {
Name string
ExpectedItems []string
DescriptionHasPlaceholder bool
}
migrations := map[int]Migration{
2: {
"GitHub",
[]string{"issues", "pull_requests", "labels", "milestones", "releases"},
true,
},
3: {
"Gitea",
[]string{"issues", "pull_requests", "labels", "milestones", "releases"},
true,
},
4: {
"GitLab",
// Note: the checkbox "Merge requests" has name "pull_requests"
[]string{"issues", "pull_requests", "labels", "milestones", "releases"},
true,
},
5: {
"Gogs",
[]string{"issues", "labels", "milestones"},
true,
},
6: {
"OneDev",
[]string{"issues", "pull_requests", "labels", "milestones"},
true,
},
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"},
true,
},
9: {
"Forgejo",
[]string{"issues", "pull_requests", "labels", "milestones", "releases"},
true,
},
}
for id, migration := range migrations {
t.Run(migration.Name, func(t *testing.T) {
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")
testRepoMigrationFormItems(t, items, migration.ExpectedItems)
descriptionInput := page.Find("#description")
assert.Equal(t, 1, descriptionInput.Length())
_, descriptionHasPlaceholder := descriptionInput.Attr("placeholder")
assert.Equal(t, migration.DescriptionHasPlaceholder, descriptionHasPlaceholder)
})
}
}
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)
}
}