diff --git a/frontend/src/routes/admin/tags/TagTreeNode.svelte.test.ts b/frontend/src/routes/admin/tags/TagTreeNode.svelte.test.ts index 9c597820..d200e596 100644 --- a/frontend/src/routes/admin/tags/TagTreeNode.svelte.test.ts +++ b/frontend/src/routes/admin/tags/TagTreeNode.svelte.test.ts @@ -122,4 +122,50 @@ describe('TagTreeNode', () => { .element(browserPage.getByRole('button', { name: /einklappen|ausklappen/i })) .toBeVisible(); }); + + it('hides the color dot when depth > 0 (only top-level shows colors)', async () => { + mockPage.url = new URL('http://localhost/admin/tags'); + const Node = await loadComponent(); + render(Node, { props: { node: leafNode(), depth: 1, collapseMap: new SvelteMap() } }); + + const dot = document.querySelector('[data-testid="tag-list-color-dot"]'); + expect(dot).toBeNull(); + }); + + it('hides the color dot when node.color is null', async () => { + mockPage.url = new URL('http://localhost/admin/tags'); + const Node = await loadComponent(); + render(Node, { + props: { node: leafNode({ color: null }), depth: 0, collapseMap: new SvelteMap() } + }); + + const dot = document.querySelector('[data-testid="tag-list-color-dot"]'); + expect(dot).toBeNull(); + }); + + it('omits the document count badge when documentCount is 0', async () => { + mockPage.url = new URL('http://localhost/admin/tags'); + const Node = await loadComponent(); + render(Node, { + props: { node: leafNode({ documentCount: 0 }), depth: 0, collapseMap: new SvelteMap() } + }); + + const link = document.querySelector('a[href="/admin/tags/t1"]'); + expect(link?.textContent).not.toMatch(/\(\d+\)/); + }); + + it('toggles the collapse state when the toggle button is clicked', async () => { + mockPage.url = new URL('http://localhost/admin/tags'); + const Node = await loadComponent(); + const map = new SvelteMap(); + render(Node, { props: { node: parentNode(), depth: 0, collapseMap: map } }); + + const toggle = Array.from(document.querySelectorAll('button')).find((b) => + /einklappen|ausklappen/i.test(b.getAttribute('aria-label') ?? '') + ) as HTMLButtonElement; + toggle?.click(); + await new Promise((r) => setTimeout(r, 30)); + // Map should have been mutated to opposite of current isCollapsed (false → true) + expect(map.get('tp1')).toBe(true); + }); });