From 24057790b5e53db32983c4c59eb86727d89cd263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20H=C3=B8egh?= Date: Fri, 24 Feb 2023 16:54:08 +0100 Subject: [PATCH] fix(Anchor): ensure id is passed down (#2016) --- .../__snapshots__/Button.test.js.snap | 10 ++++ packages/dnb-eufemia/src/elements/Anchor.tsx | 4 +- .../src/elements/__tests__/Anchor.test.tsx | 57 ++++++++++++++++++- 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/packages/dnb-eufemia/src/components/button/__tests__/__snapshots__/Button.test.js.snap b/packages/dnb-eufemia/src/components/button/__tests__/__snapshots__/Button.test.js.snap index 6fd882e77dd..c307ab37ccf 100644 --- a/packages/dnb-eufemia/src/components/button/__tests__/__snapshots__/Button.test.js.snap +++ b/packages/dnb-eufemia/src/components/button/__tests__/__snapshots__/Button.test.js.snap @@ -361,6 +361,7 @@ exports[`Button component have to match href="..." snapshot 1`] = ` "current": { expect(document.querySelector('[href]')).toBeTruthy() }) + it('should forward id', () => { + render( + + text + + ) + expect(document.querySelector('a').getAttribute('id')).toBe( + 'unique-id' + ) + }) + + it('should have tooltip markup in DOM', () => { + render( + + text + + ) + + expect( + document.querySelector('#unique-id-tooltip.dnb-tooltip__content') + .textContent + ).toBe('Tooltip') + }) + + it('should aria-describedby set by tooltip', () => { + render( + + text + + ) + + const element = document.getElementById('unique-id') + + expect(element.getAttribute('aria-describedby')).toBe( + 'unique-id-tooltip' + ) + }) + + it('should show tooltip on mouseover', () => { + render( + + text + + ) + + const element = document.getElementById('unique-id') + fireEvent.mouseEnter(element) + + expect( + document + .querySelector('#unique-id-tooltip.dnb-tooltip__content') + .parentElement.classList.contains('dnb-tooltip--active') + ).toBeTruthy() + }) + it('has no-icon class when element was given', () => { render(