Skip to content

Commit

Permalink
remove empty epaId querystring when selecting transporter
Browse files Browse the repository at this point in the history
  • Loading branch information
sheckathorne committed Jun 14, 2024
1 parent 1cdd0c9 commit 903a508
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function HandlerSearchForm({
siteType: handlerType,
siteId: debouncedInputValue,
},
{ skip }
{ skip: skip || debouncedInputValue === '' }
);
const {
data: rcrainfoData,
Expand Down
15 changes: 3 additions & 12 deletions client/src/hooks/useDebounce/useDebounce.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { beforeAll, afterAll, afterEach, describe, expect, it, vi } from 'vitest

describe('useDebounce hook', () => {
beforeAll(() => {
vi.useFakeTimers(); // Use fake timers
vi.useFakeTimers();
});

afterAll(() => {
vi.clearAllTimers(); // Clear all timers after tests
vi.clearAllTimers();
});

it('should return the initial value immediately', () => {
Expand All @@ -22,18 +22,14 @@ describe('useDebounce hook', () => {
initialProps: { value: 'initial', delay: 500 },
});

// Update the value
rerender({ value: 'updated', delay: 500 });

// Before the delay, the debounced value should still be 'initial'
expect(result.current).toBe('initial');

// Fast forward time by 500ms
act(() => {
vi.advanceTimersByTime(500);
});

// After the delay, the debounced value should be 'updated'
expect(result.current).toBe('updated');
});

Expand All @@ -42,31 +38,26 @@ describe('useDebounce hook', () => {
initialProps: { value: 'initial', delay: 500 },
});

// Update the value multiple times within the delay period
rerender({ value: 'updated1', delay: 500 });
act(() => {
vi.advanceTimersByTime(300);
});
rerender({ value: 'updated2', delay: 500 });

// Fast forward time by the remaining 200ms
act(() => {
vi.advanceTimersByTime(200);
});

// The debounced value should still be 'initial' because the timer was reset
expect(result.current).toBe('initial');

// Fast forward time by 300ms
act(() => {
vi.advanceTimersByTime(300);
});

// After the full delay, the debounced value should be 'updated2'
expect(result.current).toBe('updated2');
});

afterEach(() => {
vi.clearAllTimers(); // Clear all timers after each test
vi.clearAllTimers();
});
});

0 comments on commit 903a508

Please sign in to comment.