(autoIndex: `off` | `eager`)
| 2570 | } |
| 2571 | |
| 2572 | function createOrderByBugTests(autoIndex: `off` | `eager`): void { |
| 2573 | describe(`with autoIndex ${autoIndex}`, () => { |
| 2574 | it(`should correctly advance window when there are duplicate values`, async () => { |
| 2575 | // Create test data that reproduces the specific bug described: |
| 2576 | // Items with many duplicates at value 5, then normal progression |
| 2577 | const duplicateTestData: Array<TestItem> = [ |
| 2578 | { id: 1, a: 1, keep: true }, |
| 2579 | { id: 2, a: 2, keep: true }, |
| 2580 | { id: 3, a: 3, keep: true }, |
| 2581 | { id: 4, a: 4, keep: true }, |
| 2582 | { id: 5, a: 5, keep: true }, |
| 2583 | { id: 6, a: 5, keep: true }, |
| 2584 | { id: 7, a: 5, keep: true }, |
| 2585 | { id: 8, a: 5, keep: true }, |
| 2586 | { id: 9, a: 5, keep: true }, |
| 2587 | { id: 10, a: 5, keep: true }, |
| 2588 | { id: 11, a: 11, keep: true }, |
| 2589 | { id: 12, a: 12, keep: true }, |
| 2590 | { id: 13, a: 13, keep: true }, |
| 2591 | { id: 14, a: 14, keep: true }, |
| 2592 | { id: 15, a: 15, keep: true }, |
| 2593 | { id: 16, a: 16, keep: true }, |
| 2594 | ] |
| 2595 | |
| 2596 | const duplicateCollection = createCollection( |
| 2597 | mockSyncCollectionOptions<TestItem>({ |
| 2598 | id: `test-duplicate-window-bug`, |
| 2599 | getKey: (item) => item.id, |
| 2600 | initialData: duplicateTestData, |
| 2601 | autoIndex, |
| 2602 | }), |
| 2603 | ) |
| 2604 | |
| 2605 | // Create a live query with offset 0, limit 5 (first page) |
| 2606 | const collection = createLiveQueryCollection((q) => |
| 2607 | q |
| 2608 | .from({ items: duplicateCollection }) |
| 2609 | .where(({ items }) => eq(items.keep, true)) |
| 2610 | .orderBy(({ items }) => items.a, `asc`) |
| 2611 | .offset(0) |
| 2612 | .limit(5) |
| 2613 | .select(({ items }) => ({ |
| 2614 | id: items.id, |
| 2615 | a: items.a, |
| 2616 | keep: items.keep, |
| 2617 | })), |
| 2618 | ) |
| 2619 | await collection.preload() |
| 2620 | |
| 2621 | // First page should return items 1-5 |
| 2622 | let results = Array.from(collection.values()) |
| 2623 | .map((value) => stripVirtualProps(value)) |
| 2624 | .sort((a, b) => a.id - b.id) |
| 2625 | expect(results).toEqual([ |
| 2626 | { id: 1, a: 1, keep: true }, |
| 2627 | { id: 2, a: 2, keep: true }, |
| 2628 | { id: 3, a: 3, keep: true }, |
| 2629 | { id: 4, a: 4, keep: true }, |
no test coverage detected