|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0 and the Server Side Public License, v 1; you may not use this file except |
| 5 | + * in compliance with, at your election, the Elastic License 2.0 or the Server |
| 6 | + * Side Public License, v 1. |
| 7 | + */ |
| 8 | + |
| 9 | +import React from 'react'; |
| 10 | +import { render } from '../../../../test/rtl'; |
| 11 | +import { EuiMarkdownFormat } from '../../index'; |
| 12 | + |
| 13 | +describe('remarkIntrawordUnderscore', () => { |
| 14 | + it('preserves identifiers with double underscores as plain text', () => { |
| 15 | + const { container } = render( |
| 16 | + <EuiMarkdownFormat> |
| 17 | + {`ABDC__AppleBanana__c |
| 18 | + ABDC__MangoKiwi__c |
| 19 | + ABDC__PineappleCherry__c`} |
| 20 | + </EuiMarkdownFormat> |
| 21 | + ); |
| 22 | + |
| 23 | + expect(container.querySelector('strong')).not.toBeInTheDocument(); |
| 24 | + expect(container).toHaveTextContent('ABDC__AppleBanana__c'); |
| 25 | + expect(container).toHaveTextContent('ABDC__MangoKiwi__c'); |
| 26 | + expect(container).toHaveTextContent('ABDC__PineappleCherry__c'); |
| 27 | + }); |
| 28 | + |
| 29 | + it('preserves identifiers with single underscores as plain text', () => { |
| 30 | + const { container } = render( |
| 31 | + <EuiMarkdownFormat>{'some_variable_name'}</EuiMarkdownFormat> |
| 32 | + ); |
| 33 | + |
| 34 | + expect(container.querySelector('em')).not.toBeInTheDocument(); |
| 35 | + expect(container).toHaveTextContent('some_variable_name'); |
| 36 | + }); |
| 37 | + |
| 38 | + it('still applies bold for standalone double underscores', () => { |
| 39 | + const { container } = render( |
| 40 | + <EuiMarkdownFormat>{'__bold text__'}</EuiMarkdownFormat> |
| 41 | + ); |
| 42 | + |
| 43 | + expect(container.querySelector('strong')).toHaveTextContent('bold text'); |
| 44 | + }); |
| 45 | + |
| 46 | + it('still applies emphasis for standalone single underscores', () => { |
| 47 | + const { container } = render( |
| 48 | + <EuiMarkdownFormat>{'_italic text_'}</EuiMarkdownFormat> |
| 49 | + ); |
| 50 | + |
| 51 | + expect(container.querySelector('em')).toHaveTextContent('italic text'); |
| 52 | + }); |
| 53 | + |
| 54 | + it('handles multiple identifiers in a sentence', () => { |
| 55 | + const { container } = render( |
| 56 | + <EuiMarkdownFormat> |
| 57 | + {'Fields ABDC__AppleBanana__c and ABDC__MangoKiwi__c are required'} |
| 58 | + </EuiMarkdownFormat> |
| 59 | + ); |
| 60 | + |
| 61 | + expect(container.querySelector('strong')).not.toBeInTheDocument(); |
| 62 | + expect(container).toHaveTextContent( |
| 63 | + 'Fields ABDC__AppleBanana__c and ABDC__MangoKiwi__c are required' |
| 64 | + ); |
| 65 | + }); |
| 66 | +}); |
0 commit comments