|
| 1 | +import React from 'react'; |
| 2 | +import { render, screen } from '@testing-library/react'; |
| 3 | +import { Text } from '..'; |
| 4 | + |
| 5 | +describe('Text component', () => { |
| 6 | + it('renders text content', () => { |
| 7 | + render(<Text>Test Text</Text>); |
| 8 | + expect(screen.getByText('Test Text')).toBeInTheDocument(); |
| 9 | + }); |
| 10 | + |
| 11 | + it('renders with default props', () => { |
| 12 | + render(<Text>Default Text</Text>); |
| 13 | + const defaultText = screen.getByText('Default Text'); |
| 14 | + expect(defaultText).toHaveClass("derivs-text__weight--normal") |
| 15 | + |
| 16 | + }); |
| 17 | + |
| 18 | + it('renders with custom props', () => { |
| 19 | + render( |
| 20 | + <Text |
| 21 | + align="center" |
| 22 | + as="div" |
| 23 | + color="primary" |
| 24 | + fontStyle="italic" |
| 25 | + lineHeight="md" |
| 26 | + size="lg" |
| 27 | + weight="bold" |
| 28 | + className="custom-class" |
| 29 | + > |
| 30 | + Custom Text |
| 31 | + </Text> |
| 32 | + ); |
| 33 | + const customText = screen.getByText('Custom Text'); |
| 34 | + expect(customText).toBeInTheDocument(); |
| 35 | + expect(customText.tagName.toLowerCase()).toBe('div'); |
| 36 | + expect(customText).toHaveClass('deriv-text'); |
| 37 | + expect(customText).toHaveClass('derivs-text__size--lg'); |
| 38 | + expect(customText).toHaveClass('derivs-text__weight--bold'); |
| 39 | + expect(customText).toHaveClass('derivs-text__align--center'); |
| 40 | + expect(customText).toHaveClass('derivs-text__color--primary'); |
| 41 | + expect(customText).toHaveClass('derivs-text__line-height--md'); |
| 42 | + expect(customText).toHaveClass('custom-class'); |
| 43 | + }); |
| 44 | + |
| 45 | + it('renders with custom tag', () => { |
| 46 | + render(<Text as="h1">Header Text</Text>); |
| 47 | + const headerText = screen.getByText('Header Text'); |
| 48 | + expect(headerText.tagName.toLowerCase()).toBe('h1'); |
| 49 | + }); |
| 50 | +}); |
0 commit comments