add test for question delete; fix bug with delete question
This commit is contained in:
@@ -72,7 +72,7 @@ class IntentDetails extends Component {
|
||||
rightIcon={
|
||||
<SVGIcon
|
||||
onClick={() => {
|
||||
this.deleteQuestion (question);
|
||||
this.deleteQuestion (index);
|
||||
}}
|
||||
>
|
||||
{' '}
|
||||
@@ -146,12 +146,10 @@ class IntentDetails extends Component {
|
||||
this.setState ({intent: newIntent});
|
||||
}
|
||||
|
||||
deleteQuestion (question) {
|
||||
deleteQuestion (index) {
|
||||
if (this.state.intent.questions.length > 1) {
|
||||
let newIntent = this.state.intent;
|
||||
let removeId = newIntent.questions.indexOf (question);
|
||||
if (removeId !== -1) newIntent.questions.splice (removeId, 1);
|
||||
|
||||
if (index >= 0 && index < newIntent.questions.length) newIntent.questions.splice (index, 1);
|
||||
this.setState ({intent: newIntent});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,17 +99,45 @@ describe('complete testing', () => {
|
||||
|
||||
});
|
||||
|
||||
xit ('removes correct text field when delete button on text field is clicked', () => {
|
||||
it ('removes correct text field when delete button on text field is clicked', () => {
|
||||
const addButton = wrapper.find('button').at(0);
|
||||
addButton.simulate('click');
|
||||
addButton.simulate('click');
|
||||
const firstQuestionTextField = wrapper.find('TextField').at(2);
|
||||
const secondQuestionTextField = wrapper.find('TextField').at(3);
|
||||
const thirdQuestionTextField = wrapper.find('TextField').at(4);
|
||||
|
||||
let firstQuestionTextField = wrapper.find('TextField').at(2);
|
||||
let secondQuestionTextField = wrapper.find('TextField').at(3);
|
||||
let thirdQuestionTextField = wrapper.find('TextField').at(4);
|
||||
|
||||
firstQuestionTextField.instance().props.onChange('first question');
|
||||
secondQuestionTextField.instance().props.onChange('second question');
|
||||
thirdQuestionTextField.instance().props.onChange('third question');
|
||||
|
||||
expect(firstQuestionTextField.instance().value).toEqual('first question');
|
||||
expect(secondQuestionTextField.instance().value).toEqual('second question');
|
||||
expect(thirdQuestionTextField.instance().value).toEqual('third question');
|
||||
expect(wrapper.state('intent').questions.length).toBe(3);
|
||||
|
||||
const rightIcon = secondQuestionTextField.props().rightIcon;
|
||||
rightIcon.props.onClick(secondQuestionTextField.props().key);
|
||||
|
||||
expect(wrapper.state('intent').questions.length).toBe(2);
|
||||
expect(secondQuestionTextField.instance().value).toEqual('third question');
|
||||
expect(thirdQuestionTextField.instance()._field._field).toBeNull();
|
||||
});
|
||||
|
||||
it ('does not remove text field when it is only one left', () => {
|
||||
let firstQuestionTextField = wrapper.find('TextField').at(2);
|
||||
|
||||
firstQuestionTextField.instance().props.onChange('first question');
|
||||
|
||||
expect(firstQuestionTextField.props().id).toEqual('intent question');
|
||||
expect(secondQuestionTextField.props().id).toEqual('intent question');
|
||||
expect(thirdQuestionTextField.props().id).toEqual('intent question');
|
||||
//TODO: simulate click on delete icon inside text field and check if text field is removed
|
||||
expect(wrapper.state('intent').questions.length).toBe(1);
|
||||
|
||||
const rightIcon = firstQuestionTextField.props().rightIcon;
|
||||
rightIcon.props.onClick(firstQuestionTextField.props().key);
|
||||
|
||||
expect(wrapper.state('intent').questions.length).toBe(1);
|
||||
expect(firstQuestionTextField.instance().value).toEqual('first question');
|
||||
});
|
||||
|
||||
it ('accepts text without special characters for intent explanation', () => {
|
||||
|
||||
Reference in New Issue
Block a user