diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-12-24 09:54:19 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-24 01:54:19 +0000 |
commit | 781c6df40fcd8c8a112d048b4beb079d0b9a7f2b (patch) | |
tree | 041ce9a23cf97219eecf05d7aac2707620c17e5c /modules/markup/html_issue_test.go | |
parent | 02c64e48b7421e68d264163253318aacb6fb2f3d (diff) | |
download | gitea-781c6df40fcd8c8a112d048b4beb079d0b9a7f2b.tar.gz gitea-781c6df40fcd8c8a112d048b4beb079d0b9a7f2b.zip |
Add sub issue list support (#32940)
Just like GitHub, show issue icon/title when the issue number is in a list
Diffstat (limited to 'modules/markup/html_issue_test.go')
-rw-r--r-- | modules/markup/html_issue_test.go | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/modules/markup/html_issue_test.go b/modules/markup/html_issue_test.go new file mode 100644 index 0000000000..8d189fbdf6 --- /dev/null +++ b/modules/markup/html_issue_test.go @@ -0,0 +1,72 @@ +// Copyright 2024 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package markup_test + +import ( + "context" + "html/template" + "strings" + "testing" + + "code.gitea.io/gitea/modules/htmlutil" + "code.gitea.io/gitea/modules/markup" + "code.gitea.io/gitea/modules/markup/markdown" + testModule "code.gitea.io/gitea/modules/test" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestRender_IssueList(t *testing.T) { + defer testModule.MockVariableValue(&markup.RenderBehaviorForTesting.DisableAdditionalAttributes, true)() + markup.Init(&markup.RenderHelperFuncs{ + RenderRepoIssueIconTitle: func(ctx context.Context, opts markup.RenderIssueIconTitleOptions) (template.HTML, error) { + return htmlutil.HTMLFormat("<div>issue #%d</div>", opts.IssueIndex), nil + }, + }) + + test := func(input, expected string) { + rctx := markup.NewTestRenderContext(markup.TestAppURL, map[string]string{ + "user": "test-user", "repo": "test-repo", + "markupAllowShortIssuePattern": "true", + }) + out, err := markdown.RenderString(rctx, input) + require.NoError(t, err) + assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(out))) + } + + t.Run("NormalIssueRef", func(t *testing.T) { + test( + "#12345", + `<p><a href="http://localhost:3000/test-user/test-repo/issues/12345" class="ref-issue" rel="nofollow">#12345</a></p>`, + ) + }) + + t.Run("ListIssueRef", func(t *testing.T) { + test( + "* #12345", + `<ul> +<li><div>issue #12345</div></li> +</ul>`, + ) + }) + + t.Run("ListIssueRefNormal", func(t *testing.T) { + test( + "* foo #12345 bar", + `<ul> +<li>foo <a href="http://localhost:3000/test-user/test-repo/issues/12345" class="ref-issue" rel="nofollow">#12345</a> bar</li> +</ul>`, + ) + }) + + t.Run("ListTodoIssueRef", func(t *testing.T) { + test( + "* [ ] #12345", + `<ul> +<li class="task-list-item"><input type="checkbox" disabled="" data-source-position="2"/><div>issue #12345</div></li> +</ul>`, + ) + }) +} |