ElggPriorityListTest.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. define(function(require) {
  2. var elgg = require('elgg');
  3. describe("elgg.ElggPriorityList", function() {
  4. var list;
  5. beforeEach(function() {
  6. list = new elgg.ElggPriorityList();
  7. });
  8. describe("insert()", function() {
  9. it("defaults priority to 500", function() {
  10. list.insert('foo');
  11. expect(list.priorities_[500][0], 'foo');
  12. });
  13. });
  14. describe("forEach()", function() {
  15. it("returns elements in priority order", function() {
  16. var values = [5, 4, 3, 2, 1, 0];
  17. for (var i in values) {
  18. list.insert(values[i], values[i]);
  19. }
  20. list.forEach(function(elem, idx) {
  21. expect(elem).toBe(idx);
  22. });
  23. });
  24. it("returns same-priority elements in inserted order", function() {
  25. values = [0, 1, 2, 3, 4, 5, 6, 7, 8 , 9];
  26. for (var i in values) {
  27. list.insert(values[i], values[i]/3);
  28. }
  29. list.forEach(function(elem, idx) {
  30. expect(elem).toBe(idx);
  31. });
  32. });
  33. });
  34. describe("every()", function() {
  35. it("defaults to true", function() {
  36. expect(list.every(function() {})).toBe(true);
  37. });
  38. });
  39. });
  40. });