mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-26 12:27:06 +00:00 
			
		
		
		
	Fix some UI bugs and clean up unused tests (#34088)
1. Make the material icon falls back to basic theme correctly 2. Remove `TestAttributeReader`, the problem has been resolved. 3. Fix `toggleElem` bug and add tests
This commit is contained in:
		| @@ -99,12 +99,9 @@ func (m *MaterialIconProvider) FileIcon(ctx reqctx.RequestContext, entry *git.Tr | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	name := m.findIconNameByGit(entry) | 	name := m.findIconNameByGit(entry) | ||||||
| 	if name == "folder" { | 	// the material icon pack's "folder" icon doesn't look good, so use our built-in one | ||||||
| 		// the material icon pack's "folder" icon doesn't look good, so use our built-in one | 	// keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work | ||||||
| 		// keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work | 	if iconSVG, ok := m.svgs[name]; ok && name != "folder" && iconSVG != "" { | ||||||
| 		return svg.RenderHTML("material-folder-generic", 16, "octicon-file-directory-fill") |  | ||||||
| 	} |  | ||||||
| 	if iconSVG, ok := m.svgs[name]; ok && iconSVG != "" { |  | ||||||
| 		// keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work | 		// keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work | ||||||
| 		extraClass := "octicon-file" | 		extraClass := "octicon-file" | ||||||
| 		switch { | 		switch { | ||||||
| @@ -115,7 +112,8 @@ func (m *MaterialIconProvider) FileIcon(ctx reqctx.RequestContext, entry *git.Tr | |||||||
| 		} | 		} | ||||||
| 		return m.renderFileIconSVG(ctx, name, iconSVG, extraClass) | 		return m.renderFileIconSVG(ctx, name, iconSVG, extraClass) | ||||||
| 	} | 	} | ||||||
| 	return svg.RenderHTML("octicon-file") | 	// TODO: use an interface or wrapper for git.Entry to make the code testable. | ||||||
|  | 	return BasicThemeIcon(entry) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (m *MaterialIconProvider) findIconNameWithLangID(s string) string { | func (m *MaterialIconProvider) findIconNameWithLangID(s string) string { | ||||||
|   | |||||||
| @@ -4,16 +4,10 @@ | |||||||
| package git | package git | ||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"context" |  | ||||||
| 	mathRand "math/rand/v2" |  | ||||||
| 	"path/filepath" |  | ||||||
| 	"slices" |  | ||||||
| 	"sync" |  | ||||||
| 	"testing" | 	"testing" | ||||||
| 	"time" | 	"time" | ||||||
|  |  | ||||||
| 	"github.com/stretchr/testify/assert" | 	"github.com/stretchr/testify/assert" | ||||||
| 	"github.com/stretchr/testify/require" |  | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func Test_nulSeparatedAttributeWriter_ReadAttribute(t *testing.T) { | func Test_nulSeparatedAttributeWriter_ReadAttribute(t *testing.T) { | ||||||
| @@ -101,57 +95,3 @@ func Test_nulSeparatedAttributeWriter_ReadAttribute(t *testing.T) { | |||||||
| 		Value:     "unspecified", | 		Value:     "unspecified", | ||||||
| 	}, attr) | 	}, attr) | ||||||
| } | } | ||||||
|  |  | ||||||
| func TestAttributeReader(t *testing.T) { |  | ||||||
| 	t.Skip() // for debug purpose only, do not run in CI |  | ||||||
|  |  | ||||||
| 	ctx := t.Context() |  | ||||||
|  |  | ||||||
| 	timeout := 1 * time.Second |  | ||||||
| 	repoPath := filepath.Join(testReposDir, "language_stats_repo") |  | ||||||
| 	commitRef := "HEAD" |  | ||||||
|  |  | ||||||
| 	oneRound := func(t *testing.T, roundIdx int) { |  | ||||||
| 		ctx, cancel := context.WithTimeout(ctx, timeout) |  | ||||||
| 		_ = cancel |  | ||||||
| 		gitRepo, err := OpenRepository(ctx, repoPath) |  | ||||||
| 		require.NoError(t, err) |  | ||||||
| 		defer gitRepo.Close() |  | ||||||
|  |  | ||||||
| 		commit, err := gitRepo.GetCommit(commitRef) |  | ||||||
| 		require.NoError(t, err) |  | ||||||
|  |  | ||||||
| 		files, err := gitRepo.LsFiles() |  | ||||||
| 		require.NoError(t, err) |  | ||||||
|  |  | ||||||
| 		randomFiles := slices.Clone(files) |  | ||||||
| 		randomFiles = append(randomFiles, "any-file-1", "any-file-2") |  | ||||||
|  |  | ||||||
| 		t.Logf("Round %v with %d files", roundIdx, len(randomFiles)) |  | ||||||
|  |  | ||||||
| 		attrReader, deferrable := gitRepo.CheckAttributeReader(commit.ID.String()) |  | ||||||
| 		defer deferrable() |  | ||||||
|  |  | ||||||
| 		wg := sync.WaitGroup{} |  | ||||||
| 		wg.Add(1) |  | ||||||
|  |  | ||||||
| 		go func() { |  | ||||||
| 			for { |  | ||||||
| 				file := randomFiles[mathRand.IntN(len(randomFiles))] |  | ||||||
| 				_, err := attrReader.CheckPath(file) |  | ||||||
| 				if err != nil { |  | ||||||
| 					for i := 0; i < 10; i++ { |  | ||||||
| 						_, _ = attrReader.CheckPath(file) |  | ||||||
| 					} |  | ||||||
| 					break |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 			wg.Done() |  | ||||||
| 		}() |  | ||||||
| 		wg.Wait() |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	for i := 0; i < 100; i++ { |  | ||||||
| 		oneRound(t, i) |  | ||||||
| 	} |  | ||||||
| } |  | ||||||
|   | |||||||
| @@ -1,4 +1,10 @@ | |||||||
| import {createElementFromAttrs, createElementFromHTML, queryElemChildren, querySingleVisibleElem} from './dom.ts'; | import { | ||||||
|  |   createElementFromAttrs, | ||||||
|  |   createElementFromHTML, | ||||||
|  |   queryElemChildren, | ||||||
|  |   querySingleVisibleElem, | ||||||
|  |   toggleElem, | ||||||
|  | } from './dom.ts'; | ||||||
|  |  | ||||||
| test('createElementFromHTML', () => { | test('createElementFromHTML', () => { | ||||||
|   expect(createElementFromHTML('<a>foo<span>bar</span></a>').outerHTML).toEqual('<a>foo<span>bar</span></a>'); |   expect(createElementFromHTML('<a>foo<span>bar</span></a>').outerHTML).toEqual('<a>foo<span>bar</span></a>'); | ||||||
| @@ -32,3 +38,13 @@ test('queryElemChildren', () => { | |||||||
|   const children = queryElemChildren(el, '.a'); |   const children = queryElemChildren(el, '.a'); | ||||||
|   expect(children.length).toEqual(1); |   expect(children.length).toEqual(1); | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | test('toggleElem', () => { | ||||||
|  |   const el = createElementFromHTML('<p><div>a</div><div class="tw-hidden">b</div></p>'); | ||||||
|  |   toggleElem(el.children); | ||||||
|  |   expect(el.outerHTML).toEqual('<p><div class="tw-hidden">a</div><div class="">b</div></p>'); | ||||||
|  |   toggleElem(el.children, false); | ||||||
|  |   expect(el.outerHTML).toEqual('<p><div class="tw-hidden">a</div><div class="tw-hidden">b</div></p>'); | ||||||
|  |   toggleElem(el.children, true); | ||||||
|  |   expect(el.outerHTML).toEqual('<p><div class="">a</div><div class="">b</div></p>'); | ||||||
|  | }); | ||||||
|   | |||||||
| @@ -44,7 +44,7 @@ export function toggleClass(el: ElementArg, className: string, force?: boolean) | |||||||
|  * @param force force=true to show or force=false to hide, undefined to toggle |  * @param force force=true to show or force=false to hide, undefined to toggle | ||||||
|  */ |  */ | ||||||
| export function toggleElem(el: ElementArg, force?: boolean) { | export function toggleElem(el: ElementArg, force?: boolean) { | ||||||
|   toggleClass(el, 'tw-hidden', !force); |   toggleClass(el, 'tw-hidden', force === undefined ? force : !force); | ||||||
| } | } | ||||||
|  |  | ||||||
| export function showElem(el: ElementArg) { | export function showElem(el: ElementArg) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 wxiaoguang
					wxiaoguang