mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-01 04:12:10 +00:00
feat(i18n): allow different translations of creation links and titles (#4829)
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4829 Reviewed-by: Gusted <gusted@noreply.codeberg.org>
This commit is contained in:
parent
690b63fc74
commit
bad3b32037
13 changed files with 115 additions and 15 deletions
|
@ -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
|
||||
|
|
37
tests/integration/new_org_test.go
Normal file
37
tests/integration/new_org_test.go
Normal file
|
@ -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)
|
||||
})
|
||||
}
|
|
@ -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 `/<orgname>` and `/org/<orgname>/<section>` 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 <orgname>" 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)
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
30
tests/integration/user_dashboard_test.go
Normal file
30
tests/integration/user_dashboard_test.go
Normal file
|
@ -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()))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue