import { render, screen, waitFor } from '@testing-library/react';
import { ThemeProvider, ThemeProviderProps } from './ThemeProvider';
import { useState } from 'react';
describe('ThemeProvider', () => {
it('tests local theme provider (isNotRootProvider) has not affect on root theme (on html element)', () => {
render(
local-theme-provider
,
);
// global theme isn't affected (in this case isn't set)
expect(document.documentElement).not.toHaveClass(
'np-theme-personal',
'np-theme-personal--dark',
);
// only local theme being set
// eslint-disable-next-line testing-library/no-node-access
expect(screen.getByText('local-theme-provider').parentElement).toHaveClass(
'np-theme-personal np-theme-personal--dark',
);
});
it('tests root provider set root theme (on html element) and it is not affected by nested provider(s)', () => {
render(
root-dark-theme
nested-forest-green
nested-personal
,
);
// root provider set dark theme and it wasn't changed by two nested providers
expect(document.documentElement).toHaveClass('np-theme-personal np-theme-personal--dark');
// eslint-disable-next-line testing-library/no-node-access
expect(screen.getByText('root-dark-theme').parentElement).toHaveClass(
'np-theme-personal np-theme-personal--dark',
);
// eslint-disable-next-line testing-library/no-node-access
expect(screen.getByText('nested-forest-green').parentElement).toHaveClass(
'np-theme-personal np-theme-personal--forest-green',
);
// eslint-disable-next-line testing-library/no-node-access
expect(screen.getByText('nested-personal').parentElement).toHaveClass('np-theme-personal');
});
it('tests deprecated light theme normalization', () => {
render(