batch.js 956 B

12345678910111213141516171819202122232425262728
  1. import assert from 'assert';
  2. import batch from 'misago/utils/batch';
  3. describe('Batch', function() {
  4. it("splits list into batches", function() {
  5. assert.deepEqual(batch(['a', 'b', 'c', 'd', 'e'], 2), [
  6. ['a', 'b'], ['c', 'd'], ['e']
  7. ], "list was correctly batched");
  8. assert.deepEqual(batch(['a', 'b', 'c', 'd', 'e', 'f'], 2), [
  9. ['a', 'b'], ['c', 'd'], ['e', 'f']
  10. ], "list was correctly batched");
  11. assert.deepEqual(batch(['a', 'b', 'c', 'd', 'e', 'f'], 3), [
  12. ['a', 'b', 'c'], ['d', 'e', 'f']
  13. ], "list was correctly batched");
  14. });
  15. it("splits list into batches, pads them", function() {
  16. assert.deepEqual(batch(['a', 'b', 'c', 'd', 'e'], 2, '-'), [
  17. ['a', 'b'], ['c', 'd'], ['e', '-']
  18. ], "list was correctly batched and padded");
  19. assert.deepEqual(batch(['a', 'b', 'c', 'd', 'e', 'f'], 3, '-'), [
  20. ['a', 'b', 'c'], ['d', 'e', 'f']
  21. ], "list was correctly batched and padded");
  22. });
  23. });