import { mount } from 'enzyme';
import React from 'react';
import assert from 'assert';
import SurveyTask from './';
import Choice from './choice';
import { workflow } from '../../../pages/dev-classifier/mock-data';

describe('Survey Task', function(){
  let annotation = { value: [] };
  const task = workflow.tasks.survey
  let wrapper;

  beforeEach(function(){
    wrapper = mount(<SurveyTask task={task} annotation={annotation} />);
  });

  it(`should render a survey task`, function(){
    assert.equal(wrapper.prop('task'), task);
  });

  annotation = { 
    value: [{
      "choice": "ar",
      "answers": {
        "ho": "two",
        "be": [
          "ea"
        ]
      },
      "filters": {}
    }]
  };

  it(`should render a valid annotation as a selected choice`, function(){
    wrapper.setProps({ annotation });
    wrapper.update();
    const selectedChoice = wrapper.find('[data-choiceID="ar"]');
    assert.equal(selectedChoice.prop('className'), 'survey-task-chooser-choice-button survey-task-chooser-choice-button-chosen');
  });

  it('should render the Choice component when a choice is selected', function(){
    wrapper.setState({ selectedChoiceID: 'ar' });
    const choice = wrapper.find(Choice);
    assert.equal(choice.props().choiceID, 'ar');
  });

  it('should pass existing answers to the Choice component', function(){
    wrapper.setState({ selectedChoiceID: 'ar' });
    const choice = wrapper.find(Choice);
    assert.equal(choice.props().annotationValue, annotation.value[0]);
  });
  
  it('should reset saved choices when the annotation resets', function(){
    annotation = { value: [] };
    wrapper.setState({ selectedChoiceID: 'ar' });
    wrapper.setProps({ annotation });
    wrapper.update();
    const choice = wrapper.find(Choice);
    assert.equal(choice.props().annotationValue.answers.ho, undefined);
  });
})
@@ -1606,34 +1606,110 @@
     
-annotation = %7B value: %5B%5D %7D
+wrapper.setState(%7B selectedChoiceID: '' %7D);%0A    wrapper.setProps(%7B annotation %7D);%0A    wrapper.update()
 ;%0A  
@@ -1781,32 +1781,47 @@
 ops(%7B annotation
+: %7B value: %5B%5D %7D
  %7D);%0A    wrapper
@@ -1944,16 +1944,74 @@
 fined);%0A
+    assert.equal(choice.node.state.answers.ho, undefined)%0A
   %7D);%0A%7D)

Test that choice component initial state is in sync with props.