Skip to content

Fix some UI bugs and clean up unused tests #34088

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions modules/fileicon/material.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,9 @@ func (m *MaterialIconProvider) FileIcon(ctx reqctx.RequestContext, entry *git.Tr
}

name := m.findIconNameByGit(entry)
if name == "folder" {
// 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
return svg.RenderHTML("material-folder-generic", 16, "octicon-file-directory-fill")
}
if iconSVG, ok := m.svgs[name]; ok && iconSVG != "" {
// 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
if iconSVG, ok := m.svgs[name]; ok && name != "folder" && iconSVG != "" {
// keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
extraClass := "octicon-file"
switch {
Expand All @@ -115,7 +112,8 @@ func (m *MaterialIconProvider) FileIcon(ctx reqctx.RequestContext, entry *git.Tr
}
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 {
Expand Down
60 changes: 0 additions & 60 deletions modules/git/repo_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@
package git

import (
"context"
mathRand "math/rand/v2"
"path/filepath"
"slices"
"sync"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func Test_nulSeparatedAttributeWriter_ReadAttribute(t *testing.T) {
Expand Down Expand Up @@ -101,57 +95,3 @@ func Test_nulSeparatedAttributeWriter_ReadAttribute(t *testing.T) {
Value: "unspecified",
}, 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)
}
}
18 changes: 17 additions & 1 deletion web_src/js/utils/dom.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import {createElementFromAttrs, createElementFromHTML, queryElemChildren, querySingleVisibleElem} from './dom.ts';
import {
createElementFromAttrs,
createElementFromHTML,
queryElemChildren,
querySingleVisibleElem,
toggleElem,
} from './dom.ts';

test('createElementFromHTML', () => {
expect(createElementFromHTML('<a>foo<span>bar</span></a>').outerHTML).toEqual('<a>foo<span>bar</span></a>');
Expand Down Expand Up @@ -32,3 +38,13 @@ test('queryElemChildren', () => {
const children = queryElemChildren(el, '.a');
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>');
});
2 changes: 1 addition & 1 deletion web_src/js/utils/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
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) {
Expand Down