PageRenderTime 59ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/ext-4.0.7/src/core/test/unit/spec/Ext.js

https://bitbucket.org/srogerf/javascript
JavaScript | 1559 lines | 1222 code | 321 blank | 16 comment | 1 complexity | 0ba5ab1ebf3713b47aed37b81d19612b MD5 | raw file
  1. /*
  2. This file is part of Ext JS 4
  3. Copyright (c) 2011 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  7. If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
  8. */
  9. describe("Ext", function() {
  10. describe("Ext.global", function() {
  11. it("should return the global scope", function() {
  12. expect(Ext.global).toBe((function(){ return this;}).call());
  13. });
  14. });
  15. describe("Ext.apply", function() {
  16. var origin, o;
  17. beforeEach(function() {
  18. origin = {
  19. name: 'value',
  20. something: 'cool',
  21. items: [1,2,3],
  22. method: function() {
  23. this.myMethodCalled = true;
  24. },
  25. toString: function() {
  26. this.myToStringCalled = true;
  27. }
  28. };
  29. });
  30. it("should copy normal properties", function() {
  31. Ext.apply(origin, {
  32. name: 'newName',
  33. items: [4,5,6],
  34. otherThing: 'not cool',
  35. isCool: false
  36. });
  37. expect(origin.name).toEqual('newName');
  38. expect(origin.items).toEqual([4,5,6]);
  39. expect(origin.something).toEqual('cool');
  40. expect(origin.otherThing).toEqual('not cool');
  41. expect(origin.isCool).toEqual(false);
  42. });
  43. it("should copy functions", function() {
  44. Ext.apply(origin, {
  45. method: function() {
  46. this.newMethodCalled = true;
  47. }
  48. });
  49. origin.method();
  50. expect(origin.myMethodCalled).not.toBeDefined();
  51. expect(origin.newMethodCalled).toBeTruthy();
  52. });
  53. it("should copy non-enumerables", function() {
  54. Ext.apply(origin, {
  55. toString: function() {
  56. this.newToStringCalled = true;
  57. }
  58. });
  59. origin.toString();
  60. expect(origin.myToStringCalled).not.toBeDefined();
  61. expect(origin.newToStringCalled).toBeTruthy();
  62. });
  63. it("should apply properties and return an object", function() {
  64. o = Ext.apply({}, {
  65. foo: 1,
  66. bar: 2
  67. });
  68. expect(o).toEqual({
  69. foo: 1,
  70. bar: 2
  71. });
  72. });
  73. it("should change the reference of the object", function() {
  74. o = {};
  75. Ext.apply(o, {
  76. opt1: 'x',
  77. opt2: 'y'
  78. });
  79. expect(o).toEqual({
  80. opt1: 'x',
  81. opt2: 'y'
  82. });
  83. });
  84. it("should overwrite properties", function() {
  85. o = Ext.apply({
  86. foo: 1,
  87. baz: 4
  88. }, {
  89. foo: 2,
  90. bar: 3
  91. });
  92. expect(o).toEqual({
  93. foo: 2,
  94. bar: 3,
  95. baz: 4
  96. });
  97. });
  98. it("should use default", function() {
  99. o = {};
  100. Ext.apply(o, {
  101. foo: 'new',
  102. exist: true
  103. }, {
  104. foo: 'old',
  105. def: true
  106. });
  107. expect(o).toEqual({
  108. foo: 'new',
  109. def: true,
  110. exist: true
  111. });
  112. });
  113. it("should override all defaults", function() {
  114. o = Ext.apply({}, {
  115. foo: 'foo',
  116. bar: 'bar'
  117. }, {
  118. foo: 'oldFoo',
  119. bar: 'oldBar'
  120. });
  121. expect(o).toEqual( {
  122. foo: 'foo',
  123. bar: 'bar'
  124. });
  125. });
  126. it("should return null if null is passed as first argument", function() {
  127. expect(Ext.apply(null, {})).toBeNull();
  128. });
  129. it("should return the object if second argument is no defined", function() {
  130. o = {
  131. foo: 1
  132. };
  133. expect(Ext.apply(o)).toEqual(o);
  134. });
  135. it("should override valueOf", function() {
  136. o = Ext.apply({}, {valueOf: 1});
  137. expect(o.valueOf).toEqual(1);
  138. });
  139. it("should override toString", function() {
  140. o = Ext.apply({}, {toString: 3});
  141. expect(o.toString).toEqual(3);
  142. });
  143. });
  144. describe("Ext.emptyFn", function() {
  145. it("should return undefined without params", function() {
  146. expect(Ext.emptyFn()).toBeUndefined();
  147. });
  148. it("should return undefined if you pass params", function() {
  149. expect(Ext.emptyFn('aaaa', 'bbbbb')).toBeUndefined();
  150. });
  151. });
  152. describe("Ext.iterate", function() {
  153. var itFn;
  154. beforeEach(function() {
  155. itFn = jasmine.createSpy();
  156. });
  157. describe("iterate object", function() {
  158. var o;
  159. beforeEach(function() {
  160. o = {
  161. n1: 11,
  162. n2: 13,
  163. n3: 18
  164. };
  165. });
  166. describe("if itFn does not return false", function() {
  167. beforeEach(function() {
  168. Ext.iterate(o, itFn);
  169. });
  170. it("should call the iterate function 3 times", function () {
  171. expect(itFn.callCount).toEqual(3);
  172. });
  173. it("should call the iterate function with correct arguments", function () {
  174. expect(itFn.calls[0].args).toEqual(["n1", 11, o]);
  175. expect(itFn.calls[1].args).toEqual(["n2", 13, o]);
  176. expect(itFn.calls[2].args).toEqual(["n3", 18, o]);
  177. });
  178. });
  179. describe("if itFn return false", function() {
  180. beforeEach(function() {
  181. itFn.andReturn(false);
  182. Ext.iterate(o, itFn);
  183. });
  184. it("should stop iteration if function return false", function() {
  185. itFn.andReturn(false);
  186. expect(itFn.calls.length).toEqual(1);
  187. });
  188. });
  189. });
  190. describe("do nothing on an empty object", function() {
  191. var o;
  192. beforeEach(function() {
  193. o = {};
  194. Ext.iterate(o, itFn);
  195. });
  196. it("should not call the iterate function", function () {
  197. expect(itFn).not.toHaveBeenCalled();
  198. });
  199. });
  200. describe("iterate array", function() {
  201. var arr;
  202. beforeEach(function() {
  203. arr = [6, 7, 8, 9];
  204. });
  205. describe("if itFn does not return false", function() {
  206. beforeEach(function() {
  207. Ext.iterate(arr, itFn);
  208. });
  209. it("should call the iterate function 4 times", function () {
  210. expect(itFn.callCount).toEqual(4);
  211. });
  212. it("should call the iterate function with correct arguments", function () {
  213. expect(itFn.calls[0].args).toEqual([6, 0, arr]);
  214. expect(itFn.calls[1].args).toEqual([7, 1, arr]);
  215. expect(itFn.calls[2].args).toEqual([8, 2, arr]);
  216. expect(itFn.calls[3].args).toEqual([9, 3, arr]);
  217. });
  218. });
  219. describe("if itFn return false", function() {
  220. beforeEach(function() {
  221. itFn.andReturn(false);
  222. Ext.iterate(arr, itFn);
  223. });
  224. it("should stop iteration if function return false", function() {
  225. itFn.andReturn(false);
  226. expect(itFn.calls.length).toEqual(1);
  227. });
  228. });
  229. });
  230. describe("do nothing on an empty array", function() {
  231. var arr;
  232. beforeEach(function() {
  233. arr = [];
  234. Ext.iterate(arr, itFn);
  235. });
  236. it("should not call the iterate function", function () {
  237. expect(itFn).not.toHaveBeenCalled();
  238. });
  239. });
  240. });
  241. describe("Ext.applyIf", function(){
  242. var o;
  243. it("should apply properties and return an object with an empty destination object", function() {
  244. o = Ext.applyIf({}, {
  245. foo: 'foo',
  246. bar: 'bar'
  247. });
  248. expect(o).toEqual( {
  249. foo: 'foo',
  250. bar: 'bar'
  251. });
  252. });
  253. it("should not override default properties", function() {
  254. o = Ext.applyIf({
  255. foo: 'foo'
  256. }, {
  257. foo: 'oldFoo'
  258. });
  259. expect(o).toEqual({
  260. foo: 'foo'
  261. });
  262. });
  263. it("should not override default properties with mixing properties", function() {
  264. o = Ext.applyIf({
  265. foo: 1,
  266. bar: 2
  267. }, {
  268. bar: 3,
  269. baz: 4
  270. });
  271. expect(o).toEqual({
  272. foo: 1,
  273. bar: 2,
  274. baz: 4
  275. });
  276. });
  277. it("should change the reference of the object", function() {
  278. o = {};
  279. Ext.applyIf(o, {
  280. foo: 2
  281. }, {
  282. foo: 1
  283. });
  284. expect(o).toEqual({
  285. foo: 2
  286. });
  287. });
  288. it("should return null if null is passed as first argument", function() {
  289. expect(Ext.applyIf(null, {})).toBeNull();
  290. });
  291. it("should return the object if second argument is no defined", function() {
  292. o = {
  293. foo: 1
  294. };
  295. expect(Ext.applyIf(o)).toEqual(o);
  296. });
  297. });
  298. describe("Ext.extend", function() {
  299. var Dude, Awesome, david;
  300. beforeEach(function() {
  301. Dude = Ext.extend(Object, {
  302. constructor: function(config){
  303. Ext.apply(this, config);
  304. this.isBadass = false;
  305. }
  306. });
  307. Awesome = Ext.extend(Dude, {
  308. constructor: function(){
  309. Awesome.superclass.constructor.apply(this, arguments);
  310. this.isBadass = true;
  311. }
  312. });
  313. david = new Awesome({
  314. davis: 'isAwesome'
  315. });
  316. });
  317. it("should throw an error if superclass isn't defined", function() {
  318. expect(function() {
  319. Ext.extend(undefined, {});
  320. }).toRaiseExtError("Attempting to extend from a class which has not been loaded on the page.");
  321. });
  322. it("should create a superclass that return the original classe", function() {
  323. expect(david.superclass).toEqual(Dude.prototype);
  324. });
  325. it("should add override method", function() {
  326. expect(typeof david.override === 'function').toBe(true);
  327. });
  328. it("should override redefined methods", function() {
  329. expect(david.isBadass).toBe(true);
  330. });
  331. it("should keep new properties", function() {
  332. expect(david.davis).toEqual('isAwesome');
  333. });
  334. });
  335. describe("Ext.override", function(){
  336. var Dude,
  337. extApplySpy;
  338. beforeEach(function(){
  339. Dude = function(){}; // avoid to directly override Object class
  340. extApplySpy = spyOn(Ext, "apply");
  341. });
  342. it("should apply override", function(){
  343. var override = {foo: true};
  344. Ext.override(Dude, override);
  345. expect(extApplySpy).toHaveBeenCalledWith(Dude.prototype, override);
  346. });
  347. });
  348. describe("Ext.valueFrom", function() {
  349. var value, defaultValue;
  350. describe("with allowBlank", function() {
  351. describe("and an empty string", function() {
  352. it("should return the value", function() {
  353. expect(Ext.valueFrom('', 'aaa', true)).toBe('');
  354. });
  355. });
  356. describe("and a string", function() {
  357. it("should return the value", function() {
  358. expect(Ext.valueFrom('bbb', 'aaa', true)).toBe('bbb');
  359. });
  360. });
  361. describe("and an undefined value", function() {
  362. it("should return the default value", function() {
  363. expect(Ext.valueFrom(undefined, 'aaa', true)).toBe('aaa');
  364. });
  365. });
  366. describe("and a null value", function() {
  367. it("should return the default value", function() {
  368. expect(Ext.valueFrom(null, 'aaa', true)).toBe('aaa');
  369. });
  370. });
  371. describe("and a 0 value", function() {
  372. it("should return the value", function() {
  373. expect(Ext.valueFrom(0, 'aaa', true)).toBe(0);
  374. });
  375. });
  376. });
  377. describe("without allowBlank", function() {
  378. describe("and an empty string", function() {
  379. it("should return the default value", function() {
  380. expect(Ext.valueFrom('', 'aaa')).toBe('aaa');
  381. });
  382. });
  383. describe("and a string", function() {
  384. it("should return the value", function() {
  385. expect(Ext.valueFrom('bbb', 'aaa')).toBe('bbb');
  386. });
  387. });
  388. describe("and an undefined value", function() {
  389. it("should return the default value", function() {
  390. expect(Ext.valueFrom(undefined, 'aaa')).toBe('aaa');
  391. });
  392. });
  393. describe("and a null value", function() {
  394. it("should return the default value", function() {
  395. expect(Ext.valueFrom(null, 'aaa')).toBe('aaa');
  396. });
  397. });
  398. describe("and a 0 value", function() {
  399. it("should return the value", function() {
  400. expect(Ext.valueFrom(0, 'aaa')).toBe(0);
  401. });
  402. });
  403. });
  404. });
  405. describe("Ext.typeOf", function() {
  406. it("should return null", function() {
  407. expect(Ext.typeOf(null)).toEqual('null');
  408. });
  409. it("should return undefined", function() {
  410. expect(Ext.typeOf(undefined)).toEqual('undefined');
  411. });
  412. it("should return undefined", function() {
  413. expect(Ext.typeOf(window.someWeirdPropertyThatDoesntExist)).toEqual('undefined');
  414. });
  415. it("should return string", function() {
  416. expect(Ext.typeOf('')).toEqual('string');
  417. });
  418. it("should return string", function() {
  419. expect(Ext.typeOf('something')).toEqual('string');
  420. });
  421. it("should return string", function() {
  422. expect(Ext.typeOf('1.2')).toEqual('string');
  423. });
  424. it("should return number", function() {
  425. expect(Ext.typeOf(1)).toEqual('number');
  426. });
  427. it("should return number", function() {
  428. expect(Ext.typeOf(1.2)).toEqual('number');
  429. });
  430. it("should return boolean", function() {
  431. expect(Ext.typeOf(true)).toEqual('boolean');
  432. });
  433. it("should return boolean", function() {
  434. expect(Ext.typeOf(false)).toEqual('boolean');
  435. });
  436. it("should return array", function() {
  437. expect(Ext.typeOf([1,2,3])).toEqual('array');
  438. });
  439. it("should return array", function() {
  440. expect(Ext.typeOf(new Array(1,2,3))).toEqual('array');
  441. });
  442. it("should return function 1", function() {
  443. expect(Ext.typeOf(function(){})).toEqual('function');
  444. });
  445. // Don't run this test in IE
  446. if (typeof alert === 'function') {
  447. it("should return function 2", function() {
  448. expect(Ext.typeOf(prompt)).toEqual('function');
  449. });
  450. }
  451. it("should return function 3", function() {
  452. expect(Ext.typeOf(new Function())).toEqual('function');
  453. });
  454. it("should return regexp 1", function() {
  455. expect(Ext.typeOf(/test/)).toEqual('regexp');
  456. });
  457. it("should return regexp 2", function() {
  458. expect(Ext.typeOf(new RegExp('test'))).toEqual('regexp');
  459. });
  460. it("should return date", function() {
  461. expect(Ext.typeOf(new Date())).toEqual('date');
  462. });
  463. it("should return textnode", function() {
  464. expect(Ext.typeOf(document.createTextNode('tada'))).toEqual('textnode');
  465. });
  466. it("should return whitespace", function() {
  467. expect(Ext.typeOf(document.createTextNode(' '))).toEqual('whitespace');
  468. });
  469. it("should return whitespace", function() {
  470. expect(Ext.typeOf(document.createTextNode(' '))).toEqual('whitespace');
  471. });
  472. it("should return element", function() {
  473. expect(Ext.typeOf(document.getElementsByTagName('body')[0])).toEqual('element');
  474. });
  475. it("should return element", function() {
  476. expect(Ext.typeOf(document.createElement('button'))).toEqual('element');
  477. });
  478. it("should return element", function() {
  479. expect(Ext.typeOf(new Image())).toEqual('element');
  480. });
  481. it("should return object 1", function() {
  482. expect(Ext.typeOf({some: 'stuff'})).toEqual('object');
  483. });
  484. it("should return object 2", function() {
  485. expect(Ext.typeOf(new Object())).toEqual('object');
  486. });
  487. it("should return object 3", function() {
  488. expect(Ext.typeOf(window)).toEqual('object');
  489. });
  490. it("should return boolean", function() {
  491. expect(Ext.typeOf(new Boolean(true))).toEqual('boolean');
  492. });
  493. it("should return number", function() {
  494. expect(Ext.typeOf(new Number(1.2))).toEqual('number');
  495. });
  496. });
  497. describe("Ext.isIterable", function() {
  498. it("should return true with empty array", function() {
  499. expect(Ext.isIterable([])).toBe(true);
  500. });
  501. it("should return true with filled array", function() {
  502. expect(Ext.isIterable([1, 2, 3, 4])).toBe(true);
  503. });
  504. it("should return false with boolean true", function() {
  505. expect(Ext.isIterable(true)).toBe(false);
  506. });
  507. it("should return false with boolean false", function() {
  508. expect(Ext.isIterable(false)).toBe(false);
  509. });
  510. it("should return false with string", function() {
  511. expect(Ext.isIterable("foo")).toBe(false);
  512. });
  513. it("should return false with empty string", function() {
  514. expect(Ext.isIterable("")).toBe(false);
  515. });
  516. it("should return false with number", function() {
  517. expect(Ext.isIterable(1)).toBe(false);
  518. });
  519. it("should return false with null", function() {
  520. expect(Ext.isIterable(null)).toBe(false);
  521. });
  522. it("should return false with undefined", function() {
  523. expect(Ext.isIterable(undefined)).toBe(false);
  524. });
  525. it("should return false with date", function() {
  526. expect(Ext.isIterable(new Date())).toBe(false);
  527. });
  528. it("should return false with empty object", function() {
  529. expect(Ext.isIterable({})).toBe(false);
  530. });
  531. it("should return true with node list", function() {
  532. expect(Ext.isIterable(document.getElementsByTagName('body'))).toBe(true);
  533. });
  534. it("should return true with html collection", function() {
  535. expect(Ext.isIterable(document.images)).toBe(true);
  536. });
  537. });
  538. describe("Ext.isArray", function() {
  539. it("should return true with empty array", function() {
  540. expect(Ext.isArray([])).toBe(true);
  541. });
  542. it("should return true with filled array", function() {
  543. expect(Ext.isArray([1, 2, 3, 4])).toBe(true);
  544. });
  545. it("should return false with boolean true", function() {
  546. expect(Ext.isArray(true)).toBe(false);
  547. });
  548. it("should return false with boolean false", function() {
  549. expect(Ext.isArray(false)).toBe(false);
  550. });
  551. it("should return false with string", function() {
  552. expect(Ext.isArray("foo")).toBe(false);
  553. });
  554. it("should return false with empty string", function() {
  555. expect(Ext.isArray("")).toBe(false);
  556. });
  557. it("should return false with number", function() {
  558. expect(Ext.isArray(1)).toBe(false);
  559. });
  560. it("should return false with null", function() {
  561. expect(Ext.isArray(null)).toBe(false);
  562. });
  563. it("should return false with undefined", function() {
  564. expect(Ext.isArray(undefined)).toBe(false);
  565. });
  566. it("should return false with date", function() {
  567. expect(Ext.isArray(new Date())).toBe(false);
  568. });
  569. it("should return false with empty object", function() {
  570. expect(Ext.isArray({})).toBe(false);
  571. });
  572. it("should return false with node list", function() {
  573. expect(Ext.isArray(document.getElementsByTagName('body'))).toBe(false);
  574. });
  575. it("should return false with custom class that has a length property", function() {
  576. var C = Ext.extend(Object, {
  577. length: 1
  578. });
  579. expect(Ext.isArray(new C())).toBe(false);
  580. });
  581. it("should return false with element", function() {
  582. expect(Ext.isArray(Ext.getBody().dom)).toBe(false);
  583. });
  584. });
  585. describe("Ext.isBoolean", function() {
  586. it("should return false with empty array", function() {
  587. expect(Ext.isBoolean([])).toBe(false);
  588. });
  589. it("should return false with filled array", function() {
  590. expect(Ext.isBoolean([1, 2, 3, 4])).toBe(false);
  591. });
  592. it("should return true with boolean true", function() {
  593. expect(Ext.isBoolean(true)).toBe(true);
  594. });
  595. it("should return true with boolean false", function() {
  596. expect(Ext.isBoolean(false)).toBe(true);
  597. });
  598. it("should return false with string", function() {
  599. expect(Ext.isBoolean("foo")).toBe(false);
  600. });
  601. it("should return false with empty string", function() {
  602. expect(Ext.isBoolean("")).toBe(false);
  603. });
  604. it("should return false with number", function() {
  605. expect(Ext.isBoolean(1)).toBe(false);
  606. });
  607. it("should return false with null", function() {
  608. expect(Ext.isBoolean(null)).toBe(false);
  609. });
  610. it("should return false with undefined", function() {
  611. expect(Ext.isBoolean(undefined)).toBe(false);
  612. });
  613. it("should return false with date", function() {
  614. expect(Ext.isBoolean(new Date())).toBe(false);
  615. });
  616. it("should return false with empty object", function() {
  617. expect(Ext.isBoolean({})).toBe(false);
  618. });
  619. it("should return false with node list", function() {
  620. expect(Ext.isBoolean(document.getElementsByTagName('body'))).toBe(false);
  621. });
  622. it("should return false with element", function() {
  623. expect(Ext.isArray(Ext.getBody().dom)).toBe(false);
  624. });
  625. });
  626. describe("Ext.isDate", function() {
  627. it("should return false with empty array", function() {
  628. expect(Ext.isDate([])).toBe(false);
  629. });
  630. it("should return false with filled array", function() {
  631. expect(Ext.isDate([1, 2, 3, 4])).toBe(false);
  632. });
  633. it("should return false with boolean true", function() {
  634. expect(Ext.isDate(true)).toBe(false);
  635. });
  636. it("should return false with boolean false", function() {
  637. expect(Ext.isDate(false)).toBe(false);
  638. });
  639. it("should return false with string", function() {
  640. expect(Ext.isDate("foo")).toBe(false);
  641. });
  642. it("should return false with empty string", function() {
  643. expect(Ext.isDate("")).toBe(false);
  644. });
  645. it("should return false with number", function() {
  646. expect(Ext.isDate(1)).toBe(false);
  647. });
  648. it("should return false with null", function() {
  649. expect(Ext.isDate(null)).toBe(false);
  650. });
  651. it("should return false with undefined", function() {
  652. expect(Ext.isDate(undefined)).toBe(false);
  653. });
  654. it("should return true with date", function() {
  655. expect(Ext.isDate(new Date())).toBe(true);
  656. });
  657. it("should return false with empty object", function() {
  658. expect(Ext.isDate({})).toBe(false);
  659. });
  660. it("should return false with node list", function() {
  661. expect(Ext.isDate(document.getElementsByTagName('body'))).toBe(false);
  662. });
  663. it("should return false with element", function() {
  664. expect(Ext.isDate(Ext.getBody().dom)).toBe(false);
  665. });
  666. });
  667. describe("Ext.isDefined", function() {
  668. it("should return true with empty array", function() {
  669. expect(Ext.isDefined([])).toBe(true);
  670. });
  671. it("should return true with filled array", function() {
  672. expect(Ext.isDefined([1, 2, 3, 4])).toBe(true);
  673. });
  674. it("should return true with boolean true", function() {
  675. expect(Ext.isDefined(true)).toBe(true);
  676. });
  677. it("should return true with boolean false", function() {
  678. expect(Ext.isDefined(false)).toBe(true);
  679. });
  680. it("should return true with string", function() {
  681. expect(Ext.isDefined("foo")).toBe(true);
  682. });
  683. it("should return true with empty string", function() {
  684. expect(Ext.isDefined("")).toBe(true);
  685. });
  686. it("should return true with number", function() {
  687. expect(Ext.isDefined(1)).toBe(true);
  688. });
  689. it("should return true with null", function() {
  690. expect(Ext.isDefined(null)).toBe(true);
  691. });
  692. it("should return false with undefined", function() {
  693. expect(Ext.isDefined(undefined)).toBe(false);
  694. });
  695. it("should return true with date", function() {
  696. expect(Ext.isDefined(new Date())).toBe(true);
  697. });
  698. it("should return true with empty object", function() {
  699. expect(Ext.isDefined({})).toBe(true);
  700. });
  701. it("should return true with node list", function() {
  702. expect(Ext.isDefined(document.getElementsByTagName('body'))).toBe(true);
  703. });
  704. it("should return true with element", function() {
  705. expect(Ext.isDefined(Ext.getBody().dom)).toBe(true);
  706. });
  707. });
  708. describe("Ext.isElement", function() {
  709. it("should return false with empty array", function() {
  710. expect(Ext.isElement([])).toBe(false);
  711. });
  712. it("should return false with filled array", function() {
  713. expect(Ext.isElement([1, 2, 3, 4])).toBe(false);
  714. });
  715. it("should return false with boolean true", function() {
  716. expect(Ext.isElement(true)).toBe(false);
  717. });
  718. it("should return false with boolean false", function() {
  719. expect(Ext.isElement(false)).toBe(false);
  720. });
  721. it("should return false with string", function() {
  722. expect(Ext.isElement("foo")).toBe(false);
  723. });
  724. it("should return false with empty string", function() {
  725. expect(Ext.isElement("")).toBe(false);
  726. });
  727. it("should return false with number", function() {
  728. expect(Ext.isElement(1)).toBe(false);
  729. });
  730. it("should return false with null", function() {
  731. expect(Ext.isElement(null)).toBe(false);
  732. });
  733. it("should return false with undefined", function() {
  734. expect(Ext.isElement(undefined)).toBe(false);
  735. });
  736. it("should return false with date", function() {
  737. expect(Ext.isElement(new Date())).toBe(false);
  738. });
  739. it("should return false with empty object", function() {
  740. expect(Ext.isElement({})).toBe(false);
  741. });
  742. it("should return false with node list", function() {
  743. expect(Ext.isElement(document.getElementsByTagName('body'))).toBe(false);
  744. });
  745. it("should return true with element", function() {
  746. expect(Ext.isElement(Ext.getBody().dom)).toBe(true);
  747. });
  748. it("should return false with Ext.Element", function() {
  749. expect(Ext.isElement(Ext.getBody())).toBe(false);
  750. });
  751. it("should return false with TextNode", function() {
  752. var textNode = document.createTextNode('foobar');
  753. document.body.appendChild(textNode);
  754. expect(Ext.isElement(textNode)).toBe(false);
  755. document.body.removeChild(textNode);
  756. });
  757. });
  758. describe("Ext.isEmpty", function() {
  759. it("should return true with empty array", function() {
  760. expect(Ext.isEmpty([])).toBe(true);
  761. });
  762. it("should return false with filled array", function() {
  763. expect(Ext.isEmpty([1, 2, 3, 4])).toBe(false);
  764. });
  765. it("should return false with boolean true", function() {
  766. expect(Ext.isEmpty(true)).toBe(false);
  767. });
  768. it("should return false with boolean false", function() {
  769. expect(Ext.isEmpty(false)).toBe(false);
  770. });
  771. it("should return false with string", function() {
  772. expect(Ext.isEmpty("foo")).toBe(false);
  773. });
  774. it("should return true with empty string", function() {
  775. expect(Ext.isEmpty("")).toBe(true);
  776. });
  777. it("should return true with empty string with allowBlank", function() {
  778. expect(Ext.isEmpty("", true)).toBe(false);
  779. });
  780. it("should return false with number", function() {
  781. expect(Ext.isEmpty(1)).toBe(false);
  782. });
  783. it("should return true with null", function() {
  784. expect(Ext.isEmpty(null)).toBe(true);
  785. });
  786. it("should return true with undefined", function() {
  787. expect(Ext.isEmpty(undefined)).toBe(true);
  788. });
  789. it("should return false with date", function() {
  790. expect(Ext.isEmpty(new Date())).toBe(false);
  791. });
  792. it("should return false with empty object", function() {
  793. expect(Ext.isEmpty({})).toBe(false);
  794. });
  795. });
  796. describe("Ext.isFunction", function() {
  797. beforeEach(function() {
  798. // add global variable in whitelist
  799. addGlobal("ExtBox1");
  800. });
  801. it("should return true with anonymous function", function() {
  802. expect(Ext.isFunction(function(){})).toBe(true);
  803. });
  804. it("should return true with new Function syntax", function() {
  805. expect(Ext.isFunction(Ext.functionFactory('return "";'))).toBe(true);
  806. });
  807. it("should return true with static function", function() {
  808. expect(Ext.isFunction(Ext.emptyFn)).toBe(true);
  809. });
  810. it("should return true with instance function", function() {
  811. var stupidClass = function() {},
  812. testObject;
  813. stupidClass.prototype.testMe = function() {};
  814. testObject = new stupidClass();
  815. expect(Ext.isFunction(testObject.testMe)).toBe(true);
  816. });
  817. it("should return true with function on object", function() {
  818. var o = {
  819. fn: function() {
  820. }
  821. };
  822. expect(Ext.isFunction(o.fn)).toBe(true);
  823. });
  824. it("should return false with empty array", function() {
  825. expect(Ext.isFunction([])).toBe(false);
  826. });
  827. it("should return false with filled array", function() {
  828. expect(Ext.isFunction([1, 2, 3, 4])).toBe(false);
  829. });
  830. it("should return false with boolean true", function() {
  831. expect(Ext.isFunction(true)).toBe(false);
  832. });
  833. it("should return false with boolean false", function() {
  834. expect(Ext.isFunction(false)).toBe(false);
  835. });
  836. it("should return false with string", function() {
  837. expect(Ext.isFunction("foo")).toBe(false);
  838. });
  839. it("should return false with empty string", function() {
  840. expect(Ext.isFunction("")).toBe(false);
  841. });
  842. it("should return false with number", function() {
  843. expect(Ext.isFunction(1)).toBe(false);
  844. });
  845. it("should return false with null", function() {
  846. expect(Ext.isFunction(null)).toBe(false);
  847. });
  848. it("should return false with undefined", function() {
  849. expect(Ext.isFunction(undefined)).toBe(false);
  850. });
  851. it("should return false with date", function() {
  852. expect(Ext.isFunction(new Date())).toBe(false);
  853. });
  854. it("should return false with empty object", function() {
  855. expect(Ext.isFunction({})).toBe(false);
  856. });
  857. it("should return false with node list", function() {
  858. expect(Ext.isFunction(document.getElementsByTagName('body'))).toBe(false);
  859. });
  860. });
  861. describe("Ext.isNumber", function() {
  862. it("should return true with zero", function() {
  863. expect(Ext.isNumber(0)).toBe(true);
  864. });
  865. it("should return true with non zero", function() {
  866. expect(Ext.isNumber(4)).toBe(true);
  867. });
  868. it("should return true with negative integer", function() {
  869. expect(Ext.isNumber(-3)).toBe(true);
  870. });
  871. it("should return true with float", function() {
  872. expect(Ext.isNumber(1.75)).toBe(true);
  873. });
  874. it("should return true with negative float", function() {
  875. expect(Ext.isNumber(-4.75)).toBe(true);
  876. });
  877. it("should return true with Number.MAX_VALUE", function() {
  878. expect(Ext.isNumber(Number.MAX_VALUE)).toBe(true);
  879. });
  880. it("should return true with Number.MIN_VALUE", function() {
  881. expect(Ext.isNumber(Number.MIN_VALUE)).toBe(true);
  882. });
  883. it("should return true with Math.PI", function() {
  884. expect(Ext.isNumber(Math.PI)).toBe(true);
  885. });
  886. it("should return true with Number() contructor", function() {
  887. expect(Ext.isNumber(Number('3.1'))).toBe(true);
  888. });
  889. it("should return false with NaN", function() {
  890. expect(Ext.isNumber(Number.NaN)).toBe(false);
  891. });
  892. it("should return false with Number.POSITIVE_INFINITY", function() {
  893. expect(Ext.isNumber(Number.POSITIVE_INFINITY)).toBe(false);
  894. });
  895. it("should return false with Number.NEGATIVE_INFINITY", function() {
  896. expect(Ext.isNumber(Number.NEGATIVE_INFINITY)).toBe(false);
  897. });
  898. it("should return false with empty array", function() {
  899. expect(Ext.isNumber([])).toBe(false);
  900. });
  901. it("should return false with filled array", function() {
  902. expect(Ext.isNumber([1, 2, 3, 4])).toBe(false);
  903. });
  904. it("should return false with boolean true", function() {
  905. expect(Ext.isNumber(true)).toBe(false);
  906. });
  907. it("should return false with boolean false", function() {
  908. expect(Ext.isNumber(false)).toBe(false);
  909. });
  910. it("should return false with string", function() {
  911. expect(Ext.isNumber("foo")).toBe(false);
  912. });
  913. it("should return false with empty string", function() {
  914. expect(Ext.isNumber("")).toBe(false);
  915. });
  916. it("should return false with string containing a number", function() {
  917. expect(Ext.isNumber("1.0")).toBe(false);
  918. });
  919. it("should return false with undefined", function() {
  920. expect(Ext.isNumber(undefined)).toBe(false);
  921. });
  922. it("should return false with date", function() {
  923. expect(Ext.isNumber(new Date())).toBe(false);
  924. });
  925. it("should return false with empty object", function() {
  926. expect(Ext.isNumber({})).toBe(false);
  927. });
  928. it("should return false with node list", function() {
  929. expect(Ext.isNumber(document.getElementsByTagName('body'))).toBe(false);
  930. });
  931. });
  932. describe("Ext.isNumeric", function() {
  933. it("should return true with zero", function() {
  934. expect(Ext.isNumeric(0)).toBe(true);
  935. });
  936. it("should return true with non zero", function() {
  937. expect(Ext.isNumeric(4)).toBe(true);
  938. });
  939. it("should return true with negative integer", function() {
  940. expect(Ext.isNumeric(-3)).toBe(true);
  941. });
  942. it("should return true with float", function() {
  943. expect(Ext.isNumeric(1.75)).toBe(true);
  944. });
  945. it("should return true with negative float", function() {
  946. expect(Ext.isNumeric(-4.75)).toBe(true);
  947. });
  948. it("should return true with Number.MAX_VALUE", function() {
  949. expect(Ext.isNumeric(Number.MAX_VALUE)).toBe(true);
  950. });
  951. it("should return true with Number.MIN_VALUE", function() {
  952. expect(Ext.isNumeric(Number.MIN_VALUE)).toBe(true);
  953. });
  954. it("should return true with Math.PI", function() {
  955. expect(Ext.isNumeric(Math.PI)).toBe(true);
  956. });
  957. it("should return true with Number() contructor", function() {
  958. expect(Ext.isNumeric(Number('3.1'))).toBe(true);
  959. });
  960. it("should return false with NaN", function() {
  961. expect(Ext.isNumeric(Number.NaN)).toBe(false);
  962. });
  963. it("should return false with Number.POSITIVE_INFINITY", function() {
  964. expect(Ext.isNumeric(Number.POSITIVE_INFINITY)).toBe(false);
  965. });
  966. it("should return false with Number.NEGATIVE_INFINITY", function() {
  967. expect(Ext.isNumeric(Number.NEGATIVE_INFINITY)).toBe(false);
  968. });
  969. it("should return false with empty array", function() {
  970. expect(Ext.isNumeric([])).toBe(false);
  971. });
  972. it("should return false with filled array", function() {
  973. expect(Ext.isNumeric([1, 2, 3, 4])).toBe(false);
  974. });
  975. it("should return false with boolean true", function() {
  976. expect(Ext.isNumeric(true)).toBe(false);
  977. });
  978. it("should return false with boolean false", function() {
  979. expect(Ext.isNumeric(false)).toBe(false);
  980. });
  981. it("should return false with string", function() {
  982. expect(Ext.isNumeric("foo")).toBe(false);
  983. });
  984. it("should return false with empty string", function() {
  985. expect(Ext.isNumeric("")).toBe(false);
  986. });
  987. it("should return true with string containing a number", function() {
  988. expect(Ext.isNumeric("1.0")).toBe(true);
  989. });
  990. it("should return false with undefined", function() {
  991. expect(Ext.isNumeric(undefined)).toBe(false);
  992. });
  993. it("should return false with date", function() {
  994. expect(Ext.isNumeric(new Date())).toBe(false);
  995. });
  996. it("should return false with empty object", function() {
  997. expect(Ext.isNumeric({})).toBe(false);
  998. });
  999. it("should return false with node list", function() {
  1000. expect(Ext.isNumeric(document.getElementsByTagName('body'))).toBe(false);
  1001. });
  1002. });
  1003. describe("Ext.isObject", function() {
  1004. it("should return false with empty array", function() {
  1005. expect(Ext.isObject([])).toBe(false);
  1006. });
  1007. it("should return false with filled array", function() {
  1008. expect(Ext.isObject([1, 2, 3, 4])).toBe(false);
  1009. });
  1010. it("should return false with boolean true", function() {
  1011. expect(Ext.isObject(true)).toBe(false);
  1012. });
  1013. it("should return false with boolean false", function() {
  1014. expect(Ext.isObject(false)).toBe(false);
  1015. });
  1016. it("should return false with string", function() {
  1017. expect(Ext.isObject("foo")).toBe(false);
  1018. });
  1019. it("should return false with empty string", function() {
  1020. expect(Ext.isObject("")).toBe(false);
  1021. });
  1022. it("should return false with number", function() {
  1023. expect(Ext.isObject(1)).toBe(false);
  1024. });
  1025. it("should return false with null", function() {
  1026. expect(Ext.isObject(null)).toBe(false);
  1027. });
  1028. it("should return false with undefined", function() {
  1029. expect(Ext.isObject(undefined)).toBe(false);
  1030. });
  1031. it("should return false with date", function() {
  1032. expect(Ext.isObject(new Date())).toBe(false);
  1033. });
  1034. it("should return true with empty object", function() {
  1035. expect(Ext.isObject({})).toBe(true);
  1036. });
  1037. it("should return false with a DOM node", function() {
  1038. expect(Ext.isObject(document.body)).toBe(false);
  1039. });
  1040. it("should return false with a Text node", function() {
  1041. expect(Ext.isObject(document.createTextNode('test'))).toBe(false);
  1042. });
  1043. it("should return true with object with properties", function() {
  1044. expect(Ext.isObject({
  1045. foo: 1
  1046. })).toBe(true);
  1047. });
  1048. it("should return true with object instance", function() {
  1049. var stupidClass = function() {};
  1050. expect(Ext.isObject(new stupidClass())).toBe(true);
  1051. });
  1052. it("should return true with new Object syntax", function() {
  1053. expect(Ext.isObject(new Object())).toBe(true);
  1054. });
  1055. it("should return false with dom element", function() {
  1056. expect(Ext.isObject(document.body)).toBe(false);
  1057. });
  1058. });
  1059. describe("Ext.isPrimitive", function() {
  1060. it("should return true with integer", function() {
  1061. expect(Ext.isPrimitive(1)).toBe(true);
  1062. });
  1063. it("should return true with negative integer", function() {
  1064. expect(Ext.isPrimitive(-21)).toBe(true);
  1065. });
  1066. it("should return true with float", function() {
  1067. expect(Ext.isPrimitive(2.1)).toBe(true);
  1068. });
  1069. it("should return true with negative float", function() {
  1070. expect(Ext.isPrimitive(-12.1)).toBe(true);
  1071. });
  1072. it("should return true with Number.MAX_VALUE", function() {
  1073. expect(Ext.isPrimitive(Number.MAX_VALUE)).toBe(true);
  1074. });
  1075. it("should return true with Math.PI", function() {
  1076. expect(Ext.isPrimitive(Math.PI)).toBe(true);
  1077. });
  1078. it("should return true with empty string", function() {
  1079. expect(Ext.isPrimitive("")).toBe(true);
  1080. });
  1081. it("should return true with non empty string", function() {
  1082. expect(Ext.isPrimitive("foo")).toBe(true);
  1083. });
  1084. it("should return true with boolean true", function() {
  1085. expect(Ext.isPrimitive(true)).toBe(true);
  1086. });
  1087. it("should return true with boolean false", function() {
  1088. expect(Ext.isPrimitive(false)).toBe(true);
  1089. });
  1090. it("should return false with null", function() {
  1091. expect(Ext.isPrimitive(null)).toBe(false);
  1092. });
  1093. it("should return false with undefined", function() {
  1094. expect(Ext.isPrimitive(undefined)).toBe(false);
  1095. });
  1096. it("should return false with object", function() {
  1097. expect(Ext.isPrimitive({})).toBe(false);
  1098. });
  1099. it("should return false with object instance", function() {
  1100. var stupidClass = function() {};
  1101. expect(Ext.isPrimitive(new stupidClass())).toBe(false);
  1102. });
  1103. it("should return false with array", function() {
  1104. expect(Ext.isPrimitive([])).toBe(false);
  1105. });
  1106. });
  1107. describe("Ext.isString", function() {
  1108. it("should return true with empty string", function() {
  1109. expect(Ext.isString("")).toBe(true);
  1110. });
  1111. it("should return true with non empty string", function() {
  1112. expect(Ext.isString("foo")).toBe(true);
  1113. });
  1114. it("should return true with String() syntax", function() {
  1115. expect(Ext.isString(String(""))).toBe(true);
  1116. });
  1117. it("should return false with new String() syntax", function() { //should return an object that wraps the primitive
  1118. expect(Ext.isString(new String(""))).toBe(false);
  1119. });
  1120. it("should return false with number", function() {
  1121. expect(Ext.isString(1)).toBe(false);
  1122. });
  1123. it("should return false with boolean", function() {
  1124. expect(Ext.isString(true)).toBe(false);
  1125. });
  1126. it("should return false with null", function() {
  1127. expect(Ext.isString(null)).toBe(false);
  1128. });
  1129. it("should return false with undefined", function() {
  1130. expect(Ext.isString(undefined)).toBe(false);
  1131. });
  1132. it("should return false with array", function() {
  1133. expect(Ext.isString([])).toBe(false);
  1134. });
  1135. it("should return false with object", function() {
  1136. expect(Ext.isString({})).toBe(false);
  1137. });
  1138. });
  1139. describe("Ext.isTextNode", function() {
  1140. it("should return false with empty array", function() {
  1141. expect(Ext.isTextNode([])).toBe(false);
  1142. });
  1143. it("should return false with filled array", function() {
  1144. expect(Ext.isTextNode([1, 2, 3, 4])).toBe(false);
  1145. });
  1146. it("should return false with boolean true", function() {
  1147. expect(Ext.isTextNode(true)).toBe(false);
  1148. });
  1149. it("should return false with boolean false", function() {
  1150. expect(Ext.isTextNode(false)).toBe(false);
  1151. });
  1152. it("should return false with string", function() {
  1153. expect(Ext.isTextNode("foo")).toBe(false);
  1154. });
  1155. it("should return false with empty string", function() {
  1156. expect(Ext.isTextNode("")).toBe(false);
  1157. });
  1158. it("should return false with number", function() {
  1159. expect(Ext.isTextNode(1)).toBe(false);
  1160. });
  1161. it("should return false with null", function() {
  1162. expect(Ext.isTextNode(null)).toBe(false);
  1163. });
  1164. it("should return false with undefined", function() {
  1165. expect(Ext.isTextNode(undefined)).toBe(false);
  1166. });
  1167. it("should return false with date", function() {
  1168. expect(Ext.isTextNode(new Date())).toBe(false);
  1169. });
  1170. it("should return false with empty object", function() {
  1171. expect(Ext.isTextNode({})).toBe(false);
  1172. });
  1173. it("should return false with node list", function() {
  1174. expect(Ext.isTextNode(document.getElementsByTagName('body'))).toBe(false);
  1175. });
  1176. it("should return false with element", function() {
  1177. expect(Ext.isTextNode(Ext.getBody().dom)).toBe(false);
  1178. });
  1179. it("should return false with Ext.Element", function() {
  1180. expect(Ext.isTextNode(Ext.getBody())).toBe(false);
  1181. });
  1182. it("should return true with TextNode", function() {
  1183. var textNode = document.createTextNode('foobar');
  1184. document.body.appendChild(textNode);
  1185. expect(Ext.isTextNode(textNode)).toBe(true);
  1186. document.body.removeChild(textNode);
  1187. });
  1188. });
  1189. describe("Ext.clone", function() {
  1190. var clone;
  1191. afterEach(function() {
  1192. clone = null;
  1193. });
  1194. it("should clone an array", function() {
  1195. var array = [2,'5',[1,3,4]];
  1196. clone = Ext.clone(array);
  1197. expect(clone).toEqual(array);
  1198. expect(clone).not.toBe(array);
  1199. });
  1200. it("should clone an object", function() {
  1201. var object = {
  1202. fn: function() {
  1203. return 1;
  1204. },
  1205. b: 2
  1206. };
  1207. clone = Ext.clone(object);
  1208. expect(clone).toEqual(object);
  1209. expect(clone).not.toBe(object);
  1210. });
  1211. it("should clone a date", function(){
  1212. var date = new Date();
  1213. clone = Ext.clone(date);
  1214. expect(clone).toEqual(date);
  1215. expect(clone).not.toBe(date);
  1216. });
  1217. it("should clone a dom node", function(){
  1218. var node = document.createElement('DIV');
  1219. document.body.appendChild(node);
  1220. clone = Ext.clone(node);
  1221. expect(clone.tagName).toEqual(clone.tagName);
  1222. expect(clone.innerHTML).toEqual(clone.innerHTML);
  1223. expect(clone).not.toBe(node);
  1224. document.body.removeChild(node);
  1225. });
  1226. });
  1227. describe('getUniqueGlobalNamespace', function() {
  1228. it("should return an unique global namespace", function() {
  1229. expect(Ext.getUniqueGlobalNamespace()).toBe("ExtBox1");
  1230. });
  1231. });
  1232. });