|
1 | 1 | import { |
2 | 2 | filterUnselectedByIds, |
3 | | - getSelectedByAllItems |
| 3 | + getSelectedByAllItems, |
| 4 | + getSelectedItemsOutsideInterval, |
| 5 | + getAvailableIntervalForSelection |
4 | 6 | } from "../../src/components/multi_select_state_utils"; |
5 | 7 |
|
6 | 8 | const items = [ |
@@ -76,4 +78,52 @@ describe("testing utils for multi select state", () => { |
76 | 78 | ); |
77 | 79 | expect(allSelectedItems).toEqual([]); |
78 | 80 | }); |
| 81 | + |
| 82 | + test("filter selectedItems that not in interval", () => { |
| 83 | + const selectedItemsOutsideInterval = getSelectedItemsOutsideInterval( |
| 84 | + items, |
| 85 | + selectedItems, |
| 86 | + { minIndex: 1, maxIndex: 3 } |
| 87 | + ); |
| 88 | + expect(selectedItemsOutsideInterval.length).toEqual(1); |
| 89 | + expect(selectedItemsOutsideInterval[0]).toEqual(selectedItems[0]); |
| 90 | + }); |
| 91 | + |
| 92 | + test("filter itemsToSelect that not in interval", () => { |
| 93 | + const selectedItemsOutsideInterval = getSelectedItemsOutsideInterval( |
| 94 | + items, |
| 95 | + itemsToSelect, |
| 96 | + { minIndex: 0, maxIndex: 3 } |
| 97 | + ); |
| 98 | + expect(selectedItemsOutsideInterval.length).toEqual(0); |
| 99 | + }); |
| 100 | + |
| 101 | + test("available interval when minIndex == firstItemShiftSelected", () => { |
| 102 | + const initialInterval = { minIndex: 0, maxIndex: 3 }; |
| 103 | + const maxSelectedItems = 3; |
| 104 | + const selectedItemsOutsideInterval = 0; |
| 105 | + const firstItemShiftSelected = 0; |
| 106 | + const availableInterval = getAvailableIntervalForSelection( |
| 107 | + initialInterval, |
| 108 | + selectedItemsOutsideInterval, |
| 109 | + maxSelectedItems, |
| 110 | + firstItemShiftSelected |
| 111 | + ); |
| 112 | + expect(availableInterval).toEqual({ minIndex: 0, maxIndex: 2 }); |
| 113 | + }); |
| 114 | + |
| 115 | + test("available interval when maxIndex == firstItemShiftSelected", () => { |
| 116 | + const initialInterval = { minIndex: 1, maxIndex: 3 }; |
| 117 | + const maxSelectedItems = 3; |
| 118 | + const selectedItemsOutsideInterval = 1; |
| 119 | + const firstItemShiftSelected = 3; |
| 120 | + |
| 121 | + const availableInterval = getAvailableIntervalForSelection( |
| 122 | + initialInterval, |
| 123 | + selectedItemsOutsideInterval, |
| 124 | + maxSelectedItems, |
| 125 | + firstItemShiftSelected |
| 126 | + ); |
| 127 | + expect(availableInterval).toEqual({ minIndex: 2, maxIndex: 3 }); |
| 128 | + }); |
79 | 129 | }); |
0 commit comments