testhelpers.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Copyright 2009 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Common test functions for tweak unit tests.
  16. *
  17. * @author agrieve@google.com (Andrew Grieve)
  18. * @package
  19. */
  20. goog.provide('goog.tweak.testhelpers');
  21. goog.setTestOnly();
  22. goog.require('goog.tweak');
  23. goog.require('goog.tweak.BooleanGroup');
  24. goog.require('goog.tweak.BooleanInGroupSetting');
  25. goog.require('goog.tweak.BooleanSetting');
  26. goog.require('goog.tweak.ButtonAction');
  27. goog.require('goog.tweak.NumericSetting');
  28. goog.require('goog.tweak.Registry');
  29. goog.require('goog.tweak.StringSetting');
  30. var boolEntry;
  31. var boolEntry2;
  32. var strEntry;
  33. var strEntry2;
  34. var strEnumEntry;
  35. var numEntry;
  36. var numEnumEntry;
  37. var boolGroup;
  38. var boolOneEntry;
  39. var boolTwoEntry;
  40. var buttonEntry;
  41. /**
  42. * Creates a registry with some entries in it.
  43. * @param {string} queryParams The query parameter string to use for the
  44. * registry.
  45. * @param {!Object<string|number|boolean>=} opt_compilerOverrides Compiler
  46. * overrides.
  47. * @suppress {accessControls} Private state is accessed for test purposes.
  48. */
  49. function createRegistryEntries(queryParams, opt_compilerOverrides) {
  50. // Initialize the registry with the given query string.
  51. var registry =
  52. new goog.tweak.Registry(queryParams, opt_compilerOverrides || {});
  53. goog.tweak.registry_ = registry;
  54. boolEntry = new goog.tweak.BooleanSetting('Bool', 'The bool1');
  55. registry.register(boolEntry);
  56. boolEntry2 = new goog.tweak.BooleanSetting('Bool2', 'The bool2');
  57. boolEntry2.setDefaultValue(true);
  58. registry.register(boolEntry2);
  59. strEntry = new goog.tweak.StringSetting('Str', 'The str1');
  60. strEntry.setParamName('s');
  61. registry.register(strEntry);
  62. strEntry2 = new goog.tweak.StringSetting('Str2', 'The str2');
  63. strEntry2.setDefaultValue('foo');
  64. registry.register(strEntry2);
  65. strEnumEntry = new goog.tweak.StringSetting('Enum', 'The enum');
  66. strEnumEntry.setValidValues(['A', 'B', 'C']);
  67. strEnumEntry.setRestartRequired(false);
  68. registry.register(strEnumEntry);
  69. numEntry = new goog.tweak.NumericSetting('Num', 'The num');
  70. numEntry.setDefaultValue(99);
  71. registry.register(numEntry);
  72. numEnumEntry = new goog.tweak.NumericSetting('Enum2', 'The 2nd enum');
  73. numEnumEntry.setValidValues([1, 2, 3]);
  74. numEnumEntry.setRestartRequired(false);
  75. numEnumEntry.label = 'Enum the second&';
  76. registry.register(numEnumEntry);
  77. boolGroup = new goog.tweak.BooleanGroup('BoolGroup', 'The bool group');
  78. registry.register(boolGroup);
  79. boolOneEntry =
  80. new goog.tweak.BooleanInGroupSetting('BoolOne', 'Desc for 1', boolGroup);
  81. boolOneEntry.setToken('B1');
  82. boolOneEntry.setRestartRequired(false);
  83. boolGroup.addChild(boolOneEntry);
  84. registry.register(boolOneEntry);
  85. boolTwoEntry =
  86. new goog.tweak.BooleanInGroupSetting('BoolTwo', 'Desc for 2', boolGroup);
  87. boolTwoEntry.setDefaultValue(true);
  88. boolGroup.addChild(boolTwoEntry);
  89. registry.register(boolTwoEntry);
  90. buttonEntry =
  91. new goog.tweak.ButtonAction('Button', 'The Btn', goog.nullFunction);
  92. buttonEntry.label = '<btn>';
  93. registry.register(buttonEntry);
  94. var nsBoolGroup =
  95. new goog.tweak.BooleanGroup('foo.bar.BoolGroup', 'Namespaced Bool Group');
  96. registry.register(nsBoolGroup);
  97. var nsBool = new goog.tweak.BooleanInGroupSetting(
  98. 'foo.bar.BoolOne', 'Desc for Namespaced 1', nsBoolGroup);
  99. nsBoolGroup.addChild(nsBool);
  100. registry.register(nsBool);
  101. }