a zip code crypto-currency system good for red ONLY

input-tester.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. (function (factory) {
  2. if (typeof module === "object" && typeof module.exports === "object") {
  3. var v = factory(require, exports);
  4. if (v !== undefined) module.exports = v;
  5. }
  6. else if (typeof define === "function" && define.amd) {
  7. define(["require", "exports", "@angular/core"], factory);
  8. }
  9. })(function (require, exports) {
  10. "use strict";
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. var core_1 = require("@angular/core");
  13. var lorem_ipsum = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi maximus nisl lobortis interdum condimentum. Cras volutpat, massa quis vehicula eleifend, turpis mauris sodales erat, ut varius ligula ipsum et turpis. Aliquam erat volutpat. Maecenas sodales pellentesque auctor. Suspendisse faucibus a erat sit amet pretium. Vestibulum nec tempus tellus. Mauris fringilla faucibus dui sed vestibulum. Curabitur porttitor consectetur nisl. Nulla porta, neque sed congue tempus, erat nunc rutrum diam, eu elementum sapien leo quis eros. Donec non convallis felis. Nam eu pharetra sapien.';
  14. exports.TEXT_CORPUS = [
  15. ['hola', 'hola'],
  16. ['', ''],
  17. [' ', ' '],
  18. ['adiós', 'adiós'],
  19. ['hola y adiós', 'hola y adiós'],
  20. [lorem_ipsum, lorem_ipsum]
  21. ];
  22. exports.NUMBER_CORPUS = [
  23. [-1, -1],
  24. [0, 0],
  25. [-123456789, -123456789],
  26. [1.1234, 1.1234],
  27. [123456789, 123456789],
  28. ['1.1234', 1.1234],
  29. ['123456789', 123456789],
  30. ['-123456789', -123456789]
  31. ];
  32. exports.BOOLEAN_CORPUS = [
  33. [true, true],
  34. [false, false],
  35. ['', true],
  36. ['false', false],
  37. ['true', true],
  38. ];
  39. exports.ANY_CORPUS = [
  40. [true, true],
  41. [false, false],
  42. [0, 0],
  43. ['', ''],
  44. [' ', ' '],
  45. ['hola', 'hola']
  46. ];
  47. function commonInputTest(input, config) {
  48. // TODO test form register/deregister
  49. // TODO test item classes
  50. // TODO test disable
  51. var zone = new core_1.NgZone({ enableLongStackTrace: true });
  52. zone.run(function () {
  53. if (config.testItem === true && !input._item) {
  54. (void 0) /* assert */;
  55. }
  56. if (config.testForm === true && !input._form) {
  57. (void 0) /* assert */;
  58. }
  59. // Run tests before initialization
  60. testInput(input, config, false);
  61. input.ngAfterContentInit();
  62. input.ngAfterViewInit && input.ngAfterViewInit();
  63. // Run tests after initialization
  64. testInput(input, config, true);
  65. // Run tests without item
  66. if (config.testItem === true && !input._item) {
  67. input._item = undefined;
  68. testInput(input, config, true);
  69. }
  70. // Run tests without item
  71. if (config.testForm === true && !input._form) {
  72. input._form = undefined;
  73. testInput(input, config, true);
  74. }
  75. testInput(input, config, true);
  76. input.ngOnDestroy();
  77. (void 0) /* assert */;
  78. });
  79. }
  80. exports.commonInputTest = commonInputTest;
  81. function testInput(input, config, isInit) {
  82. testState(input, config, isInit);
  83. testWriteValue(input, config, isInit);
  84. testNgModelChange(input, config, isInit);
  85. }
  86. function testState(input, config, isInit) {
  87. assertEqual(input._init, isInit, 'input must be init');
  88. assertEqual(input._isFocus, false, 'should not be focus');
  89. assertEqual(input.isFocus(), false, 'should not be focus');
  90. assertEqual(input.value, config.defaultValue, 'default value is wrong');
  91. if (isInit) {
  92. var blurCount_1 = 0;
  93. var focusCount_1 = 0;
  94. var onTouchedCalled_1 = 0;
  95. var subBlur = input.ionBlur.subscribe(function (ev) {
  96. assertEqual(ev, input, 'ionBlur argument is wrong');
  97. blurCount_1++;
  98. if (config.onFocusChange && config.onFocusChange(false) !== true) {
  99. (void 0) /* assert */;
  100. }
  101. });
  102. var subFocus = input.ionFocus.subscribe(function (ev) {
  103. assertEqual(ev, input, 'ionFocus argument is wrong');
  104. focusCount_1++;
  105. if (config.onFocusChange && config.onFocusChange(true) !== true) {
  106. (void 0) /* assert */;
  107. }
  108. });
  109. input.registerOnTouched(function () {
  110. assertEqual(onTouchedCalled_1, 0, 'registerOnTouched: internal error');
  111. onTouchedCalled_1++;
  112. });
  113. input._fireBlur();
  114. assertEqual(blurCount_1, 0, 'blur should not have been emitted');
  115. assertEqual(onTouchedCalled_1, 0, 'touched should not have been called');
  116. input._fireFocus();
  117. assertEqual(input._isFocus, true, 'should be focus');
  118. assertEqual(input.isFocus(), true, 'should be focus');
  119. input._fireFocus();
  120. input._fireBlur();
  121. assertEqual(input._isFocus, false, 'should be not focus');
  122. assertEqual(input.isFocus(), false, 'should be not focus');
  123. assertEqual(onTouchedCalled_1, 1, 'touched should have been called');
  124. input._fireBlur(); // it should not crash
  125. assertEqual(focusCount_1, 1, 'ionFocus was not called correctly');
  126. assertEqual(blurCount_1, 1, 'ionBlur was not called correctly');
  127. subBlur.unsubscribe();
  128. subFocus.unsubscribe();
  129. }
  130. }
  131. function testWriteValue(input, config, isInit) {
  132. var test;
  133. var i;
  134. var ionChangeCalled = 0;
  135. var OnChangeCalled = 0;
  136. var OnTouchedCalled = 0;
  137. var ngModelValue;
  138. // Test ionChange
  139. var sub = input.ionChange.subscribe(function (ev) {
  140. assertEqual(ionChangeCalled, 0, 'ionChange: internal error');
  141. assertEqual(ev, input, 'ionChange: ev is not the input');
  142. assertEqual(ev.value, test[1], 'ionChange: value does not match');
  143. assertEqual(ngModelValue, test[1], 'ionChange: ngmodel was not updated');
  144. ionChangeCalled++;
  145. });
  146. // Test registerOnChange
  147. input.registerOnChange(function (ev) {
  148. assertEqual(OnChangeCalled, 0, 'registerOnChange: internal error');
  149. assertEqual(input.value, ev, 'registerOnChange: ev output does not match');
  150. assertEqual(input.value, test[1], 'registerOnChange: value does not match');
  151. ngModelValue = ev;
  152. OnChangeCalled++;
  153. });
  154. // Test registerOnTouched
  155. input.registerOnTouched(function () {
  156. assertEqual(OnTouchedCalled, 0, 'registerOnTouched: internal error');
  157. OnTouchedCalled++;
  158. });
  159. // Run corpus
  160. for (i = 0; i < config.corpus.length; i++) {
  161. test = config.corpus[i];
  162. input.value = test[0];
  163. assertEqual(input.value, test[1], 'loop: input/output does not match');
  164. if (isInit) {
  165. assertEqual(ionChangeCalled, 1, 'loop: ionChange error');
  166. if (config.onValueChange && config.onValueChange(test[1]) !== true) {
  167. (void 0) /* assert */;
  168. }
  169. }
  170. else {
  171. assertEqual(ionChangeCalled, 0, 'loop: ionChange error');
  172. }
  173. assertEqual(OnChangeCalled, 1, 'loop: OnChangeCalled was not called');
  174. assertEqual(OnTouchedCalled, 0, 'loop: OnTouchedCalled was called');
  175. OnTouchedCalled = OnChangeCalled = ionChangeCalled = 0;
  176. // Set same value (it should not redispatch)
  177. input.value = test[0];
  178. assertEqual(ionChangeCalled, 0, 'loop: ionChange should not be called');
  179. assertEqual(OnChangeCalled, 0, 'loop: OnChangeCalled should not be called');
  180. // TODO OnTouchedCalled?
  181. OnTouchedCalled = OnChangeCalled = ionChangeCalled = 0;
  182. }
  183. // Test undefined
  184. input.value = undefined;
  185. assertEqual(input.value, test[1], 'undefined should not change the value');
  186. assertEqual(ionChangeCalled, 0, 'undefined: ionChange should not be called');
  187. assertEqual(OnChangeCalled, 0, 'undefined: OnChangeCalled should not be called');
  188. assertEqual(OnTouchedCalled, 0, 'undefined: OnTouchedCalled should not be called');
  189. // Test null (reset)
  190. test = [null, config.defaultValue];
  191. input.value = null;
  192. assertEqual(input.value, config.defaultValue, 'null: wrong default value');
  193. assertEqual(OnChangeCalled, 1, 'null: OnChangeCalled was not called');
  194. assertEqual(OnTouchedCalled, 0, 'null: OnTouchedCalled was called');
  195. input.registerOnChange(null);
  196. input.registerOnTouched(null);
  197. sub.unsubscribe();
  198. }
  199. function testNgModelChange(input, config, isInit) {
  200. var test;
  201. var i;
  202. var ionChangeCalled = 0;
  203. var OnChangeCalled = 0;
  204. var OnTouchedCalled = 0;
  205. // Test ionChange
  206. var sub = input.ionChange.subscribe(function (ev) {
  207. assertEqual(ionChangeCalled, 0, 'internal error');
  208. assertEqual(ev, input, 'ev output does not match');
  209. assertEqual(test[1], ev.value, 'value does not match');
  210. ionChangeCalled++;
  211. });
  212. // Test registerOnChange
  213. input.registerOnChange(function () {
  214. OnChangeCalled++;
  215. });
  216. // Test registerOnChange
  217. input.registerOnTouched(function () {
  218. OnTouchedCalled++;
  219. });
  220. // Run corpus
  221. for (i = 0; i < config.corpus.length; i++) {
  222. test = config.corpus[i];
  223. input.writeValue(test[0]);
  224. assertEqual(input.value, test[1], 'input/output does not match');
  225. if (isInit) {
  226. assertEqual(ionChangeCalled, 1, 'ionChange error');
  227. if (config.onValueChange && config.onValueChange(test[1]) !== true) {
  228. (void 0) /* assert */;
  229. }
  230. }
  231. else {
  232. assertEqual(ionChangeCalled, 0, 'ionChange error');
  233. }
  234. assertEqual(OnChangeCalled, 0, 'OnChangeCalled should not be called');
  235. assertEqual(OnTouchedCalled, 0, 'OnTouchedCalled should not be called');
  236. OnTouchedCalled = OnChangeCalled = ionChangeCalled = 0;
  237. // Set same value (it should not redispatch)
  238. input.writeValue(test[0]);
  239. input.value = test[0];
  240. assertEqual(ionChangeCalled, 0, 'ionChange should not be called');
  241. assertEqual(OnChangeCalled, 0, 'OnChangeCalled should not be called');
  242. // TODO OnTouchedCalled?
  243. OnTouchedCalled = OnChangeCalled = ionChangeCalled = 0;
  244. }
  245. input.registerOnChange(null);
  246. input.registerOnTouched(null);
  247. sub.unsubscribe();
  248. input.value = config.defaultValue;
  249. }
  250. function assertEqual(a, b, message) {
  251. if (!equal(a, b)) {
  252. (void 0) /* assert */;
  253. }
  254. }
  255. function equal(a, b) {
  256. if (a === b) {
  257. return true;
  258. }
  259. // return false;
  260. return JSON.stringify(a) === JSON.stringify(b);
  261. }
  262. });
  263. //# sourceMappingURL=input-tester.js.map