Fix for exception if label is not permitted
Fixes exception caused by combination of default_value and absence of label in permitted labels Change-Id: I9d45fcbfdc2520a34baab6ff435efec1f4e26b33
This commit is contained in:
		@@ -66,7 +66,8 @@
 | 
			
		||||
    _getLabelValue(labels, permittedLabels, label) {
 | 
			
		||||
      if (label.value) {
 | 
			
		||||
        return label.value;
 | 
			
		||||
      } else if (labels[label.name].hasOwnProperty('default_value')) {
 | 
			
		||||
      } else if (labels[label.name].hasOwnProperty('default_value') &&
 | 
			
		||||
                 permittedLabels.hasOwnProperty(label.name)) {
 | 
			
		||||
        // default_value is an int, convert it to string label, e.g. "+1".
 | 
			
		||||
        return permittedLabels[label.name].find(
 | 
			
		||||
            value => parseInt(value, 10) === labels[label.name].default_value);
 | 
			
		||||
 
 | 
			
		||||
@@ -281,5 +281,33 @@ limitations under the License.
 | 
			
		||||
      flushAsynchronousOperations();
 | 
			
		||||
      assert.strictEqual(element.selectedValue, '-1');
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    test('default_value is null if not permitted', () => {
 | 
			
		||||
      element.permittedLabels = {
 | 
			
		||||
        Verified: [
 | 
			
		||||
          '-1',
 | 
			
		||||
          ' 0',
 | 
			
		||||
          '+1',
 | 
			
		||||
        ],
 | 
			
		||||
      };
 | 
			
		||||
      element.labels = {
 | 
			
		||||
        'Code-Review': {
 | 
			
		||||
          values: {
 | 
			
		||||
            '0': 'No score',
 | 
			
		||||
            '+1': 'good',
 | 
			
		||||
            '+2': 'excellent',
 | 
			
		||||
            '-1': 'bad',
 | 
			
		||||
            '-2': 'terrible',
 | 
			
		||||
          },
 | 
			
		||||
          default_value: -1,
 | 
			
		||||
        },
 | 
			
		||||
      };
 | 
			
		||||
      element.label = {
 | 
			
		||||
        name: 'Code-Review',
 | 
			
		||||
        value: null,
 | 
			
		||||
      };
 | 
			
		||||
      flushAsynchronousOperations();
 | 
			
		||||
      assert.isNull(element.selectedValue);
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
</script>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user