/* eslint-disable camelcase */
import { test } from 'qunit';
import moduleForAcceptance from 'frontend/tests/helpers/module-for-acceptance';

let surveyTemplate;
moduleForAcceptance('Acceptance | questions collapsible', {
  beforeEach() {
    server.loadFixtures();
    surveyTemplate = server.create('survey-template');
  }
});

test('collapsing and uncollapsing', async function(assert) {
  assert.expect(5);
  server.logging = true;
  let topAncestry = server.create('question', { question_text: 'top', surveyTemplate, answer_type_id: 57 }); // Answer Type id 57 = `Repeater`
  server.createList('question', 2, { surveyTemplate, parent_id: topAncestry.id, ancestry: topAncestry.id });
  let firstAncestry = server.create('question', {
    question_text: 'first',
    surveyTemplate,
    answer_type_id: 56, // Answer Type id 56 = `Section`
    parent_id: topAncestry.id,
    ancestry: topAncestry.id
  });
  server.createList('question', 2, {
    surveyTemplate,
    parent_id: firstAncestry.id,
    ancestry: `${topAncestry.id}/${firstAncestry.id}`
  });
  let secondAncestry = server.create('question', {
    question_text: 'second',
    surveyTemplate,
    answer_type_id: 56, // Answer Type id 56 = `Section`
    parent_id: firstAncestry.id,
    ancestry: `${topAncestry.id}/${firstAncestry.id}`
  });
  server.createList('question', 2, {
    surveyTemplate,
    parent_id: secondAncestry.id,
    ancestry: `${topAncestry.id}/${firstAncestry.id}/${secondAncestry.id}`
  });

  await visit(`/survey_templates/${surveyTemplate.id}`);
  assert.equal(find('[data-question-id]').length, 9, 'all questions displayed');
  await click(`[data-question-id="${secondAncestry.id}"] [data-test-collapse]`);
  assert.equal(find('[data-question-id]').length, 7, '2 questions hidden');
  await click(`[data-question-id="${firstAncestry.id}"] [data-test-collapse]`);
  assert.equal(find('[data-question-id]').length, 4, '3 questions hidden');
  await click(`[data-question-id="${topAncestry.id}"] [data-test-collapse]`);
  assert.equal(find('[data-question-id]').length, 1, '2 questions hidden');
  await click(`[data-question-id="${topAncestry.id}"] [data-test-collapse]`);
  assert.equal(find('[data-question-id]').length, 4, 'only 3 questions showen');
});

@@ -400,17 +400,17 @@
 .expect(
-5
+8
 );%0A  ser
@@ -429,16 +429,146 @@
 = true;%0A
+  server.create('question', %7B question_text: 'top sibiling', surveyTemplate, answer_type_id: 15 %7D); // Answer Type id 15 = %60text%60%0A
   let to
@@ -1658,24 +1658,37 @@
 late.id%7D%60);%0A
+  // Showing%0A
   assert.equ
@@ -1729,16 +1729,20 @@
 th, 
-9
+2
 , 'all 
+top 
 ques
@@ -1756,24 +1756,512 @@
 isplayed');%0A
+  await click(%60%5Bdata-question-id=%22$%7BtopAncestry.id%7D%22%5D %5Bdata-test-collapse%5D%60);%0A  assert.equal(find('%5Bdata-question-id%5D').length, 5, 'only 4 questions showen');%0A  await click(%60%5Bdata-question-id=%22$%7BfirstAncestry.id%7D%22%5D %5Bdata-test-collapse%5D%60);%0A  assert.equal(find('%5Bdata-question-id%5D').length, 8, '8 questions showen');%0A  await click(%60%5Bdata-question-id=%22$%7BsecondAncestry.id%7D%22%5D %5Bdata-test-collapse%5D%60);%0A  assert.equal(find('%5Bdata-question-id%5D').length, 10, '10 questions showen');%0A%0A  // Hidding%0A
   await clic
@@ -2379,17 +2379,17 @@
 length, 
-7
+8
 , '2 que
@@ -2535,17 +2535,17 @@
 length, 
-4
+5
 , '3 que
@@ -2689,17 +2689,17 @@
 length, 
-1
+2
 , '2 que
@@ -2843,17 +2843,17 @@
 length, 
-4
+5
 , 'only 

fix collapsing test