sort by Disk I/O and Net I/O - the header cycles read/write and down/up

This commit is contained in:
Jarek Krochmalski committed 2026-08-27 07:34:38 +02:00
1 parent b1e7518096
commit 0d516be4dd
8 files changed
+217 -18

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
/**
* nextIoSortState: a two-metric grid column (Disk I/O = read/write) cycles a header
* click through all four (metric, direction) states rather than a plain asc/desc
* toggle (#1111).
*/
import { describe, it, expect } from 'bun:test';
import { nextIoSortState } from '../src/lib/utils/io-sort-cycle';
const DISK = [
{ field: 'diskRead', direction: 'desc' as const },
{ field: 'diskRead', direction: 'asc' as const },
{ field: 'diskWrite', direction: 'desc' as const },
{ field: 'diskWrite', direction: 'asc' as const }
];
describe('nextIoSortState', () => {
it('starts the cycle at read-desc when the column is not currently sorted', () => {
expect(nextIoSortState(DISK, { field: 'name', direction: 'asc' })).toEqual(DISK[0]);
});
it('walks read-desc -> read-asc -> write-desc -> write-asc', () => {
expect(nextIoSortState(DISK, DISK[0])).toEqual(DISK[1]);
expect(nextIoSortState(DISK, DISK[1])).toEqual(DISK[2]);
expect(nextIoSortState(DISK, DISK[2])).toEqual(DISK[3]);
});
it('wraps from the last state back to the first', () => {
expect(nextIoSortState(DISK, DISK[3])).toEqual(DISK[0]);
});
it('restarts the cycle when the current field is another cycle column', () => {
// e.g. the user was sorting Net I/O, now clicks Disk I/O
expect(nextIoSortState(DISK, { field: 'netRx', direction: 'asc' })).toEqual(DISK[0]);
});
});