Merge pull request #2957 from alphagov/add-js-tests-for-list-entry

Add JS tests for list entry module
This commit is contained in:
Tom Byers
2019-05-17 13:36:52 +01:00
committed by GitHub
2 changed files with 343 additions and 5 deletions

View File

@@ -1,10 +1,6 @@
(function (Modules) {
'use strict';
var root = this,
$ = this.jQuery;
var lists = [],
listEntry,
ListEntry;
@@ -62,6 +58,7 @@
getAttributesHTML = function (attrsByElm) {
var attrStr = '',
elmIdx = attrsByElm.length,
existingAttributes = [],
elmAttrs,
attrIdx;
@@ -69,7 +66,11 @@
elmAttrs = attrsByElm[elmIdx];
attrIdx = elmAttrs.length;
while (attrIdx--) {
attrStr += attributeTemplate.render({ 'name': elmAttrs[attrIdx].name, 'value': elmAttrs[attrIdx].value });
// prevent duplicates
if ($.inArray(elmAttrs[attrIdx].name, existingAttributes) === -1) {
attrStr += attributeTemplate.render({ 'name': elmAttrs[attrIdx].name, 'value': elmAttrs[attrIdx].value });
existingAttributes.push(elmAttrs[attrIdx].name);
}
}
}
return attrStr;