Skip to content

Commit 86c1a33

Browse files
authored
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
1 parent d54418a commit 86c1a33

File tree

4 files changed

+23
-69
lines changed

4 files changed

+23
-69
lines changed

modules/fileicon/material.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,9 @@ func (m *MaterialIconProvider) FileIcon(ctx reqctx.RequestContext, entry *git.Tr
9999
}
100100

101101
name := m.findIconNameByGit(entry)
102-
if name == "folder" {
103-
// the material icon pack's "folder" icon doesn't look good, so use our built-in one
104-
// keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
105-
return svg.RenderHTML("material-folder-generic", 16, "octicon-file-directory-fill")
106-
}
107-
if iconSVG, ok := m.svgs[name]; ok && iconSVG != "" {
102+
// the material icon pack's "folder" icon doesn't look good, so use our built-in one
103+
// keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
104+
if iconSVG, ok := m.svgs[name]; ok && name != "folder" && iconSVG != "" {
108105
// keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
109106
extraClass := "octicon-file"
110107
switch {
@@ -115,7 +112,8 @@ func (m *MaterialIconProvider) FileIcon(ctx reqctx.RequestContext, entry *git.Tr
115112
}
116113
return m.renderFileIconSVG(ctx, name, iconSVG, extraClass)
117114
}
118-
return svg.RenderHTML("octicon-file")
115+
// TODO: use an interface or wrapper for git.Entry to make the code testable.
116+
return BasicThemeIcon(entry)
119117
}
120118

121119
func (m *MaterialIconProvider) findIconNameWithLangID(s string) string {

modules/git/repo_attribute_test.go

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,10 @@
44
package git
55

66
import (
7-
"context"
8-
mathRand "math/rand/v2"
9-
"path/filepath"
10-
"slices"
11-
"sync"
127
"testing"
138
"time"
149

1510
"github.com/stretchr/testify/assert"
16-
"github.com/stretchr/testify/require"
1711
)
1812

1913
func Test_nulSeparatedAttributeWriter_ReadAttribute(t *testing.T) {
@@ -101,57 +95,3 @@ func Test_nulSeparatedAttributeWriter_ReadAttribute(t *testing.T) {
10195
Value: "unspecified",
10296
}, attr)
10397
}
104-
105-
func TestAttributeReader(t *testing.T) {
106-
t.Skip() // for debug purpose only, do not run in CI
107-
108-
ctx := t.Context()
109-
110-
timeout := 1 * time.Second
111-
repoPath := filepath.Join(testReposDir, "language_stats_repo")
112-
commitRef := "HEAD"
113-
114-
oneRound := func(t *testing.T, roundIdx int) {
115-
ctx, cancel := context.WithTimeout(ctx, timeout)
116-
_ = cancel
117-
gitRepo, err := OpenRepository(ctx, repoPath)
118-
require.NoError(t, err)
119-
defer gitRepo.Close()
120-
121-
commit, err := gitRepo.GetCommit(commitRef)
122-
require.NoError(t, err)
123-
124-
files, err := gitRepo.LsFiles()
125-
require.NoError(t, err)
126-
127-
randomFiles := slices.Clone(files)
128-
randomFiles = append(randomFiles, "any-file-1", "any-file-2")
129-
130-
t.Logf("Round %v with %d files", roundIdx, len(randomFiles))
131-
132-
attrReader, deferrable := gitRepo.CheckAttributeReader(commit.ID.String())
133-
defer deferrable()
134-
135-
wg := sync.WaitGroup{}
136-
wg.Add(1)
137-
138-
go func() {
139-
for {
140-
file := randomFiles[mathRand.IntN(len(randomFiles))]
141-
_, err := attrReader.CheckPath(file)
142-
if err != nil {
143-
for i := 0; i < 10; i++ {
144-
_, _ = attrReader.CheckPath(file)
145-
}
146-
break
147-
}
148-
}
149-
wg.Done()
150-
}()
151-
wg.Wait()
152-
}
153-
154-
for i := 0; i < 100; i++ {
155-
oneRound(t, i)
156-
}
157-
}

web_src/js/utils/dom.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import {createElementFromAttrs, createElementFromHTML, queryElemChildren, querySingleVisibleElem} from './dom.ts';
1+
import {
2+
createElementFromAttrs,
3+
createElementFromHTML,
4+
queryElemChildren,
5+
querySingleVisibleElem,
6+
toggleElem,
7+
} from './dom.ts';
28

39
test('createElementFromHTML', () => {
410
expect(createElementFromHTML('<a>foo<span>bar</span></a>').outerHTML).toEqual('<a>foo<span>bar</span></a>');
@@ -32,3 +38,13 @@ test('queryElemChildren', () => {
3238
const children = queryElemChildren(el, '.a');
3339
expect(children.length).toEqual(1);
3440
});
41+
42+
test('toggleElem', () => {
43+
const el = createElementFromHTML('<p><div>a</div><div class="tw-hidden">b</div></p>');
44+
toggleElem(el.children);
45+
expect(el.outerHTML).toEqual('<p><div class="tw-hidden">a</div><div class="">b</div></p>');
46+
toggleElem(el.children, false);
47+
expect(el.outerHTML).toEqual('<p><div class="tw-hidden">a</div><div class="tw-hidden">b</div></p>');
48+
toggleElem(el.children, true);
49+
expect(el.outerHTML).toEqual('<p><div class="">a</div><div class="">b</div></p>');
50+
});

web_src/js/utils/dom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function toggleClass(el: ElementArg, className: string, force?: boolean)
4444
* @param force force=true to show or force=false to hide, undefined to toggle
4545
*/
4646
export function toggleElem(el: ElementArg, force?: boolean) {
47-
toggleClass(el, 'tw-hidden', !force);
47+
toggleClass(el, 'tw-hidden', force === undefined ? force : !force);
4848
}
4949

5050
export function showElem(el: ElementArg) {

0 commit comments

Comments
 (0)