import React from 'react'
import {render, fireEvent} from '@testing-library/react-native'
import {Button, Text} from 'react-native'
import {ThemeProvider, useTheme, useThemeColor} from './ThemeProvider'
import {SupportedThemes, ThemeStorage} from './types'
import {ErrorBoundary} from '@yoroi/common'
describe('ThemeProvider', () => {
let storedValue: SupportedThemes | undefined
const mockStorage: ThemeStorage = {
key: 'theme-name',
save: jest.fn().mockImplementation((v) => (storedValue = v)),
read: jest.fn().mockImplementation(() => storedValue),
}
beforeEach(() => {
storedValue = undefined
})
it('should render children', () => {
const {getByText} = render(
Test
,
)
expect(getByText('Test')).toBeTruthy()
})
it('should provide the theme context', () => {
const TestComponent = () => {
const theme = useTheme()
return {theme.name}
}
const {getByText} = render(
,
)
expect(getByText('system')).toBeTruthy()
})
it('should update the theme when selectThemeName is called', () => {
const TestComponent = () => {
const theme = useTheme()
const color = useThemeColor()
return (
<>
{theme.name}