import React from 'react/addons';
import assert from 'assert';
import {
  rendersDomNodeWithTextContent,
  rendersNoDomNodeWithTextContent
} from '../../src/dom-asserts.js';

describe('renders(No)DomNodeWithTextContent', function() {
  
  describe('finds none', function() {
    it('there is none', function() {
      const component = <b></b>;
      rendersNoDomNodeWithTextContent(component, 'bold');
    });
    it('there is one, which should fail', function() {
      const component = <b>bold</b>;
      assert.throws(() => {
        rendersNoDomNodeWithTextContent(component, 'bold');
      });
    });

    describe('error message', function() {
      let errorMessage;
      const component = <b>bold</b>;
      beforeEach(function() {
        try {
          rendersNoDomNodeWithTextContent(component, 'bold');
        } catch (error) {
          errorMessage = error.message;
        }
      });
      it('starts with `Did NOT expect`', function() {
        assert.ok(errorMessage.startsWith('Did NOT expect'), 'Doesnt start with `Did NOT expect`.');
      });
      it('contains the component name in backticks', function() {
        const name = component.type;
        assert.ok(errorMessage.includes(`\`${name}\``), 'Doesn`t contain `<component name>`.');
      });
      it('contains `bold` in backticks', function() {
        assert.ok(errorMessage.includes('`bold`'), 'Doesn`t contain `\`bold\``.');
      });
    });

  });
  
  describe('finds some', function() {
    it('when its the only node', function() {
      const component = <b>bold</b>;
      rendersDomNodeWithTextContent(component, 'bold');
    });
    it('and has another sibling', function() {
      const component = <b>bold<b/></b>;
      rendersDomNodeWithTextContent(component, 'bold');
    });

    describe('error message', function() {
      let errorMessage;
      const component = <b></b>;
      beforeEach(function() {
        try {
          rendersDomNodeWithTextContent(component, 'bold');
        } catch (error) {
          errorMessage = error.message;
        }
      });
      it('starts with `Expected`', function() {
        assert.ok(errorMessage.startsWith('Expected'), 'Doesnt start with `Expected`.');
      });
      it('contains the component name in backticks', function() {
        const name = component.type;
        assert.ok(errorMessage.includes(`\`${name}\``), 'Doesn`t contain `<component name>`.');
      });
      it('contains `bold` in backticks', function() {
        assert.ok(errorMessage.includes('`bold`'), 'Doesn`t contain `\`bold\``.');
      });
    });
  });

  describe('finds combined content', function() {
    it('e.g. <b>({one})</b>', function() {
      const number = 42;
      const component = <b>({number})</b>;
      rendersDomNodeWithTextContent(component, '(42)');
    });
  });

  describe('finds multiple rendered subcomponents', function() {
    it('', function() {
      const numbers = [23, 42];
      const NumberComponent = class extends React.Component {
        render() {return <span>{this.props.number}</span>;}
      };
      const component = (
        <b>
          {numbers.map(number => <NumberComponent number={number} />)}
        </b>
      );
      rendersDomNodeWithTextContent(component, numbers[1]);
    });
  });
  
});

@@ -2822,32 +2822,17 @@
 %0A%0A  
-describe('finds multiple
+it('finds
  ren
@@ -2870,34 +2870,8 @@
 ) %7B%0A
-    it('', function() %7B%0A  
     
@@ -2896,26 +2896,24 @@
 3, 42%5D;%0A    
-  
 const Number
@@ -2956,18 +2956,16 @@
 onent %7B%0A
-  
       re
@@ -3022,19 +3022,15 @@
     
-  
 %7D;%0A    
- 
- 
 cons
@@ -3051,18 +3051,16 @@
 (%0A      
-  
 %3Cb%3E%0A    
@@ -3067,32 +3067,55 @@
     
-  %7Bn
+%3CN
 umber
-s.map(number =%3E
+Component number=%7Bnumbers%5B0%5D%7D /%3E%0A       
  %3CNu
@@ -3146,23 +3146,23 @@
 mber
+s%5B1%5D
 %7D /%3E
-)%7D
 %0A      
-  
 %3C/b%3E
@@ -3170,15 +3170,11 @@
     
-  
 );%0A
-  
     
@@ -3227,24 +3227,16 @@
 rs%5B1%5D);%0A
-    %7D);%0A
   %7D);%0A  

Simplify tests a bit.