options.spec.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright 2018 Scytl Secure Electronic Voting SA
  3. *
  4. * All rights reserved
  5. *
  6. * See our extended copyright notice in *file 'Copyright.txt' which is part of this source code package
  7. */
  8. /* global OV */
  9. describe('Options contest parser', function() {
  10. 'use strict';
  11. var optionsParser = OV.OptionsParser;
  12. var contest = require('./mocks/options.json');
  13. var contestWithBlank = require('./mocks/optionsWithBlank.json');
  14. it('should parse the options configuration', function() {
  15. var parsed = optionsParser.parse(contest);
  16. expect(parsed.template).toBe('options');
  17. });
  18. it('should parse the questions min and max restrictions', function() {
  19. var parsed = optionsParser.parse(contest);
  20. expect(parsed.questions[0].optionsMinChoices).toBe(1);
  21. expect(parsed.questions[0].optionsMaxChoices).toBe(1);
  22. });
  23. it('should parse the options inside the questions', function() {
  24. var parsed = optionsParser.parse(contest);
  25. expect(parsed.questions[0].options.length).toBe(2);
  26. expect(parsed.questions[0].options
  27. .filter(function(o) { return o.prime === '100003' }).length).toBe(1);
  28. expect(parsed.questions[0].options
  29. .filter(function(o) { return o.prime === '100019' }).length).toBe(1);
  30. });
  31. it('should not parse a blank option as min == max', function() {
  32. contest.questions[0].min = 1;
  33. contest.questions[0].max = 1;
  34. var parsed = optionsParser.parse(contest);
  35. expect(parsed.questions[0].blankOption).toBe(null);
  36. });
  37. it('should parse the blank option as min < max (blank vote allowed)', function() {
  38. var parsed = optionsParser.parse(contestWithBlank);
  39. expect(parsed.questions[0].blankOption.prime).toBe('10009');
  40. });
  41. });