diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 5f066beb2d..bce75a3031 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -55,11 +55,8 @@ webauthn_error_timeout = Timeout reached before your key could be read. Please r repository = Repository organization = Organization mirror = Mirror -new_repo = New repository -new_migrate = New migration new_mirror = New mirror new_fork = New repository fork -new_org = New organization new_project = New project new_project_column = New column admin_panel = Site administration @@ -68,6 +65,14 @@ your_profile = Profile your_starred = Starred your_settings = Settings +new_repo.title = New repository +new_migrate.title = New migration +new_org.title = New organization + +new_repo.link = New repository +new_migrate.link = New migration +new_org.link = New organization + all = All sources = Sources mirrors = Mirrors diff --git a/routers/web/org/org.go b/routers/web/org/org.go index f94dd16eae..dd3aab458b 100644 --- a/routers/web/org/org.go +++ b/routers/web/org/org.go @@ -26,7 +26,7 @@ const ( // Create render the page for create organization func Create(ctx *context.Context) { - ctx.Data["Title"] = ctx.Tr("new_org") + ctx.Data["Title"] = ctx.Tr("new_org.title") ctx.Data["DefaultOrgVisibilityMode"] = setting.Service.DefaultOrgVisibilityMode if !ctx.Doer.CanCreateOrganization() { ctx.ServerError("Not allowed", errors.New(ctx.Locale.TrString("org.form.create_org_not_allowed"))) @@ -38,7 +38,7 @@ func Create(ctx *context.Context) { // CreatePost response for create organization func CreatePost(ctx *context.Context) { form := *web.GetForm(ctx).(*forms.CreateOrgForm) - ctx.Data["Title"] = ctx.Tr("new_org") + ctx.Data["Title"] = ctx.Tr("new_org.title") if !ctx.Doer.CanCreateOrganization() { ctx.ServerError("Not allowed", errors.New(ctx.Locale.TrString("org.form.create_org_not_allowed"))) diff --git a/routers/web/repo/migrate.go b/routers/web/repo/migrate.go index 70113e50ec..0acf966bca 100644 --- a/routers/web/repo/migrate.go +++ b/routers/web/repo/migrate.go @@ -253,7 +253,7 @@ func MigratePost(ctx *context.Context) { } func setMigrationContextData(ctx *context.Context, serviceType structs.GitServiceType) { - ctx.Data["Title"] = ctx.Tr("new_migrate") + ctx.Data["Title"] = ctx.Tr("new_migrate.title") ctx.Data["LFSActive"] = setting.LFS.StartServer ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index 652738afda..9562491440 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -152,7 +152,7 @@ func getRepoPrivate(ctx *context.Context) bool { // Create render creating repository page func Create(ctx *context.Context) { - ctx.Data["Title"] = ctx.Tr("new_repo") + ctx.Data["Title"] = ctx.Tr("new_repo.title") // Give default value for template to render. ctx.Data["Gitignores"] = repo_module.Gitignores @@ -223,7 +223,7 @@ func handleCreateError(ctx *context.Context, owner *user_model.User, err error, // CreatePost response for creating repository func CreatePost(ctx *context.Context) { form := web.GetForm(ctx).(*forms.CreateRepoForm) - ctx.Data["Title"] = ctx.Tr("new_repo") + ctx.Data["Title"] = ctx.Tr("new_repo.title") ctx.Data["Gitignores"] = repo_module.Gitignores ctx.Data["LabelTemplateFiles"] = repo_module.LabelTemplateFiles diff --git a/templates/base/head_navbar.tmpl b/templates/base/head_navbar.tmpl index 068271bbe9..ba17222f9b 100644 --- a/templates/base/head_navbar.tmpl +++ b/templates/base/head_navbar.tmpl @@ -126,16 +126,16 @@ diff --git a/templates/org/create.tmpl b/templates/org/create.tmpl index 92be4a0adb..ad172ea990 100644 --- a/templates/org/create.tmpl +++ b/templates/org/create.tmpl @@ -5,7 +5,7 @@
{{.CsrfTokenHtml}}

- {{ctx.Locale.Tr "new_org"}} + {{ctx.Locale.Tr "new_org.title"}}

{{template "base/alert" .}} diff --git a/templates/org/home.tmpl b/templates/org/home.tmpl index e4d6b1954a..3ae5f01d04 100644 --- a/templates/org/home.tmpl +++ b/templates/org/home.tmpl @@ -22,9 +22,9 @@
{{if .CanCreateOrgRepo}}
diff --git a/templates/repo/create.tmpl b/templates/repo/create.tmpl index d3a11e7ed5..df4288a2f2 100644 --- a/templates/repo/create.tmpl +++ b/templates/repo/create.tmpl @@ -5,7 +5,7 @@ {{.CsrfTokenHtml}}

- {{ctx.Locale.Tr "new_repo"}} + {{ctx.Locale.Tr "new_repo.title"}}

{{template "base/alert" .}} diff --git a/tests/integration/migrate_test.go b/tests/integration/migrate_test.go index 949bcd47bb..123f975ca9 100644 --- a/tests/integration/migrate_test.go +++ b/tests/integration/migrate_test.go @@ -1,4 +1,5 @@ // Copyright 2021 The Gitea Authors. All rights reserved. +// Copyright 2024 The Forgejo Authors. All rights reserved. // SPDX-License-Identifier: MIT package integration @@ -20,6 +21,7 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/translation" "code.gitea.io/gitea/services/migrations" "code.gitea.io/gitea/services/repository" @@ -88,6 +90,10 @@ func TestMigrate(t *testing.T) { resp := session.MakeRequest(t, req, http.StatusOK) // Step 2: load the form htmlDoc := NewHTMLParser(t, resp.Body) + // Check form title + title := htmlDoc.doc.Find("title").Text() + assert.Contains(t, title, translation.NewLocale("en-US").TrString("new_migrate.title")) + // Get the link of migration button link, exists := htmlDoc.doc.Find(`form.ui.form[action^="/repo/migrate"]`).Attr("action") assert.True(t, exists, "The template has changed") // Step 4: submit the migration to only migrate issues diff --git a/tests/integration/new_org_test.go b/tests/integration/new_org_test.go new file mode 100644 index 0000000000..ec9f2f244c --- /dev/null +++ b/tests/integration/new_org_test.go @@ -0,0 +1,37 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package integration + +import ( + "net/http" + "net/url" + "strings" + "testing" + + "code.gitea.io/gitea/modules/translation" + + "github.com/stretchr/testify/assert" +) + +func TestNewOrganizationForm(t *testing.T) { + onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { + session := loginUser(t, "user1") + locale := translation.NewLocale("en-US") + + response := session.MakeRequest(t, NewRequest(t, "GET", "/org/create"), http.StatusOK) + page := NewHTMLParser(t, response.Body) + + // Verify page title + title := page.Find("title").Text() + assert.Contains(t, title, locale.TrString("new_org.title")) + + // Verify page form + _, exists := page.Find("form[action='/org/create']").Attr("method") + assert.True(t, exists) + + // Verify page header + header := strings.TrimSpace(page.Find(".form[action='/org/create'] .header").Text()) + assert.EqualValues(t, locale.TrString("new_org.title"), header) + }) +} diff --git a/tests/integration/org_nav_test.go b/tests/integration/org_nav_test.go index 6fe3a9d2c8..37b62921ae 100644 --- a/tests/integration/org_nav_test.go +++ b/tests/integration/org_nav_test.go @@ -5,9 +5,13 @@ package integration import ( "net/http" + "strings" "testing" + "code.gitea.io/gitea/modules/translation" "code.gitea.io/gitea/tests" + + "github.com/stretchr/testify/assert" ) // This test makes sure that organization members are able to navigate between `/` and `/org//
` freely. @@ -19,6 +23,8 @@ import ( func TestOrgNavigationDashboard(t *testing.T) { defer tests.PrepareTestEnv(t)() + locale := translation.NewLocale("en-US") + // Login as the future organization admin and create an organization session1 := loginUser(t, "user2") session1.MakeRequest(t, NewRequestWithValues(t, "POST", "/org/create", map[string]string{ @@ -33,6 +39,11 @@ func TestOrgNavigationDashboard(t *testing.T) { doc := NewHTMLParser(t, resp.Body) doc.AssertElement(t, "#org-info a[href='/org/org_navigation_test/dashboard']", true) + // Verify the "New repository" and "New migration" buttons + links := doc.Find(".organization.profile .grid .column .center") + assert.EqualValues(t, locale.TrString("new_repo.link"), strings.TrimSpace(links.Find("a[href^='/repo/create?org=']").Text())) + assert.EqualValues(t, locale.TrString("new_migrate.link"), strings.TrimSpace(links.Find("a[href^='/repo/migrate?org=']").Text())) + // Check if the "View " button is available on dashboard for the org admin (member) resp = session1.MakeRequest(t, NewRequest(t, "GET", "/org/org_navigation_test/dashboard"), http.StatusOK) doc = NewHTMLParser(t, resp.Body) diff --git a/tests/integration/repo_generate_test.go b/tests/integration/repo_generate_test.go index 2cd2002b51..c475c92eef 100644 --- a/tests/integration/repo_generate_test.go +++ b/tests/integration/repo_generate_test.go @@ -1,4 +1,5 @@ // Copyright 2019 The Gitea Authors. All rights reserved. +// Copyright 2024 The Forgejo Authors. All rights reserved. // SPDX-License-Identifier: MIT package integration @@ -13,6 +14,7 @@ import ( "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/translation" "code.gitea.io/gitea/tests" "github.com/stretchr/testify/assert" @@ -21,6 +23,15 @@ import ( func assertRepoCreateForm(t *testing.T, htmlDoc *HTMLDoc, owner *user_model.User, templateID string) { _, exists := htmlDoc.doc.Find("form.ui.form[action^='/repo/create']").Attr("action") assert.True(t, exists, "Expected the repo creation form") + locale := translation.NewLocale("en-US") + + // Verify page title + title := htmlDoc.doc.Find("title").Text() + assert.Contains(t, title, locale.TrString("new_repo.title")) + + // Verify form header + header := strings.TrimSpace(htmlDoc.doc.Find(".form[action='/repo/create'] .header").Text()) + assert.EqualValues(t, locale.TrString("new_repo.title"), header) htmlDoc.AssertDropdownHasSelectedOption(t, "uid", strconv.FormatInt(owner.ID, 10)) diff --git a/tests/integration/user_dashboard_test.go b/tests/integration/user_dashboard_test.go new file mode 100644 index 0000000000..abc3e065d9 --- /dev/null +++ b/tests/integration/user_dashboard_test.go @@ -0,0 +1,30 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package integration + +import ( + "net/http" + "strings" + "testing" + + "code.gitea.io/gitea/models/unittest" + "code.gitea.io/gitea/modules/translation" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestUserDashboardActionLinks(t *testing.T) { + require.NoError(t, unittest.PrepareTestDatabase()) + + session := loginUser(t, "user1") + locale := translation.NewLocale("en-US") + + response := session.MakeRequest(t, NewRequest(t, "GET", "/"), http.StatusOK) + page := NewHTMLParser(t, response.Body) + links := page.Find("#navbar .dropdown[data-tooltip-content='Create…'] .menu") + assert.EqualValues(t, locale.TrString("new_repo.link"), strings.TrimSpace(links.Find("a[href='/repo/create']").Text())) + assert.EqualValues(t, locale.TrString("new_migrate.link"), strings.TrimSpace(links.Find("a[href='/repo/migrate']").Text())) + assert.EqualValues(t, locale.TrString("new_org.link"), strings.TrimSpace(links.Find("a[href='/org/create']").Text())) +}