|
| 1 | +import { expect, it, vi } from "vitest"; |
| 2 | +import cleanUpSkipped from "../../src/helpers/cleanUpSkipped"; |
| 3 | +import { QueueMapPair } from "../../src/types"; |
| 4 | + |
| 5 | +it("should clean up skipped items", () => { |
| 6 | + const cleanUp = vi.fn(); |
| 7 | + const queueItems = [ |
| 8 | + [Symbol("1"), vi.fn()], |
| 9 | + [Symbol("2"), vi.fn()], |
| 10 | + [Symbol("3"), vi.fn()], |
| 11 | + [Symbol("4"), vi.fn()], |
| 12 | + [Symbol("5"), vi.fn()], |
| 13 | + ] as QueueMapPair[]; |
| 14 | + |
| 15 | + cleanUpSkipped({ |
| 16 | + index: 1, |
| 17 | + newIndex: 3, |
| 18 | + queueItems, |
| 19 | + cleanUp, |
| 20 | + }); |
| 21 | + |
| 22 | + expect(cleanUp).toHaveBeenCalledTimes(2); |
| 23 | + expect(cleanUp).toHaveBeenCalledWith(queueItems[2][0]); |
| 24 | + expect(cleanUp).toHaveBeenCalledWith(queueItems[3][0]); |
| 25 | +}); |
| 26 | + |
| 27 | +it("should clean up skipped items... again", () => { |
| 28 | + const cleanUp = vi.fn(); |
| 29 | + const queueItems = [ |
| 30 | + [Symbol("1"), vi.fn()], |
| 31 | + [Symbol("2"), vi.fn()], |
| 32 | + [Symbol("3"), vi.fn()], |
| 33 | + [Symbol("4"), vi.fn()], |
| 34 | + [Symbol("5"), vi.fn()], |
| 35 | + ] as QueueMapPair[]; |
| 36 | + |
| 37 | + cleanUpSkipped({ |
| 38 | + index: 0, |
| 39 | + newIndex: 4, |
| 40 | + queueItems, |
| 41 | + cleanUp, |
| 42 | + }); |
| 43 | + |
| 44 | + expect(cleanUp).toHaveBeenCalledTimes(4); |
| 45 | + expect(cleanUp).toHaveBeenCalledWith(queueItems[1][0]); |
| 46 | + expect(cleanUp).toHaveBeenCalledWith(queueItems[2][0]); |
| 47 | + expect(cleanUp).toHaveBeenCalledWith(queueItems[3][0]); |
| 48 | + expect(cleanUp).toHaveBeenCalledWith(queueItems[4][0]); |
| 49 | +}); |
| 50 | + |
| 51 | +it("should clean up skipped items... again", () => { |
| 52 | + const cleanUp = vi.fn(); |
| 53 | + const queueItems = [ |
| 54 | + [Symbol("1"), vi.fn()], |
| 55 | + [Symbol("2"), vi.fn()], |
| 56 | + [Symbol("3"), vi.fn()], |
| 57 | + [Symbol("4"), vi.fn()], |
| 58 | + [Symbol("5"), vi.fn()], |
| 59 | + ] as QueueMapPair[]; |
| 60 | + |
| 61 | + cleanUpSkipped({ |
| 62 | + index: 0, |
| 63 | + newIndex: 0, |
| 64 | + queueItems, |
| 65 | + cleanUp, |
| 66 | + }); |
| 67 | + |
| 68 | + expect(cleanUp).toHaveBeenCalledTimes(0); |
| 69 | +}); |
| 70 | + |
| 71 | +it("should clean up skipped items... again", () => { |
| 72 | + const cleanUp = vi.fn(); |
| 73 | + const queueItems = [ |
| 74 | + [Symbol("1"), vi.fn()], |
| 75 | + [Symbol("2"), vi.fn()], |
| 76 | + [Symbol("3"), vi.fn()], |
| 77 | + [Symbol("4"), vi.fn()], |
| 78 | + [Symbol("5"), vi.fn()], |
| 79 | + ] as QueueMapPair[]; |
| 80 | + |
| 81 | + cleanUpSkipped({ |
| 82 | + index: 4, |
| 83 | + newIndex: 4, |
| 84 | + queueItems, |
| 85 | + cleanUp, |
| 86 | + }); |
| 87 | + |
| 88 | + expect(cleanUp).toHaveBeenCalledTimes(0); |
| 89 | +}); |
0 commit comments