function testSetMultipleTemplatesWithThreeTemplates() {
  var extensionItem1Id = 'extension1_test_id';
  var extensionItem1 = {
    id: extensionItem1Id,
    type: 'line',
    text: HTML_STRING,
    insertAfter: RADIO2['id']
  };

  var extensionItem2Id = 'extension2_test_id';
  var extensionItem2 = {
    id: extensionItem2Id,
    type: 'info',
    text: HTML_STRING,
    insertAfter: RADIO2['id']
  };

  var baseQuestionnaire = {'questionnaire': [BLOCK1], 'version': 4};
  var extension1 = {
    'extensions': [extensionItem1], 'version': 4, 'namespace': 'test1'};
  var extension2 = {
    'extensions': [extensionItem2], 'version': 4, 'namespace': 'test2'};

  var q = new vsaq.Questionnaire(root);
  q.setMultipleTemplates(baseQuestionnaire, extension1, extension2);

  // Make sure that items from extensions are rendered and visible.
  var rendered_extension1_item = q.items_[extensionItem1['id']];
  assertTrue(rendered_extension1_item.isVisible());
  var rendered_extension2_item = q.items_[extensionItem2['id']];
  assertTrue(rendered_extension2_item.isVisible());

  // Make sure that inserted items from extensions are at the right position.
  // Since extension2 was applied after extension1 with
  // "insertAfter: RADIO2['id']", the new order should look like:
  //   [..., RADIO2, extensionItem2, extensionItem1, ...]
  var block1Items = BLOCK1['items'];
  var radio2Pos = goog.array.indexOf(block1Items, RADIO2);
  var element1PositionAfterRadio = block1Items[radio2Pos + 1];
  var element2PositionsAfterRadio = block1Items[radio2Pos + 2];
  assertEquals(extensionItem2, element1PositionAfterRadio);
  assertEquals(extensionItem1, element2PositionsAfterRadio);

  // Make sure that the namespaces were applied to inserted item ids.
  assertEquals(
      extension1['namespace'] + ':' + extensionItem1Id, extensionItem1['id']);
  assertEquals(
      extension2['namespace'] + ':' + extensionItem2Id, extensionItem2['id']);
}
/**
 * Tests merging of three templates.
 */
Tests merging of three templates.
Tests merging of three templates .
function testSetMultipleTemplatesWithThreeTemplates() {
  var extensionItem1Id = 'extension1_test_id';
  var extensionItem1 = {
    id: extensionItem1Id,
    type: 'line',
    text: HTML_STRING,
    insertAfter: RADIO2['id']
  };
  var extensionItem2Id = 'extension2_test_id';
  var extensionItem2 = {
    id: extensionItem2Id,
    type: 'info',
    text: HTML_STRING,
    insertAfter: RADIO2['id']
  };
  var baseQuestionnaire = {'questionnaire': [BLOCK1], 'version': 4};
  var extension1 = {
    'extensions': [extensionItem1], 'version': 4, 'namespace': 'test1'};
  var extension2 = {
    'extensions': [extensionItem2], 'version': 4, 'namespace': 'test2'};
  var q = new vsaq.Questionnaire(root);
  q.setMultipleTemplates(baseQuestionnaire, extension1, extension2);
  var rendered_extension1_item = q.items_[extensionItem1['id']];
  assertTrue(rendered_extension1_item.isVisible());
  var rendered_extension2_item = q.items_[extensionItem2['id']];
  assertTrue(rendered_extension2_item.isVisible());
  var block1Items = BLOCK1['items'];
  var radio2Pos = goog.array.indexOf(block1Items, RADIO2);
  var element1PositionAfterRadio = block1Items[radio2Pos + 1];
  var element2PositionsAfterRadio = block1Items[radio2Pos + 2];
  assertEquals(extensionItem2, element1PositionAfterRadio);
  assertEquals(extensionItem1, element2PositionsAfterRadio);
  assertEquals(
      extension1['namespace'] + ':' + extensionItem1Id, extensionItem1['id']);
  assertEquals(
      extension2['namespace'] + ':' + extensionItem2Id, extensionItem2['id']);
}
function testSetMultipleTemplatesWithThreeTemplates ( ) { var extensionItem1Id = 'extension1_test_id' ; var extensionItem1 = { id : extensionItem1Id , type : 'line' , text : HTML_STRING , insertAfter : RADIO2 [ 'id' ] } ; var extensionItem2Id = 'extension2_test_id' ; var extensionItem2 = { id : extensionItem2Id , type : 'info' , text : HTML_STRING , insertAfter : RADIO2 [ 'id' ] } ; var baseQuestionnaire = { 'questionnaire' : [ BLOCK1 ] , 'version' : 4 } ; var extension1 = { 'extensions' : [ extensionItem1 ] , 'version' : 4 , 'namespace' : 'test1' } ; var extension2 = { 'extensions' : [ extensionItem2 ] , 'version' : 4 , 'namespace' : 'test2' } ; var q = new vsaq . Questionnaire ( root ) ; q . setMultipleTemplates ( baseQuestionnaire , extension1 , extension2 ) ; var rendered_extension1_item = q . items_ [ extensionItem1 [ 'id' ] ] ; assertTrue ( rendered_extension1_item . isVisible ( ) ) ; var rendered_extension2_item = q . items_ [ extensionItem2 [ 'id' ] ] ; assertTrue ( rendered_extension2_item . isVisible ( ) ) ; var block1Items = BLOCK1 [ 'items' ] ; var radio2Pos = goog . array . indexOf ( block1Items , RADIO2 ) ; var element1PositionAfterRadio = block1Items [ radio2Pos + 1 ] ; var element2PositionsAfterRadio = block1Items [ radio2Pos + 2 ] ; assertEquals ( extensionItem2 , element1PositionAfterRadio ) ; assertEquals ( extensionItem1 , element2PositionsAfterRadio ) ; assertEquals ( extension1 [ 'namespace' ] + ':' + extensionItem1Id , extensionItem1 [ 'id' ] ) ; assertEquals ( extension2 [ 'namespace' ] + ':' + extensionItem2Id , extensionItem2 [ 'id' ] ) ; }
Tests merging of three templates.
Tests merging of three templates .
// Make sure that items from extensions are rendered and visible. // Make sure that inserted items from extensions are at the right position. // Since extension2 was applied after extension1 with // "insertAfter: RADIO2['id']", the new order should look like: //   [..., RADIO2, extensionItem2, extensionItem1, ...] // Make sure that the namespaces were applied to inserted item ids.