Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

fix: TimezonePicker test and fix HocWithI18n structure

kruzhambusb75d13b250c5
diff --git a/src/ui/Tooltip.tsx b/src/ui/Tooltip.tsx
index 7cd5278c4..d6d3d6dae 100644
--- a/src/ui/Tooltip.tsx
+++ b/src/ui/Tooltip.tsx
@@ -10,9 +10,9 @@ const Tooltip = ({
className?: string,
tooltipNode?: JSX.Element,
}): JSX.Element => (
- <div className={cx('w-5 h-5 relative flex flex-col group items-center', className)}>
+ <div className={cx('w-5 h-5 relative flex flex-col group items-center', className)} data-testid='tooltip-wrapper'>
{tooltipNode || (
- <QuestionMarkCircleIcon className='w-5 h-5 text-gray-700 dark:text-gray-300' />
+ <QuestionMarkCircleIcon className='w-5 h-5 text-gray-700 dark:text-gray-300' data-testid='tooltip-icon' />
)}
<div className='absolute bottom-0 flex-col mb-6 hidden group-hover:flex items-center'>
<span className='opacity-95 relative w-60 z-10 p-2 text-xs leading-none text-white whitespace-no-wrap bg-gray-700 shadow-lg rounded-md'>
diff --git a/src/ui/__test__/Modal.test.tsx b/src/ui/__test__/Modal.test.tsx
index 8d4513696..44d6adb05 100644
--- a/src/ui/__test__/Modal.test.tsx
+++ b/src/ui/__test__/Modal.test.tsx
@@ -22,11 +22,9 @@ describe('Modal component', () => {
}
// use HOC to wrap component with I18nextProvider
- const HocWithI18n = ({ children }: {
- children: React.ReactNode,
- }): JSX.Element => (
+ const HocWithI18n = (props: any): JSX.Element => (
<I18nextProvider i18n={i18n}>
- {children}
+ <Modal {...props} />
</I18nextProvider>
)
@@ -50,9 +48,7 @@ describe('Modal component', () => {
it('renders with default props', () => {
const { getByText } = render(
- <HocWithI18n>
- <Modal {...defaultProps} />
- </HocWithI18n>,
+ <HocWithI18n {...defaultProps} />,
)
expect(getByText('Success')).toBeInTheDocument()
expect(getByText('Action completed successfully')).toBeInTheDocument()
@@ -60,9 +56,7 @@ describe('Modal component', () => {
it('calls onClose when close button is clicked', () => {
const { getByText } = render(
- <HocWithI18n>
- <Modal {...defaultProps} closeText='Close' />
- </HocWithI18n>,
+ <HocWithI18n {...defaultProps} closeText='Close' />,
)
const closeButton = getByText('Close')
fireEvent.click(closeButton)
@@ -72,9 +66,7 @@ describe('Modal component', () => {
it('calls onSubmit when submit button is clicked', () => {
const onSubmit = jest.fn()
const { getByText } = render(
- <HocWithI18n>
- <Modal {...defaultProps} onSubmit={onSubmit} submitText='Submit' />
- </HocWithI18n>,
+ <HocWithI18n {...defaultProps} onSubmit={onSubmit} submitText='Submit' />,
)
const submitButton = getByText('Submit')
fireEvent.click(submitButton)
@@ -84,27 +76,21 @@ describe('Modal component', () => {
it('renders custom buttons', () => {
const customButtons = <button type='button'>Custom Button</button>
const { getByText } = render(
- <HocWithI18n>
- <Modal {...defaultProps} customButtons={customButtons} />
- </HocWithI18n>,
+ <HocWithI18n {...defaultProps} customButtons={customButtons} />,
)
expect(getByText('Custom Button')).toBeInTheDocument()
})
it('renders beta badge when isBeta prop is true', () => {
const { getByText } = render(
- <HocWithI18n>
- <Modal {...defaultProps} isBeta />
- </HocWithI18n>,
+ <HocWithI18n {...defaultProps} isBeta />,
)
expect(getByText('beta.title')).toBeInTheDocument()
})
it('snapshot', () => {
const { asFragment } = render(
- <HocWithI18n>
- <Modal {...defaultProps} />
- </HocWithI18n>,
+ <HocWithI18n {...defaultProps} />,
)
expect(asFragment()).toMatchSnapshot()
})
diff --git a/src/ui/__test__/Pagination.test.tsx b/src/ui/__test__/Pagination.test.tsx
index 568016ba1..60bf088a3 100644
--- a/src/ui/__test__/Pagination.test.tsx
+++ b/src/ui/__test__/Pagination.test.tsx
@@ -22,11 +22,9 @@ describe('Pagination', () => {
}
// use HOC to wrap component with I18nextProvider
- const HocWithI18n = ({ children }: {
- children: React.ReactNode,
- }): JSX.Element => (
+ const HocWithI18n = (props: any): JSX.Element => (
<I18nextProvider i18n={i18n}>
- {children}
+ <Pagination {...props} />
</I18nextProvider>
)
@@ -59,9 +57,7 @@ describe('Pagination', () => {
it('renders with default props', () => {
const { getByText } = render(
- <HocWithI18n>
- <Pagination {...defaultProps} />
- </HocWithI18n>,
+ <HocWithI18n {...defaultProps} />,
)
expect(getByText('1')).toBeInTheDocument()
expect(getByText('10')).toBeInTheDocument()
@@ -71,9 +67,7 @@ describe('Pagination', () => {
it('renders on page > 1', () => {
defaultProps.page = 2
const { getByText } = render(
- <HocWithI18n>
- <Pagination {...defaultProps} />
- </HocWithI18n>,
+ <HocWithI18n {...defaultProps} />,
)
expect(getByText('1')).toBeInTheDocument()
expect(getByText('10')).toBeInTheDocument()
@@ -84,9 +78,7 @@ describe('Pagination', () => {
it('renders on page > 1 and page < pageAmount', () => {
defaultProps.page = 5
const { getByText } = render(
- <HocWithI18n>
- <Pagination {...defaultProps} />
- </HocWithI18n>,
+ <HocWithI18n {...defaultProps} />,
)
expect(getByText('1')).toBeInTheDocument()
expect(getByText('10')).toBeInTheDocument()
@@ -97,9 +89,7 @@ describe('Pagination', () => {
it('renders on page = pageAmount', () => {
defaultProps.page = 10
const { getByText } = render(
- <HocWithI18n>
- <Pagination {...defaultProps} />
- </HocWithI18n>,
+ <HocWithI18n {...defaultProps} />,
)
expect(getByText('1')).toBeInTheDocument()
expect(getByText('10')).toBeInTheDocument()
@@ -110,9 +100,7 @@ describe('Pagination', () => {
defaultProps.page = 10
defaultProps.total = 101
const { getByText } = render(
- <HocWithI18n>
- <Pagination {...defaultProps} />
- </HocWithI18n>,
+ <HocWithI18n {...defaultProps} />,
)
expect(getByText('1')).toBeInTheDocument()
expect(getByText('11')).toBeInTheDocument()
@@ -121,9 +109,7 @@ describe('Pagination', () => {
it('snapshot', () => {
const { container } = render(
- <HocWithI18n>
- <Pagination {...defaultProps} />
- </HocWithI18n>,
+ <HocWithI18n {...defaultProps} />,
)
expect(container).toMatchSnapshot()
})
diff --git a/src/ui/__test__/TimezonePicker.test.tsx b/src/ui/__test__/TimezonePicker.test.tsx
index e079afcd5..b3184a914 100644
--- a/src/ui/__test__/TimezonePicker.test.tsx
+++ b/src/ui/__test__/TimezonePicker.test.tsx
@@ -2,6 +2,8 @@
/* eslint-disable import/no-extraneous-dependencies */
import React from 'react'
import { fireEvent, render } from '@testing-library/react'
+import { I18nextProvider } from 'react-i18next'
+import i18n from 'i18next'
import TimezonePicker from '../TimezonePicker'
@@ -12,9 +14,33 @@ describe('TimezonePricker', () => {
jest.clearAllMocks()
})
+ const HocWithI18n = (props: any): JSX.Element => (
+ <I18nextProvider i18n={i18n}>
+ <TimezonePicker {...props} />
+ </I18nextProvider>
+ )
+
+ // initialize i18n before each test
+ beforeEach(() => {
+ i18n.init({
+ lng: 'en',
+ resources: {
+ en: {
+ profileSettings: {
+ timezoneDesc: 'Timezone description',
+ },
+ },
+ },
+ })
+ })
+
+ afterEach(() => {
+ jest.resetAllMocks()
+ })
+
it('renders the component', () => {
const { getByText } = render(
- <TimezonePicker value='Europe/London' onChange={onChange} />,
+ <HocWithI18n value='Europe/London' onChange={onChange} />,
)
expect(getByText('(GMT+1:00) Edinburgh, London')).toBeInTheDocument()
@@ -22,7 +48,7 @@ describe('TimezonePricker', () => {
it('calls onChange function when an option is selected', () => {
const { getByText, getByRole } = render(
- <TimezonePicker value='Europe/London' onChange={onChange} />,
+ <HocWithI18n value='Europe/London' onChange={onChange} />,
)
fireEvent.click(getByRole('button'))
@@ -36,7 +62,7 @@ describe('TimezonePricker', () => {
it('snapshots', () => {
const { container } = render(
- <TimezonePicker value='Europe/London' onChange={onChange} />,
+ <HocWithI18n value='Europe/London' onChange={onChange} />,
)
expect(container).toMatchSnapshot()
diff --git a/src/ui/__test__/__snapshots__/Beta.test.tsx.snap b/src/ui/__test__/__snapshots__/Beta.test.tsx.snap
index e9b54627e..3a3cf2f25 100644
--- a/src/ui/__test__/__snapshots__/Beta.test.tsx.snap
+++ b/src/ui/__test__/__snapshots__/Beta.test.tsx.snap
@@ -4,6 +4,7 @@ exports[`Beta component snapshot 1`] = `
<div>
<div
class="w-5 h-5 relative flex flex-col group items-center max-w-content !w-full"
+ data-testid="tooltip-wrapper"
>
<p
class="px-2 inline-flex text-sm leading-5 font-normal rounded-full bg-yellow-200 text-yellow-800 dark:bg-yellow-300 dark:text-yellow-900"
diff --git a/src/ui/__test__/__snapshots__/Chart.test.tsx.snap b/src/ui/__test__/__snapshots__/Chart.test.tsx.snap
index f411196da..bab01cccf 100644
--- a/src/ui/__test__/__snapshots__/Chart.test.tsx.snap
+++ b/src/ui/__test__/__snapshots__/Chart.test.tsx.snap
@@ -16,7 +16,7 @@ exports[`Chart component snapshot 1`] = `
>
<defs>
<clippath
- id="bb-10089432076500000-clip"
+ id="bb-8754287941272330-clip"
>
<rect
height="226"
@@ -24,7 +24,7 @@ exports[`Chart component snapshot 1`] = `
/>
</clippath>
<clippath
- id="bb-10089432076500000-clip-xaxis"
+ id="bb-8754287941272330-clip-xaxis"
>
<rect
height="110"
@@ -34,7 +34,7 @@ exports[`Chart component snapshot 1`] = `
/>
</clippath>
<clippath
- id="bb-10089432076500000-clip-yaxis"
+ id="bb-8754287941272330-clip-yaxis"
>
<rect
height="240"
@@ -44,7 +44,7 @@ exports[`Chart component snapshot 1`] = `
/>
</clippath>
<clippath
- id="bb-10089432076500000-clip-grid"
+ id="bb-8754287941272330-clip-grid"
>
<rect
height="226"
@@ -58,7 +58,7 @@ exports[`Chart component snapshot 1`] = `
>
<g
class="bb-grid"
- clip-path="url(http://localhost/#bb-10089432076500000-clip-grid)"
+ clip-path="url(http://localhost/#bb-8754287941272330-clip-grid)"
>
<g
class="bb-xgrid-focus"
@@ -74,7 +74,7 @@ exports[`Chart component snapshot 1`] = `
</g>
<g
class="bb-chart"
- clip-path="url(http://localhost/#bb-10089432076500000-clip)"
+ clip-path="url(http://localhost/#bb-8754287941272330-clip)"
>
<g
class="bb-event-rects bb-event-rects-single"
@@ -215,7 +215,7 @@ exports[`Chart component snapshot 1`] = `
</g>
<g
class="bb-axis bb-axis-x"
- clip-path="url(http://localhost/#bb-10089432076500000-clip-xaxis)"
+ clip-path="url(http://localhost/#bb-8754287941272330-clip-xaxis)"
transform="translate(0, 226)"
>
<text
@@ -370,7 +370,7 @@ exports[`Chart component snapshot 1`] = `
</g>
<g
class="bb-axis bb-axis-y"
- clip-path="url(http://localhost/#bb-10089432076500000-clip-yaxis)"
+ clip-path="url(http://localhost/#bb-8754287941272330-clip-yaxis)"
transform="translate(0, 0)"
>
<text