All files dab-ipsum.tsx

100% Statements 34/34
100% Branches 15/15
100% Functions 8/8
100% Lines 30/30

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 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 15919x 19x                     19x                                                                                                                           19x   19x 7x     19x 300x       20x     19x 19x 19x   19x   10x           1x             8x               19x 19x 3x       19x 5x 10x 10x     23x       5x   1x           1x           1x         2x             19x  
import * as randomSeed from 'random-seed';
import * as React from 'react';
 
export interface IIpsumProps {
  component: 'li' | 'p' | 'text';
}
 
export interface IDabIpsumProps {
  component?: 'ul' | 'ol' | 'p' | 'text';
  count?: number;
}
 
const words = [
  'academia',
  'agile',
  'angular',
  'apprentice',
  'apps',
  'brighton',
  'business',
  'careers',
  'cats',
  'client',
  'coffee',
  'community',
  'css',
  'dabapps',
  'design',
  'designers',
  'development',
  'developers',
  'digital',
  'django',
  'documentation',
  'education',
  'equality',
  'events',
  'framework',
  'green',
  'innovation',
  'ionic',
  'ios',
  'java',
  'javascript',
  'kittens',
  'llamas',
  'mobile',
  'native',
  'networking',
  'news',
  'objective-c',
  'open-source',
  'partnerships',
  'product',
  'projects',
  'prototyping',
  'python',
  'react',
  'react-native',
  'recognition',
  'rest',
  'service',
  'smashing',
  'tea',
  'teaching',
  'technical',
  'testimonial',
  'testing',
  'toolkit',
  'training',
  'typescript',
  'web'
];
 
let rand = randomSeed.create('dabapps');
 
export const resetRandomSeed = () => {
  rand = randomSeed.create('dabapps');
}
 
export const generateIpsum = () => {
  const ipsum = Array.apply(null, new Array(15)).map(() => (
    words[Math.floor(rand.range(words.length))]
  )).join(' ');
 
  return ipsum.charAt(0).toUpperCase() + ipsum.substring(1) + '.';
}
 
export const Ipsum: React.SFC<IIpsumProps> = (props) => {
  const { component } = props;
  const ipsum = generateIpsum();
 
  switch (component) {
    case 'li':
      return (
        <li>
          {ipsum}
        </li>
      );
    case 'text':
      return (
        <span>
          {ipsum}
        </span>
      );
    // case 'p': NOTE: this is the default, so a case for it is not needed
    default:
      return (
        <p>
          {ipsum}
        </p>
      );
  }
};
 
export class DabIpsum extends React.Component<IDabIpsumProps, void> {
  public shouldComponentUpdate (prevProps: IDabIpsumProps) {
    return prevProps.component !== this.props.component ||
      prevProps.count !== this.props.count;
  }
 
  public render () {
    const {
      component = 'p',
      count = 5
    } = this.props;
 
    const items = Array.apply(null, new Array(count)).map((v: void, index: number) => (
      <Ipsum key={index} component={component === 'p' ? component : 'li'} />
    ));
 
    switch (component) {
      case 'ul':
        return (
          <ul>
            {items}
          </ul>
        );
      case 'ol':
        return (
          <ol>
            {items}
          </ol>
        );
      case 'text':
        return (
          <Ipsum component="text" />
        );
      // case 'p': NOTE: this is the default, so a case for it is not needed
      default:
        return (
          <div>
            {items}
          </div>
        );
    }
  }
}