Skip to content

Commit 4ec911c

Browse files
authored
Merge pull request #872 from Litezy/feat/accessible-color-contrast
feat(frontend): add accessible contrast to transaction filter chips
2 parents 5bd7e44 + d234f12 commit 4ec911c

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

dex_with_fiat_frontend/src/hooks/useTransactionFilters.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,63 @@ describe('useTransactionFilters', () => {
6161
});
6262
expect(mockPush).not.toHaveBeenCalled();
6363

64+
it('clears all filters through the keyboard shortcut outside editable fields', () => {
65+
mockSearchParams = new URLSearchParams('status=completed');
66+
67+
renderHook(() => useTransactionFilters(sampleTransactions));
68+
69+
act(() => {
70+
window.dispatchEvent(
71+
new KeyboardEvent('keydown', {
72+
key: 'x',
73+
ctrlKey: true,
74+
shiftKey: true,
75+
bubbles: true,
76+
}),
77+
);
78+
});
79+
80+
act(() => {
81+
vi.advanceTimersByTime(150);
82+
});
83+
84+
expect(pushMock).toHaveBeenCalledWith('/receipts', { scroll: false });
85+
});
86+
87+
it('ignores keyboard shortcuts while typing in an input', () => {
88+
mockSearchParams = new URLSearchParams('status=completed');
89+
90+
renderHook(() => useTransactionFilters(sampleTransactions));
91+
92+
const input = document.createElement('input');
93+
document.body.appendChild(input);
94+
95+
act(() => {
96+
input.dispatchEvent(
97+
new KeyboardEvent('keydown', {
98+
key: 'x',
99+
ctrlKey: true,
100+
shiftKey: true,
101+
bubbles: true,
102+
}),
103+
);
104+
vi.advanceTimersByTime(150);
105+
});
106+
107+
expect(pushMock).not.toHaveBeenCalled();
108+
109+
document.body.removeChild(input);
110+
});
111+
112+
it('exposes the same accessible chip tone resolver through the hook', () => {
113+
const { result } = renderHook(() =>
114+
useTransactionFilters(sampleTransactions),
115+
);
116+
117+
expect(
118+
result.current.getFilterChipTone('status', 'pending', true),
119+
).toEqual(getAccessibleFilterChipTone('status', 'pending', true));
120+
})
64121
act(() => {
65122
vi.advanceTimersByTime(1);
66123
});
@@ -91,5 +148,6 @@ describe('useTransactionFilters', () => {
91148
expect(KEYBOARD_SHORTCUTS.cycleStatus.key).toBe('1');
92149
expect(KEYBOARD_SHORTCUTS.cycleAsset.key).toBe('2');
93150
expect(KEYBOARD_SHORTCUTS.cycleNetwork.key).toBe('3');
151+
94152
});
95153
});

0 commit comments

Comments
 (0)