|
1 |
| -import { concurrentFilter, conform, filter, reduce, map } from '../'; |
| 1 | +import { concurrentFilter, conform, filter, reduce, map, move } from '../'; |
2 | 2 |
|
3 | 3 | describe('@ionic/utils-array', () => {
|
4 | 4 |
|
@@ -212,4 +212,53 @@ describe('@ionic/utils-array', () => {
|
212 | 212 |
|
213 | 213 | });
|
214 | 214 |
|
| 215 | + describe('move', () => { |
| 216 | + |
| 217 | + const array = ['a', 'b', 'c']; |
| 218 | + |
| 219 | + it('should move first element to last element', () => { |
| 220 | + const result = move(array, 0, 2); |
| 221 | + expect(result).toEqual(['b', 'c', 'a']); |
| 222 | + }); |
| 223 | + |
| 224 | + it('should move last element to first element', () => { |
| 225 | + const result = move(array, 2, 0); |
| 226 | + expect(result).toEqual(['c', 'a', 'b']); |
| 227 | + }); |
| 228 | + |
| 229 | + it('should not move element with equal indexes', () => { |
| 230 | + const result = move(array, 1, 1); |
| 231 | + expect(result).toEqual(['a', 'b', 'c']); |
| 232 | + expect(result).not.toBe(array); |
| 233 | + }); |
| 234 | + |
| 235 | + describe('out of bounds', () => { |
| 236 | + it('should leave array unchanged for from index greater than array length', () => { |
| 237 | + const result = move(array, 5, 0); |
| 238 | + expect(result).toEqual(['a', 'b', 'c']); |
| 239 | + expect(result).not.toBe(array); |
| 240 | + }); |
| 241 | + |
| 242 | + it('should leave array unchanged for to index greater than array length', () => { |
| 243 | + const result = move(array, 0, 5); |
| 244 | + expect(result).toEqual(['a', 'b', 'c']); |
| 245 | + expect(result).not.toBe(array); |
| 246 | + }); |
| 247 | + |
| 248 | + it('should leave array unchanged for from index less than zero', () => { |
| 249 | + const result = move(array, -1, 0); |
| 250 | + expect(result).toEqual(['a', 'b', 'c']); |
| 251 | + expect(result).not.toBe(array); |
| 252 | + }); |
| 253 | + |
| 254 | + it('should leave array unchanged for to index less than zero', () => { |
| 255 | + const result = move(array, 0, -1); |
| 256 | + expect(result).toEqual(['a', 'b', 'c']); |
| 257 | + expect(result).not.toBe(array); |
| 258 | + }); |
| 259 | + |
| 260 | + }); |
| 261 | + |
| 262 | + }); |
| 263 | + |
215 | 264 | });
|
0 commit comments