Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
76 lines
2.3 KiB
Go
76 lines
2.3 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package fileicon_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"gitea.dev/modules/fileicon"
|
|
"gitea.dev/modules/git"
|
|
"gitea.dev/modules/setting"
|
|
"gitea.dev/modules/test"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRenderEntryIconHTML_WithDifferentThemes(t *testing.T) {
|
|
// Test that folder icons use the folder theme
|
|
t.Run("FolderUsesBasicTheme", func(t *testing.T) {
|
|
defer test.MockVariableValue(&setting.UI.FileIconTheme, "material")()
|
|
defer test.MockVariableValue(&setting.UI.FolderIconTheme, "basic")()
|
|
|
|
folderEntry := &fileicon.EntryInfo{
|
|
BaseName: "testfolder",
|
|
EntryMode: git.EntryModeTree,
|
|
}
|
|
|
|
html := fileicon.RenderEntryIconHTML(nil, folderEntry)
|
|
// Basic theme renders octicon classes
|
|
assert.Contains(t, string(html), "octicon-file-directory-fill")
|
|
})
|
|
|
|
t.Run("FileUsesMaterialTheme", func(t *testing.T) {
|
|
defer test.MockVariableValue(&setting.UI.FileIconTheme, "material")()
|
|
defer test.MockVariableValue(&setting.UI.FolderIconTheme, "basic")()
|
|
|
|
fileEntry := &fileicon.EntryInfo{
|
|
BaseName: "test.js",
|
|
EntryMode: git.EntryModeBlob,
|
|
}
|
|
|
|
html := fileicon.RenderEntryIconHTML(nil, fileEntry)
|
|
// Material theme for files renders material icons
|
|
assert.Contains(t, string(html), "svg-mfi-")
|
|
})
|
|
|
|
t.Run("SymlinkToFolderUsesBasicTheme", func(t *testing.T) {
|
|
defer test.MockVariableValue(&setting.UI.FileIconTheme, "material")()
|
|
defer test.MockVariableValue(&setting.UI.FolderIconTheme, "basic")()
|
|
|
|
symlinkEntry := &fileicon.EntryInfo{
|
|
BaseName: "link",
|
|
EntryMode: git.EntryModeSymlink,
|
|
SymlinkToMode: git.EntryModeTree,
|
|
}
|
|
|
|
html := fileicon.RenderEntryIconHTML(nil, symlinkEntry)
|
|
// Symlinks to folders should use folder theme
|
|
assert.Contains(t, string(html), "octicon-file-directory-symlink")
|
|
})
|
|
|
|
t.Run("BothMaterialTheme", func(t *testing.T) {
|
|
defer test.MockVariableValue(&setting.UI.FileIconTheme, "material")()
|
|
defer test.MockVariableValue(&setting.UI.FolderIconTheme, "material")()
|
|
|
|
folderEntry := &fileicon.EntryInfo{
|
|
BaseName: "testfolder",
|
|
EntryMode: git.EntryModeTree,
|
|
}
|
|
|
|
html := fileicon.RenderEntryIconHTML(nil, folderEntry)
|
|
// Material theme for folders renders material folder icons
|
|
assert.Contains(t, string(html), "svg-mfi-")
|
|
})
|
|
}
|