// test-utils.js
import React from 'react'
import type { RenderResult } from '@testing-library/react'
import { render as rtlRender } from '@testing-library/react'
import { IntlProvider } from 'react-intl'
import { TestingProvider } from '@planview/pv-utilities'

function render(
    ui: Parameters<typeof rtlRender>[0],
    { locale = 'en', ...renderOptions } = {}
): RenderResult {
    function Wrapper({ children }: { children: React.ReactNode }) {
        return <IntlProvider locale={locale}>{children}</IntlProvider>
    }
    return rtlRender(ui, { wrapper: Wrapper, ...renderOptions })
}

// re-export everything
export * from '@testing-library/react'

// override render method
export { render }

export const snapshot = (str: string, ui: Parameters<typeof rtlRender>[0]) => {
    test(str, () => {
        const { container } = render(<TestingProvider>{ui}</TestingProvider>)
        expect(container.firstChild).toMatchSnapshot()
    })
}
