import describe from 'tape';
import dom from 'cheerio';
import React from 'react';
import ReactDOMServer from 'react-dom/server';

import withFeatures from '../../with-features';
import configureFeature from '../../configure-feature';

const render = ReactDOMServer.renderToStaticMarkup;

/*
Test Scenarios: ✔ ✗
  no features
    no config
      no fallbackComponent ✗
      with fallbackComponent
    empty config object
      no fallbackComponent
      with fallbackComponent
  with features
    config with initialFeatures
      one feature enabled
        with props ✗
      two features enabled
      no features enabled
    config with initialFeatures plus overrides from URL search params
*/

describe('integration of withFeatures() & configureFeature()', ({ test }) => {
  test('...no config (no features), no fallbackComponent', ({ end, deepEqual }) => {
    const NotFound = () => <div className="not-found">No help for you today!</div>;
    const HelpChatComponent = () => <div className="help-chat">Need help? Call XXX-XXX-XXXX</div>;
    const FeatureComponent = withFeatures()(HelpChatComponent);
    const ConfiguredFeature = configureFeature(NotFound)('help')(FeatureComponent);

    const $ = dom.load(
      render(
        <FeatureComponent>
          <ConfiguredFeature />
        </FeatureComponent>
      )
    );
    {
      const msg = 'it should render NotFound component';
      const actual = $('.not-found').length;
      const expected = 1;
      deepEqual(actual, expected, msg);
    }
    {
      const msg = 'it should not render the Feature component';
      const actual = $('.feature').length;
      const expected = 0;
      deepEqual(actual, expected, msg);
    }
    {
      const msg = 'it should not render the Fallback component';
      const actual = $('.fall-back').length;
      const expected = 0;
      deepEqual(actual, expected, msg);
    }
    end();
  });

  // test('...config with initialFeatures, no fallbackComponent, with props', ({ end, deepEqual }) => {
  //   const initialFeatures = {
  //     comments: {
  //       enabled: false,
  //       dependencies: []
  //     },
  //     help: {
  //       enabled: true,
  //       dependencies: []
  //     },
  //     sorting: {
  //       enabled: false,
  //       dependencies: []
  //     }
  //   };
  //
  //   const WrappedComponent = createWrappedComponent();
  //   const FeatureComponent = withFeatures({ initialFeatures })(WrappedComponent);
  //   const NotFound = createTestComponent('not-found');
  //   const ConfiguredFeature = configureFeature(NotFound)('help')(FeatureComponent);
  //   // const FeatureWithContext = withContext([])(ConfiguredFeature);
  //
  //   const someOtherProp = 'bacon and eggs';
  //
  //   const $ = dom.load(
  //     render(<ConfiguredFeature someOtherProp={someOtherProp} />)
  //   );
  //   {
  //     const msg = 'it should not render NotFound component';
  //     const actual = $('.not-found').length;
  //     const expected = 0;
  //     deepEqual(actual, expected, msg);
  //   }
  //   {
  //     const msg = 'it should render the Feature component';
  //     const actual = $('.feature').length;
  //     const expected = 1;
  //     deepEqual(actual, expected, msg);
  //   }
  //   {
  //     const msg = 'it should not render the Fallback component';
  //     const actual = $('.fall-back').length;
  //     const expected = 0;
  //     deepEqual(actual, expected, msg);
  //   }
  //   {
  //     const msg = 'it should pass through received props';
  //     const actual = $('.some-other-prop').text();
  //     const expected = someOtherProp;
  //     deepEqual(actual, expected, msg);
  //   }
  //   end();
  // });
});

@@ -304,13 +304,9 @@
 ios:
- %E2%9C%94 %E2%9C%97
 %0A
+
   no
@@ -536,24 +536,26 @@
 ture enabled
+ %E2%9C%94
 %0A        wit
@@ -561,18 +561,16 @@
 th props
- %E2%9C%97
 %0A      t
@@ -1604,50 +1604,1464 @@
 $('.
-feature').length;%0A      const expected = 0
+help-chat').length;%0A      const expected = 0;%0A      deepEqual(actual, expected, msg);%0A    %7D%0A    %7B%0A      const msg = 'it should not render the Fallback component';%0A      const actual = $('.fall-back').length;%0A      const expected = 0;%0A      deepEqual(actual, expected, msg);%0A    %7D%0A    end();%0A  %7D);%0A%0A  test('...config with initialFeatures, no fallbackComponent', (%7B end, deepEqual %7D) =%3E %7B%0A    const initialFeatures = %7B%0A      comments: %7B%0A        enabled: false,%0A        dependencies: %5B%5D%0A      %7D,%0A      help: %7B%0A        enabled: true,%0A        dependencies: %5B%5D%0A      %7D,%0A      sorting: %7B%0A        enabled: false,%0A        dependencies: %5B%5D%0A      %7D%0A    %7D;%0A%0A    const NotFound = () =%3E %3Cdiv className=%22not-found%22%3ENo help for you today!%3C/div%3E;%0A    const HelpChatComponent = () =%3E %3Cdiv className=%22help-chat%22%3ENeed help? Call XXX-XXX-XXXX%3C/div%3E;%0A    const FeatureComponent = withFeatures(%7B initialFeatures %7D)(HelpChatComponent);%0A    const ConfiguredFeature = configureFeature(NotFound)('help')(FeatureComponent);%0A%0A    const $ = dom.load(%0A      render(%0A        %3CFeatureComponent%3E%0A          %3CConfiguredFeature /%3E%0A        %3C/FeatureComponent%3E%0A      )%0A    );%0A    %7B%0A      const msg = 'it should not render NotFound component';%0A      const actual = $('.not-found').length;%0A      const expected = 0;%0A      deepEqual(actual, expected, msg);%0A    %7D%0A    %7B%0A      const msg = 'it should render the Feature component';%0A      const actual = $('.help-chat').length;%0A      const expected = 1
 ;%0A  

Add with initialConfig test