import React from 'react'; import { render, screen, cleanup } from '@testing-library/react'; import { Formula } from '.'; afterEach(() => cleanup()); describe('', () => { it('should render formula parts individually', () => { render(Li4Ti5O12); expect(screen.getByText('Li')).toBeInTheDocument(); expect(screen.getByText('4')).toBeInTheDocument(); expect(screen.getByText('Ti')).toBeInTheDocument(); expect(screen.getByText('5')).toBeInTheDocument(); expect(screen.getByText('O')).toBeInTheDocument(); /** Multi-digit numbers should be rendered digit by digit */ expect(screen.getByText('1')).toBeInTheDocument(); expect(screen.getByText('2')).toBeInTheDocument(); }); it('should render elements as spans', () => { render(Li4Ti5O12); expect(screen.getByText('Li').tagName).toBe('SPAN'); expect(screen.getByText('Ti').tagName).toBe('SPAN'); expect(screen.getByText('O').tagName).toBe('SPAN'); }); it('should render numbers as subscripts', () => { render(Li4Ti5O12); expect(screen.getByText('4').tagName).toBe('SUB'); expect(screen.getByText('5').tagName).toBe('SUB'); expect(screen.getByText('1').tagName).toBe('SUB'); expect(screen.getByText('2').tagName).toBe('SUB'); }); it('should render non-elements as subscripts', () => { render(LiFexMn2-xO4); expect(screen.getAllByText('x')[0].tagName).toBe('SUB'); expect(screen.getByText('2').tagName).toBe('SUB'); expect(screen.getByText('-').tagName).toBe('SUB'); expect(screen.getAllByText('x')[1].tagName).toBe('SUB'); expect(screen.getByText('4').tagName).toBe('SUB'); }); it('should render decimals as subscripts', () => { render(Y0.95VO4); expect(screen.getByText('0').tagName).toBe('SUB'); expect(screen.getByText('.').tagName).toBe('SUB'); expect(screen.getByText('9').tagName).toBe('SUB'); expect(screen.getByText('5').tagName).toBe('SUB'); expect(screen.getByText('4').tagName).toBe('SUB'); }); });