feat: redesign routed ZarinPal merchant dashboard
This commit is contained in:
41
src/lib/dashboard-filters.test.ts
Normal file
41
src/lib/dashboard-filters.test.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { parseDashboardFilters, setDashboardQuery, type DashboardRange } from './dashboard-filters';
|
||||
|
||||
describe('dashboard filters', () => {
|
||||
const terminals = ['T83', 'T84'];
|
||||
|
||||
it('uses safe, shareable defaults for invalid query values', () => {
|
||||
const query = new URLSearchParams('range=year&terminal=someone-elses-terminal&minAmount=-1');
|
||||
|
||||
expect(parseDashboardFilters(query, terminals)).toEqual({
|
||||
range: 'month',
|
||||
terminal: 'all',
|
||||
status: 'all',
|
||||
minAmount: null,
|
||||
maxAmount: null,
|
||||
});
|
||||
});
|
||||
|
||||
it.each<DashboardRange>(['day', 'week', 'month', 'season'])(
|
||||
'keeps the %s range in the copied URL',
|
||||
(range) => {
|
||||
const next = setDashboardQuery(new URL('https://example.test/transactions?terminal=T83'), {
|
||||
range,
|
||||
});
|
||||
|
||||
expect(next.searchParams.get('range')).toBe(range);
|
||||
expect(next.searchParams.get('terminal')).toBe('T83');
|
||||
},
|
||||
);
|
||||
|
||||
it('normalizes an inverted amount range', () => {
|
||||
const filters = parseDashboardFilters(
|
||||
new URLSearchParams('minAmount=900000&maxAmount=100000'),
|
||||
terminals,
|
||||
);
|
||||
|
||||
expect(filters.minAmount).toBe(100000);
|
||||
expect(filters.maxAmount).toBe(900000);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user