From e571302c27495bb6ba80a7030987de2d935c3ec1 Mon Sep 17 00:00:00 2001 From: Joakim Bjerknes Date: Wed, 29 Nov 2023 11:01:45 +0100 Subject: [PATCH 01/15] add tests for Dropdown --- .../dropdown/__tests__/Dropdown.test.tsx | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/packages/dnb-eufemia/src/components/dropdown/__tests__/Dropdown.test.tsx b/packages/dnb-eufemia/src/components/dropdown/__tests__/Dropdown.test.tsx index d2d8d12e6e4..b2d91950258 100644 --- a/packages/dnb-eufemia/src/components/dropdown/__tests__/Dropdown.test.tsx +++ b/packages/dnb-eufemia/src/components/dropdown/__tests__/Dropdown.test.tsx @@ -1179,6 +1179,21 @@ describe('Dropdown component', () => { expect(ref.current instanceof HTMLButtonElement).toBe(true) }) + it.only('gets valid buttonRef element when ref is function', () => { + const ref: React.MutableRefObject = + React.createRef() + + function refFuntion(instance: HTMLButtonElement) { + ref.current = instance + } + + render() + + expect(ref.current.id).toBe(props.id) + expect(ref.current.tagName).toBe('BUTTON') + expect(ref.current instanceof HTMLButtonElement).toBe(true) + }) + it('gets valid innerRef element', () => { let ref: React.RefObject @@ -1194,6 +1209,21 @@ describe('Dropdown component', () => { expect(ref.current instanceof HTMLSpanElement).toBe(true) }) + it.only('gets valid innerRef element when ref is function', () => { + const ref: React.MutableRefObject = + React.createRef() + + function refFuntion(instance: HTMLButtonElement) { + ref.current = instance + } + + render() + + expect(ref.current.className).toContain('dnb-dropdown') + expect(ref.current.tagName).toBe('SPAN') + expect(ref.current instanceof HTMLSpanElement).toBe(true) + }) + beforeAll(() => { window.resizeTo = function resizeTo({ width = window.innerWidth, From 2d9b8e5224a1f9c74d7085b65a6144b38048c8bb Mon Sep 17 00:00:00 2001 From: Joakim Bjerknes Date: Wed, 29 Nov 2023 11:02:41 +0100 Subject: [PATCH 02/15] removed only --- .../src/components/dropdown/__tests__/Dropdown.test.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/dnb-eufemia/src/components/dropdown/__tests__/Dropdown.test.tsx b/packages/dnb-eufemia/src/components/dropdown/__tests__/Dropdown.test.tsx index b2d91950258..9e4931bc85c 100644 --- a/packages/dnb-eufemia/src/components/dropdown/__tests__/Dropdown.test.tsx +++ b/packages/dnb-eufemia/src/components/dropdown/__tests__/Dropdown.test.tsx @@ -1179,7 +1179,7 @@ describe('Dropdown component', () => { expect(ref.current instanceof HTMLButtonElement).toBe(true) }) - it.only('gets valid buttonRef element when ref is function', () => { + it('gets valid buttonRef element when ref is function', () => { const ref: React.MutableRefObject = React.createRef() @@ -1209,7 +1209,7 @@ describe('Dropdown component', () => { expect(ref.current instanceof HTMLSpanElement).toBe(true) }) - it.only('gets valid innerRef element when ref is function', () => { + it('gets valid innerRef element when ref is function', () => { const ref: React.MutableRefObject = React.createRef() From 4b3b71d0ae3f5584de9395b4818ec3aef0c13820 Mon Sep 17 00:00:00 2001 From: Joakim Bjerknes Date: Wed, 29 Nov 2023 12:56:47 +0100 Subject: [PATCH 03/15] add test for Anchor --- .../components/anchor/__tests__/Anchor.test.tsx | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/dnb-eufemia/src/components/anchor/__tests__/Anchor.test.tsx b/packages/dnb-eufemia/src/components/anchor/__tests__/Anchor.test.tsx index 95d0d9303ce..d11b5ae5a2e 100644 --- a/packages/dnb-eufemia/src/components/anchor/__tests__/Anchor.test.tsx +++ b/packages/dnb-eufemia/src/components/anchor/__tests__/Anchor.test.tsx @@ -163,6 +163,20 @@ describe('Anchor element', () => { expect(ref.current).toBe(element) }) + it('gets valid element when ref is function', () => { + const ref: React.MutableRefObject = + React.createRef() + + const refFn = (elem: HTMLAnchorElement) => { + ref.current = elem + } + + render() + + expect(ref.current.getAttribute('id')).toBe('unique') + expect(ref.current.tagName).toBe('A') + }) + it('has aria-describedby when target is blank', () => { const { rerender } = render( From eb3ab33a018235a783ec981b47d73e5bf9e498ab Mon Sep 17 00:00:00 2001 From: Joakim Bjerknes Date: Wed, 29 Nov 2023 13:00:58 +0100 Subject: [PATCH 04/15] add test for Autocomplete --- .../autocomplete/__tests__/Autocomplete.test.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/dnb-eufemia/src/components/autocomplete/__tests__/Autocomplete.test.tsx b/packages/dnb-eufemia/src/components/autocomplete/__tests__/Autocomplete.test.tsx index 0b037045e91..76c1df19ab8 100644 --- a/packages/dnb-eufemia/src/components/autocomplete/__tests__/Autocomplete.test.tsx +++ b/packages/dnb-eufemia/src/components/autocomplete/__tests__/Autocomplete.test.tsx @@ -3085,6 +3085,19 @@ describe('Autocomplete component', () => { }) }) }) + + it('gets valid element when input_ref is function', () => { + const ref: React.MutableRefObject = React.createRef() + + const refFn = (elem: HTMLInputElement) => { + ref.current = elem + } + + render() + + expect(ref.current.getAttribute('id')).toBe('unique') + expect(ref.current.tagName).toBe('INPUT') + }) }) describe('Autocomplete markup', () => { From ed4d2b5c10a4f0d933e63efc2a1a660f126e49c0 Mon Sep 17 00:00:00 2001 From: Joakim Bjerknes Date: Wed, 29 Nov 2023 13:37:15 +0100 Subject: [PATCH 05/15] add test for Button --- .../src/components/button/__tests__/Button.test.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/dnb-eufemia/src/components/button/__tests__/Button.test.tsx b/packages/dnb-eufemia/src/components/button/__tests__/Button.test.tsx index 05cd11526f4..a6ac2540615 100644 --- a/packages/dnb-eufemia/src/components/button/__tests__/Button.test.tsx +++ b/packages/dnb-eufemia/src/components/button/__tests__/Button.test.tsx @@ -167,6 +167,19 @@ describe('Button component', () => { expect(typeof ref.current).toBe('object') }) + it('gets valid element when innerRef is function', () => { + const ref: React.MutableRefObject = + React.createRef() + + const refFn = (elem: HTMLButtonElement) => { + ref.current = elem + } + render(