aboutsummaryrefslogtreecommitdiffstats
path: root/services/markup/renderhelper_issueicontitle_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'services/markup/renderhelper_issueicontitle_test.go')
-rw-r--r--services/markup/renderhelper_issueicontitle_test.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/services/markup/renderhelper_issueicontitle_test.go b/services/markup/renderhelper_issueicontitle_test.go
new file mode 100644
index 0000000000..adce8401e0
--- /dev/null
+++ b/services/markup/renderhelper_issueicontitle_test.go
@@ -0,0 +1,49 @@
+// Copyright 2024 The Gitea Authors. All rights reserved.
+// SPDX-License-Identifier: MIT
+
+package markup
+
+import (
+ "testing"
+
+ "code.gitea.io/gitea/models/repo"
+ "code.gitea.io/gitea/models/unittest"
+ "code.gitea.io/gitea/modules/markup"
+ "code.gitea.io/gitea/modules/templates"
+ "code.gitea.io/gitea/modules/util"
+ "code.gitea.io/gitea/services/contexttest"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestRenderHelperIssueIconTitle(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+
+ ctx, _ := contexttest.MockContext(t, "/", contexttest.MockContextOption{Render: templates.HTMLRenderer()})
+ ctx.Repo.Repository = unittest.AssertExistsAndLoadBean(t, &repo.Repository{ID: 1})
+ htm, err := renderRepoIssueIconTitle(ctx, markup.RenderIssueIconTitleOptions{
+ LinkHref: "/link",
+ IssueIndex: 1,
+ })
+ assert.NoError(t, err)
+ assert.Equal(t, `<a href="/link"><span>octicon-issue-opened(16/text green)</span> issue1 (#1)</a>`, string(htm))
+
+ ctx, _ = contexttest.MockContext(t, "/", contexttest.MockContextOption{Render: templates.HTMLRenderer()})
+ htm, err = renderRepoIssueIconTitle(ctx, markup.RenderIssueIconTitleOptions{
+ OwnerName: "user2",
+ RepoName: "repo1",
+ LinkHref: "/link",
+ IssueIndex: 1,
+ })
+ assert.NoError(t, err)
+ assert.Equal(t, `<a href="/link"><span>octicon-issue-opened(16/text green)</span> issue1 (user2/repo1#1)</a>`, string(htm))
+
+ ctx, _ = contexttest.MockContext(t, "/", contexttest.MockContextOption{Render: templates.HTMLRenderer()})
+ _, err = renderRepoIssueIconTitle(ctx, markup.RenderIssueIconTitleOptions{
+ OwnerName: "user2",
+ RepoName: "repo2",
+ LinkHref: "/link",
+ IssueIndex: 2,
+ })
+ assert.ErrorIs(t, err, util.ErrPermissionDenied)
+}