1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-05 10:07:22 +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:
wxiaoguang
2025-04-01 15:02:30 +08:00
committed by GitHub
parent d54418a7d3
commit 86c1a33369
4 changed files with 23 additions and 69 deletions

View File

@ -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>');
@ -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>');
});

View File

@ -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) {