/** * Copyright (c) Paymium. * * This source code is licensed under the MIT license found in the * LICENSE file in the root of this projects source tree. */ import React from 'react'; import { render, screen } from '@crossed/test'; import { ButtonIcon } from '../Icon'; import { buttonContext } from '../context'; import { afterEach } from '@jest/globals'; const X = jest.fn(() =>
); describe('ButtonIcon', () => { const renderWithContext = (children: React.ReactNode, contextValue: any) => { return render( {children} ); }; afterEach(() => { X.mockReset(); }); it('renders correctly with default props', () => { renderWithContext(null, { variant: 'primary', state: {}, disabled: false }); // Vérifie que rien n'est rendu (pas de children) expect(() => screen.getByTestId('x')).toThrow(); }); it('renders the child element and applies color styles', () => { renderWithContext(, { variant: 'primary', state: { hover: false, active: false }, disabled: false, }); expect(X).toBeCalledWith( { 'color': 'var(--components--action-primary-default-text)' }, {} ); }); it('applies hover styles when state.hover is true', () => { renderWithContext(, { variant: 'primary', state: { hover: true, active: false }, disabled: false, }); expect(X).toBeCalledWith( { 'color': 'var(--components--action-primary-hover-text)' }, {} ); }); it('applies active styles when state.active is true', () => { renderWithContext(, { variant: 'primary', state: { hover: false, active: true }, disabled: false, }); expect(X).toBeCalledWith( { 'color': 'var(--components--action-primary-active-text)' }, {} ); }); it('applies disabled styles when disabled is true', () => { renderWithContext(, { variant: 'primary', state: {}, disabled: true, }); expect(X).toBeCalledWith( { 'color': 'var(--components--action-primary-default-text)' }, {} ); }); it('renders secondary variant styles correctly', () => { renderWithContext(, { variant: 'secondary', state: { hover: false, active: false }, disabled: false, }); expect(X).toBeCalledWith( { 'color': 'var(--components--action-secondary-default-text)' }, {} ); }); it('returns raw children if not a valid React element', () => { const { container } = renderWithContext('Raw Text', { variant: 'primary', state: {}, disabled: false, }); expect(container.textContent).toBe('Raw Text'); }); });