|
| 1 | +import React from 'react'; |
| 2 | +import { render, screen } from '@testing-library/react'; |
| 3 | +import { ActionScreen } from '..'; |
| 4 | + |
| 5 | +describe('ActionScreen component', () => { |
| 6 | + it('should render without crashing', () => { |
| 7 | + render(<ActionScreen />); |
| 8 | + }); |
| 9 | + |
| 10 | + it('should display the title when provided', () => { |
| 11 | + const title = 'Test Title'; |
| 12 | + render(<ActionScreen title={title} />); |
| 13 | + const titleElement = screen.getByText(title); |
| 14 | + expect(titleElement).toBeInTheDocument(); |
| 15 | + }); |
| 16 | + |
| 17 | + it('should not display the title element when title prop is not provided', () => { |
| 18 | + const { queryByText } = render(<ActionScreen />); |
| 19 | + const titleElement = queryByText(/someTitle/i); |
| 20 | + expect(titleElement).toBeNull(); |
| 21 | + }); |
| 22 | + |
| 23 | + it('should display the description when provided', () => { |
| 24 | + const description = 'Test description'; |
| 25 | + render(<ActionScreen description={description} />); |
| 26 | + expect(screen.getByText(description)).toBeInTheDocument(); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should not display the description element when description prop is not provided', () => { |
| 30 | + const { queryByText } = render(<ActionScreen />); |
| 31 | + expect(queryByText(/.+/)).toBeNull(); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should apply the default descriptionSize when not provided', () => { |
| 35 | + render(<ActionScreen description="Sample description" />); |
| 36 | + const descriptionElement = screen.getByText('Sample description'); |
| 37 | + expect(descriptionElement).toHaveClass('derivs-text__size--md'); |
| 38 | + }); |
| 39 | + |
| 40 | + it('should apply the specified descriptionSize when provided', () => { |
| 41 | + render( |
| 42 | + <ActionScreen |
| 43 | + description="Test description" |
| 44 | + descriptionSize="lg" |
| 45 | + /> |
| 46 | + ); |
| 47 | + const descriptionElement = screen.getByText('Test description'); |
| 48 | + expect(descriptionElement).toHaveClass('derivs-text__size--lg'); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should apply the default titleSize when not provided', () => { |
| 52 | + render(<ActionScreen title="Sample Title" />); |
| 53 | + const titleElement = screen.getByText('Sample Title'); |
| 54 | + expect(titleElement).toHaveClass('derivs-text__size--md'); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should apply the specified titleSize when provided', () => { |
| 58 | + const { getByText } = render(<ActionScreen title="Test Title" titleSize="lg" />); |
| 59 | + const titleElement = getByText('Test Title'); |
| 60 | + expect(titleElement).toHaveClass('derivs-text__size--lg'); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should display the actionButtons when provided', () => { |
| 64 | + const actionButtons = <button>Click me</button>; |
| 65 | + const { getByText } = render(<ActionScreen actionButtons={actionButtons} />); |
| 66 | + expect(getByText('Click me')).toBeInTheDocument(); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should not display the actionButtons element when actionButtons prop is not provided', () => { |
| 70 | + const { queryByText } = render(<ActionScreen />); |
| 71 | + expect(queryByText('Click me')).not.toBeInTheDocument(); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should render the icon when provided', () => { |
| 75 | + const icon = <span className="custom-icon" />; |
| 76 | + const { container } = render(<ActionScreen icon={icon} />); |
| 77 | + expect(container.querySelector('.custom-icon')).toBeInTheDocument(); |
| 78 | + }); |
| 79 | + |
| 80 | + it('should not render the icon element when icon prop is not provided', () => { |
| 81 | + const { container } = render(<ActionScreen />); |
| 82 | + expect(container.querySelector('.custom-icon')).not.toBeInTheDocument(); |
| 83 | + }); |
| 84 | + |
| 85 | + it('should render Text component for title with correct props', () => { |
| 86 | + const { getByText } = render(<ActionScreen title="Test Title" titleSize="lg" />); |
| 87 | + const titleElement = getByText('Test Title').parentNode; |
| 88 | + expect(titleElement).toHaveClass('derivs-action-screen__info'); |
| 89 | + }); |
| 90 | + |
| 91 | + it('should render Text component for description with correct props', () => { |
| 92 | + const description = "This is a test description"; |
| 93 | + const { getByText } = render(<ActionScreen description={description} descriptionSize="sm" />); |
| 94 | + const descriptionElement = getByText(description).parentNode; |
| 95 | + expect(descriptionElement).toHaveClass('derivs-action-screen__info'); |
| 96 | + }); |
| 97 | + |
| 98 | + it('should correctly render non-element description as Text component', () => { |
| 99 | + const description = "This is a test description"; |
| 100 | + const { getByText } = render(<ActionScreen description={description} />); |
| 101 | + expect(getByText(description)).toBeInTheDocument(); |
| 102 | + }); |
| 103 | +}); |
0 commit comments