|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var R = require('ramda'); |
| 4 | + |
| 5 | +var listUtils = require('../lib/Lists'); |
| 6 | + |
| 7 | +var DROP_IF_GTE_LENGTH = 5, |
| 8 | + |
| 9 | + LIST_LONGER = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'], |
| 10 | + LIST_LONGER_EXPECT = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'], |
| 11 | + |
| 12 | + LIST_SHORTER = ['x', 'y', 'z'], |
| 13 | + LIST_SHORTER_EXPECT = ['x', 'y', 'z'], |
| 14 | + |
| 15 | + LIST_MIXED_UNSORTED = ['b', 'd', 'a', 'c'], |
| 16 | + LIST_MIXED_SORTED_ASC = ['a', 'b', 'c', 'd'], |
| 17 | + LIST_MIXED_SORTED_DESC = ['d', 'c', 'b', 'a'], |
| 18 | + |
| 19 | + LIST_OF_ITEMS_PRE_FILTERED = ['a', 'b', 'c'], |
| 20 | + LIST_OF_ITEMS_FILTERED = ['a', 'c'], |
| 21 | + |
| 22 | + LIST_OF_OBJECTS_PRE_FILTERED = [{ foo : 'bar'}, {baz : 'bat'}, {buz : 'but'}], |
| 23 | + LIST_OF_OBJECTS_FILTERED = [{ foo : 'bar'}, {buz : 'but'}], |
| 24 | + |
| 25 | + LIST_DROP_LENGTH = ['q', 'w', 'e', 'r', 't', 'y'], |
| 26 | + LIST_DROP_LENGTH_EXPECT = ['q', 'w', 'e', 'r', 't']; |
| 27 | + |
| 28 | +describe('maybeDropLastItem', function() { |
| 29 | + it('drops the last item from a list if list length exceeds minimum drop length', function() { |
| 30 | + expect(listUtils.maybeDropLastItem(DROP_IF_GTE_LENGTH, LIST_LONGER)).toEqual(LIST_LONGER_EXPECT); |
| 31 | + }); |
| 32 | + it('preserves list if length is less than minimum drop length', function() { |
| 33 | + expect(listUtils.maybeDropLastItem(DROP_IF_GTE_LENGTH, LIST_SHORTER)).toEqual(LIST_SHORTER_EXPECT); |
| 34 | + }); |
| 35 | + it('drops the last item from a list if list length is exactly the minimum drop length', function() { |
| 36 | + expect(listUtils.maybeDropLastItem(DROP_IF_GTE_LENGTH, LIST_DROP_LENGTH)).toEqual(LIST_DROP_LENGTH_EXPECT); |
| 37 | + }); |
| 38 | +}); |
| 39 | + |
| 40 | +describe('filterOutObject', function() { |
| 41 | + it('removes an object from a list', function() { |
| 42 | + expect(listUtils.filterOutObject('baz', 'bat', LIST_OF_OBJECTS_PRE_FILTERED)).toEqual(LIST_OF_OBJECTS_FILTERED); |
| 43 | + }); |
| 44 | +}); |
| 45 | + |
| 46 | +describe('filterOutItem', function() { |
| 47 | + it('removes an item from a list', function() { |
| 48 | + expect(listUtils.filterOutItem('b', LIST_OF_ITEMS_PRE_FILTERED)).toEqual(LIST_OF_ITEMS_FILTERED); |
| 49 | + }); |
| 50 | +}); |
| 51 | + |
| 52 | +describe('sortAsc', function() { |
| 53 | + it('sorts a list ascending', function() { |
| 54 | + expect(R.sort(listUtils.sortAsc, LIST_MIXED_UNSORTED)).toEqual(LIST_MIXED_SORTED_ASC); |
| 55 | + }); |
| 56 | +}); |
| 57 | + |
| 58 | +describe('sortDesc', function() { |
| 59 | + it('sorts a list descending', function() { |
| 60 | + expect(R.sort(listUtils.sortDesc, LIST_MIXED_UNSORTED)).toEqual(LIST_MIXED_SORTED_DESC); |
| 61 | + }); |
| 62 | +}); |
0 commit comments