Skip to content

Commit da5d04f

Browse files
committed
upreate real-project
1 parent b5d2f3e commit da5d04f

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

05-testing/01-react/05-real-project/00-boilerplate/src/common/components/search-bar/search-bar.component.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ export const SearchBarComponent: React.FunctionComponent<Props> = (props) => {
2222
value={search}
2323
onChange={(e) => onSearch(e.target.value)}
2424
placeholder={labels.placeholder}
25-
InputProps={{
26-
startAdornment: <SearchIcon />,
25+
slotProps={{
26+
input: {
27+
startAdornment: <SearchIcon />,
28+
},
2729
}}
2830
/>
2931
);

05-testing/01-react/05-real-project/README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,11 @@ _./src/common/components/search-bar/search-bar.component.tsx_
334334
value={search}
335335
onChange={e => onSearch(e.target.value)}
336336
placeholder={labels.placeholder}
337-
InputProps={{
338-
- startAdornment: <SearchIcon />,
339-
+ startAdornment: <SearchIcon aria-label="Search icon" />,
337+
slotProps={{
338+
input: {
339+
- startAdornment: <SearchIcon />,
340+
+ startAdornment: <SearchIcon aria-label="Search icon" />,
341+
},
340342
}}
341343
/>
342344
);
@@ -512,13 +514,13 @@ import { useSearchBar } from './search-bar.hook';
512514
+ { id: 2, name: 'blue' },
513515
+ { id: 3, name: 'green' },
514516
+ ];
515-
+ const debounceSearchStub = vi.spyOn(commonHooks, 'useDebounce');
517+
+ vi.spyOn(commonHooks, 'useDebounce');
516518

517519
+ // Act
518520
+ renderHook(() => useSearchBar(colors, ['name']));
519521

520522
+ // Assert
521-
+ expect(debounceSearchStub).toHaveBeenCalledWith('', 250);
523+
+ expect(commonHooks.useDebounce).toHaveBeenCalledWith('', 250);
522524
+ });
523525

524526
```
@@ -537,15 +539,13 @@ _./src/common/components/search-bar/search-bar.hook.spec.tsx_
537539
+ { id: 2, name: 'blue' },
538540
+ { id: 3, name: 'green' },
539541
+ ];
540-
+ const debounceSearchStub = vi
541-
+ .spyOn(commonHooks, 'useDebounce')
542-
+ .mockReturnValue('blue');
542+
+ vi.spyOn(commonHooks, 'useDebounce').mockReturnValue('blue');
543543

544544
+ // Act
545545
+ const { result } = renderHook(() => useSearchBar(colors, ['name']));
546546

547547
+ // Assert
548-
+ expect(debounceSearchStub).toHaveBeenCalledWith('', 250);
548+
+ expect(commonHooks.useDebounce).toHaveBeenCalledWith('', 250);
549549
+ expect(result.current.search).toEqual('');
550550
+ expect(result.current.filteredList).toEqual([{ id: 2, name: 'blue' }]);
551551
+ });
@@ -570,13 +570,13 @@ import { useSearchBar } from './search-bar.hook';
570570
+ { id: 2, name: 'blue' },
571571
+ { id: 3, name: 'green' },
572572
+ ];
573-
+ const filterByTextStub = vi.spyOn(filterHelpers, 'filterByText');
573+
+ vi.spyOn(filterHelpers, 'filterByText');
574574

575575
+ // Act
576576
+ renderHook(() => useSearchBar(colors, ['name']));
577577

578578
+ // Assert
579-
+ expect(filterByTextStub).toHaveBeenCalledWith(colors, '', ['name']);
579+
+ expect(filterHelpers.filterByText).toHaveBeenCalledWith(colors, '', ['name']);
580580
+ });
581581

582582
```
@@ -595,18 +595,18 @@ _./src/common/components/search-bar/search-bar.hook.spec.tsx_
595595
+ { id: 2, name: 'blue' },
596596
+ { id: 3, name: 'green' },
597597
+ ];
598-
+ const filterByTextStub = vi
599-
+ .spyOn(filterHelpers, 'filterByText')
600-
+ .mockReturnValue([
601-
+ { id: 2, name: 'blue' },
602-
+ { id: 3, name: 'green' },
603-
+ ]);
598+
+ vi.spyOn(filterHelpers, 'filterByText').mockReturnValue([
599+
+ { id: 2, name: 'blue' },
600+
+ { id: 3, name: 'green' },
601+
+ ]);
604602

605603
+ // Act
606604
+ const { result } = renderHook(() => useSearchBar(colors, ['name']));
607605

608606
+ // Assert
609-
+ expect(filterByTextStub).toHaveBeenCalledWith(colors, '', ['name']);
607+
+ expect(filterHelpers.filterByText).toHaveBeenCalledWith(colors, '', [
608+
+ 'name',
609+
+ ]);
610610
+ expect(result.current.search).toEqual('');
611611
+ expect(result.current.filteredList).toEqual([
612612
+ { id: 2, name: 'blue' },

0 commit comments

Comments
 (0)