|
| 1 | +// @vitest-environment jsdom |
| 2 | +// |
| 3 | +// The record-list footer was decluttered to show ONLY "Showing X–Y": the total |
| 4 | +// count ("of N in collection (unfiltered)") and the query timing ("· Nms") now |
| 5 | +// live in the Aggregate Pipeline Debug, so they were removed here — along with the |
| 6 | +// >1s slow-query tint (record-count-slow), which moved to the debug timings. |
| 7 | +// |
| 8 | +import { describe, it, expect, beforeEach, vi } from 'vitest'; |
| 9 | +import { h, render } from 'preact'; |
| 10 | + |
| 11 | +globalThis.ResizeObserver = class { observe() {} unobserve() {} disconnect() {} }; |
| 12 | +globalThis.chrome = { storage: { local: { get: (k, cb) => cb && cb({}), set() {}, remove() {} } } }; |
| 13 | + |
| 14 | +vi.mock('../src/mdh/api.js'); |
| 15 | +vi.mock('../src/mdh/components/RecordCard.jsx', () => ({ default: () => h('div', { class: 'record-card-stub' }) })); |
| 16 | +vi.mock('../src/mdh/components/DownloadSplitButton.jsx', () => ({ default: () => h('div') })); |
| 17 | + |
| 18 | +import RecordList from '../src/mdh/components/RecordList.jsx'; |
| 19 | +import { skip, limit, selectedCollection, selectionMode, selectedIds, selectionPipelineDirty } from '../src/mdh/store.js'; |
| 20 | + |
| 21 | +const pagination = { hasPrev: () => false, hasNext: () => false, page: () => 1 }; |
| 22 | + |
| 23 | +function renderList(props = {}) { |
| 24 | + const root = document.createElement('div'); |
| 25 | + document.body.appendChild(root); |
| 26 | + render(h(RecordList, { |
| 27 | + records: [{ _id: '1' }, { _id: '2' }], |
| 28 | + pipelineText: '[]', filterState: {}, sortState: {}, |
| 29 | + lastQueryMs: 0, totalCount: null, pagination, |
| 30 | + onSort() {}, onFilter() {}, onPageChange() {}, onEdit() {}, onDelete() {}, onRefresh() {}, |
| 31 | + downloadState: null, onCancelDownload() {}, onEnterSelectionMode() {}, onExitSelectionMode() {}, |
| 32 | + onBulkDelete() {}, onBulkUpdate() {}, onSelectPage() {}, onClearSelection() {}, onViewSelected() {}, |
| 33 | + ...props, |
| 34 | + }), root); |
| 35 | + return root; |
| 36 | +} |
| 37 | + |
| 38 | +beforeEach(() => { |
| 39 | + vi.clearAllMocks(); |
| 40 | + skip.value = 0; |
| 41 | + limit.value = 50; |
| 42 | + selectedCollection.value = null; |
| 43 | + selectionMode.value = false; |
| 44 | + selectedIds.value = new Map(); |
| 45 | + selectionPipelineDirty.value = false; |
| 46 | +}); |
| 47 | + |
| 48 | +describe('RecordList footer', () => { |
| 49 | + it('shows only "Showing X–Y" — no total count, no timing', () => { |
| 50 | + const root = renderList({ totalCount: 162, lastQueryMs: 277 }); |
| 51 | + const count = root.querySelector('.record-count'); |
| 52 | + expect(count).not.toBeNull(); |
| 53 | + expect(count.textContent).toBe('Showing 1–2'); |
| 54 | + expect(count.textContent).not.toContain('in collection'); |
| 55 | + expect(count.textContent).not.toContain('162'); |
| 56 | + expect(count.textContent).not.toContain('ms'); |
| 57 | + }); |
| 58 | + |
| 59 | + it('does not apply the slow-query tint, even for a slow (>1s) query', () => { |
| 60 | + const root = renderList({ totalCount: 162, lastQueryMs: 5000 }); |
| 61 | + const count = root.querySelector('.record-count'); |
| 62 | + expect(count.classList.contains('record-count-slow')).toBe(false); |
| 63 | + }); |
| 64 | + |
| 65 | + it('still shows "No records" when there are no records', () => { |
| 66 | + const root = renderList({ records: [], totalCount: 162, lastQueryMs: 277 }); |
| 67 | + expect(root.querySelector('.record-count').textContent).toBe('No records'); |
| 68 | + }); |
| 69 | +}); |
0 commit comments