44package files
55
66import (
7- "html/template"
87 "testing"
98
109 "code.gitea.io/gitea/models/unittest"
10+ "code.gitea.io/gitea/modules/fileicon"
1111 "code.gitea.io/gitea/modules/git"
12+ "code.gitea.io/gitea/modules/reqctx"
1213 api "code.gitea.io/gitea/modules/structs"
14+ "code.gitea.io/gitea/modules/templates"
1315 "code.gitea.io/gitea/services/contexttest"
1416
1517 "github.com/stretchr/testify/assert"
@@ -62,15 +64,19 @@ func TestGetTreeViewNodes(t *testing.T) {
6264 contexttest .LoadUser (t , ctx , 2 )
6365 contexttest .LoadGitRepo (t , ctx )
6466 defer ctx .Repo .GitRepo .Close ()
67+ renderUtils := templates .NewRenderUtils (reqctx .FromContext (ctx ))
6568
6669 treeNodes , err := GetTreeViewNodes (ctx , ctx .Repo .Commit , "" , "" )
6770 assert .NoError (t , err )
6871 assert .Equal (t , []* TreeViewNode {
6972 {
7073 EntryName : "docs" ,
7174 EntryMode : "tree" ,
72- FileIcon : template .HTML (`<svg id="svg-mfi-folder-docs" class="svg git-entry-icon octicon-file-directory-fill" width="16" height="16" aria-hidden="true" viewBox='0 0 32 32'><path fill='#0277bd' d='m13.844 7.536-1.288-1.072A2 2 0 0 0 11.276 6H4a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h24a2 2 0 0 0 2-2V10a2 2 0 0 0-2-2H15.124a2 2 0 0 1-1.28-.464'/><path fill='#b3e5fc' d='M24 10h-7a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V16Zm0 16h-6v-2h6Zm4-4H18v-2h10Zm-4.828-5.172V12L28 16.828Z'/></svg>` ),
73- FullPath : "docs" ,
75+ FileIcon : renderUtils .RenderFileIcon (& fileicon.FileIcon {
76+ Name : "docs" ,
77+ EntryMode : git .EntryModeTree ,
78+ }),
79+ FullPath : "docs" ,
7480 },
7581 }, treeNodes )
7682
@@ -80,14 +86,20 @@ func TestGetTreeViewNodes(t *testing.T) {
8086 {
8187 EntryName : "docs" ,
8288 EntryMode : "tree" ,
83- FileIcon : template .HTML (`<svg class="svg git-entry-icon octicon-file-directory-fill" width="16" height="16" aria-hidden="true"><use xlink:href="#svg-mfi-folder-docs"></use></svg>` ),
84- FullPath : "docs" ,
89+ FileIcon : renderUtils .RenderFileIcon (& fileicon.FileIcon {
90+ Name : "docs" ,
91+ EntryMode : git .EntryModeTree ,
92+ }),
93+ FullPath : "docs" ,
8594 Children : []* TreeViewNode {
8695 {
8796 EntryName : "README.md" ,
8897 EntryMode : "blob" ,
89- FileIcon : template .HTML (`<svg id="svg-mfi-readme" class="svg git-entry-icon octicon-file" width="16" height="16" aria-hidden="true" fill='none' viewBox='0 0 16 16'><path d='M0 0h24v24H0z'/><path fill='#42a5f5' d='M8 1C4.136 1 1 4.136 1 8s3.136 7 7 7 7-3.136 7-7-3.136-7-7-7m1 11H7V7.5h2zm0-6H7V4h2z'/></svg>` ),
90- FullPath : "docs/README.md" ,
98+ FileIcon : renderUtils .RenderFileIcon (& fileicon.FileIcon {
99+ Name : "README.md" ,
100+ EntryMode : git .EntryModeBlob ,
101+ }),
102+ FullPath : "docs/README.md" ,
91103 },
92104 },
93105 },
@@ -99,8 +111,11 @@ func TestGetTreeViewNodes(t *testing.T) {
99111 {
100112 EntryName : "README.md" ,
101113 EntryMode : "blob" ,
102- FileIcon : template .HTML (`<svg class="svg git-entry-icon octicon-file" width="16" height="16" aria-hidden="true"><use xlink:href="#svg-mfi-readme"></use></svg>` ),
103- FullPath : "docs/README.md" ,
114+ FileIcon : renderUtils .RenderFileIcon (& fileicon.FileIcon {
115+ Name : "README.md" ,
116+ EntryMode : git .EntryModeBlob ,
117+ }),
118+ FullPath : "docs/README.md" ,
104119 },
105120 }, treeNodes )
106121}
0 commit comments