Skip to content

Commit

Permalink
release of v10.62.3 (#4435)
Browse files Browse the repository at this point in the history
  • Loading branch information
langz authored Jan 7, 2025
2 parents e8e1f94 + ba7b764 commit 203425c
Show file tree
Hide file tree
Showing 5 changed files with 1,256 additions and 951 deletions.
1 change: 1 addition & 0 deletions packages/dnb-eufemia/src/components/radio/Radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export default class Radio extends React.PureComponent {
if (this.context.onChange) {
this.context.onChange({
value,
event,
})
}
dispatchCustomElementEvent(this, 'on_change', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ describe('Radio group component', () => {
fireEvent.click(document.querySelectorAll('input')[0])
expect(my_event.mock.calls.length).toBe(1)
expect(my_event.mock.calls[0][0].value).toBe('first')
expect(my_event.mock.calls[0][0].event).toBeType('object')

fireEvent.click(document.querySelectorAll('input')[1])
expect(my_event.mock.calls.length).toBe(2)
expect(my_event.mock.calls[1][0].value).toBe('second')
expect(my_event.mock.calls[1][0].event).toBeType('object')
})

it('will disable a single button within a group', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,21 @@ describe('UploadFileListLink', () => {
expect(element).toHaveClass('dnb-space__top--large')
})
})

describe('as non-clickable', () => {
const props = { ...defaultProps, href: undefined, onClick: undefined }

it('renders the span with a dnb-p class', () => {
render(<UploadFileLink {...props} />)
expect(document.querySelector('span')).toHaveClass('dnb-p')
})

it('forwards HTML attributes', () => {
render(<UploadFileLink {...props} data-testid="test" />)
expect(document.querySelector('span')).toHaveAttribute(
'data-testid',
'test'
)
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
import React from 'react'
import { renderHook } from '@testing-library/react'
import useExternalValue from '../useExternalValue'
import { DataContext } from '../..'
import IterateElementContext from '../../Iterate/IterateItemContext'

describe('useExternalValue', () => {
const transformers = {
current: {
fromExternal: (val) => val,
},
}

it('should return value when directly provided', () => {
const { result } = renderHook(() =>
useExternalValue({
value: 'test-value',
emptyValue: '',
transformers,
})
)

expect(result.current).toBe('test-value')
})

it('should transform value using fromExternal when provided', () => {
const transformers = {
current: {
fromExternal: (val) => val.toUpperCase(),
},
}

const { result } = renderHook(() =>
useExternalValue({
value: 'test',
transformers,
})
)

expect(result.current).toBe('TEST')
})

it('should return emptyValue when value matches emptyValue', () => {
const { result } = renderHook(() =>
useExternalValue({
value: '',
emptyValue: '',
transformers,
})
)

expect(result.current).toBe('')
})

describe('with iterate context', () => {
it('should return iterate element value when itemPath is "/"', () => {
const wrapper = ({ children }) => (
<IterateElementContext.Provider
value={{
value: 'iterate-value',
}}
>
{children}
</IterateElementContext.Provider>
)

const { result } = renderHook(
() =>
useExternalValue({
itemPath: '/',
transformers,
}),
{ wrapper }
)

expect(result.current).toBe('iterate-value')
})

it('should return value from iterate element using itemPath', () => {
const wrapper = ({ children }) => (
<IterateElementContext.Provider
value={{
value: {
nested: 'nested-value',
},
}}
>
{children}
</IterateElementContext.Provider>
)

const { result } = renderHook(
() =>
useExternalValue({
itemPath: '/nested',
transformers,
}),
{ wrapper }
)

expect(result.current).toBe('nested-value')
})

it('should transform value using fromExternal when provided', () => {
const transformers = {
current: {
fromExternal: (val) => val.toUpperCase(),
},
}

const wrapper = ({ children }) => (
<IterateElementContext.Provider
value={{
value: {
nested: 'nested-value',
},
}}
>
{children}
</IterateElementContext.Provider>
)

const { result } = renderHook(
() =>
useExternalValue({
itemPath: '/nested',
transformers,
}),
{ wrapper }
)

expect(result.current).toBe('NESTED-VALUE')
})
})

describe('with data context', () => {
it('should return full data when path is "/"', () => {
const wrapper = ({ children }) => (
<DataContext.Provider
data={{
foo: 'bar',
}}
>
{children}
</DataContext.Provider>
)

const { result } = renderHook(
() =>
useExternalValue({
path: '/',
transformers,
}),
{ wrapper }
)

expect(result.current).toEqual({ foo: 'bar' })
})

it('should return value from data using path', () => {
const wrapper = ({ children }) => (
<DataContext.Provider
data={{
nested: {
value: 'context-value',
},
}}
>
{children}
</DataContext.Provider>
)

const { result } = renderHook(
() =>
useExternalValue({
path: '/nested/value',
transformers,
}),
{ wrapper }
)

expect(result.current).toBe('context-value')
})

it('should transform value using fromExternal when provided', () => {
const transformers = {
current: {
fromExternal: (val) => val.toUpperCase(),
},
}

const wrapper = ({ children }) => (
<DataContext.Provider
data={{
nested: {
value: 'context-value',
},
}}
>
{children}
</DataContext.Provider>
)

const { result } = renderHook(
() =>
useExternalValue({
path: '/nested/value',
transformers,
}),
{ wrapper }
)

expect(result.current).toBe('CONTEXT-VALUE')
})

it('should return emptyValue when path does not exist', () => {
const wrapper = ({ children }) => (
<DataContext.Provider data={{}}>{children}</DataContext.Provider>
)

const { result } = renderHook(
() =>
useExternalValue({
path: '/missing',
emptyValue: 'empty',
transformers,
}),
{ wrapper }
)

expect(result.current).toBe('empty')
})
})

it('should handle priority order: value > iterate > data context', () => {
const wrapper = ({ children }) => (
<IterateElementContext.Provider
value={{
value: 'iterate-value',
}}
>
{children}
</IterateElementContext.Provider>
)

const { result } = renderHook(
() =>
useExternalValue({
value: 'direct-value',
path: '/foo',
itemPath: '/',
emptyValue: 'empty',
transformers,
}),
{ wrapper }
)

expect(result.current).toBe('direct-value')
})

it('should fall back to emptyValue when no value source is provided', () => {
const { result } = renderHook(() =>
useExternalValue({
emptyValue: 'empty',
transformers,
})
)

expect(result.current).toBe('empty')
})

it('should handle null contexts gracefully', () => {
const { result } = renderHook(() =>
useExternalValue({
path: '/foo',
itemPath: '/bar',
emptyValue: 'empty',
transformers,
})
)

expect(result.current).toBe('empty')
})
})
Loading

0 comments on commit 203425c

Please sign in to comment.