All files / components/Utils Plaintext.js

100% Statements 6/6
100% Branches 4/4
100% Functions 2/2
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24          369x 1x   368x 368x 368x         1405x                
import { Fragment } from 'react';
 
// based in part on this SO answer: https://codereview.stackexchange.com/a/211511
 
export default function Plaintext({text}) {
  if (text==null) {
    return (<pre data-testid="plaintext-empty"></pre>)
  }
  const textToRender = typeof text === "string" ? text : JSON.stringify(text, null, 2);
  const [firstLine, ...rest] = textToRender.split('\n')
  return (
    <pre data-testid="plaintext">
      <span>{ firstLine }</span>
      {
        rest.map((line, i) => (
          <Fragment key={i}>
            <br />
            <span>{ line }</span>
          </Fragment>
        ))
      }
    </pre>
  );
}