@@ -2,7 +2,11 @@ import { render, screen } from '@testing-library/react';
2
2
import { MemoryRouter } from 'react-router-dom' ;
3
3
import { List } from '../src/views/List' ;
4
4
import { mockShoppingListData } from '../src/mocks/__fixtures__/shoppingListData' ;
5
- import { useStateWithStorage , useEnsureListPath } from '../src/hooks' ;
5
+ import {
6
+ useStateWithStorage ,
7
+ useEnsureListPath ,
8
+ useUrgency ,
9
+ } from '../src/hooks' ;
6
10
import {
7
11
getDateLastPurchasedOrDateCreated ,
8
12
getDaysFromDate ,
@@ -12,20 +16,7 @@ import {
12
16
vi . mock ( '../src/hooks' , ( ) => ( {
13
17
useEnsureListPath : vi . fn ( ) ,
14
18
useStateWithStorage : vi . fn ( ) ,
15
- useUrgency : vi . fn ( ( ) => ( {
16
- getUrgency : vi . fn ( ( name ) => {
17
- if ( name === 'nutella' ) return 'soon' ;
18
- if ( name === 'Cheese' ) return 'overdue' ;
19
- return 'notSoon' ;
20
- } ) ,
21
- urgencyObject : {
22
- overdue : [ { name : 'nutella' , id : '0T1ByXr8YJSOzujOlLMI' } ] ,
23
- soon : [ { name : 'Cheese' , id : '1MFWOWMCzDtEHQboFZfR' } ] ,
24
- kindOfSoon : [ ] ,
25
- notSoon : [ { name : 'Jam' , id : 'MnUiYUmhg8iCzX1eMxW8' } ] ,
26
- inactive : [ ] ,
27
- } ,
28
- } ) ) ,
19
+ useUrgency : vi . fn ( ) ,
29
20
} ) ) ;
30
21
31
22
vi . mock ( '../src/utils' , ( ) => ( {
@@ -36,6 +27,7 @@ vi.mock('../src/utils', () => ({
36
27
} ) ) ;
37
28
38
29
beforeEach ( ( ) => {
30
+ vi . clearAllMocks ( ) ;
39
31
Object . defineProperty ( window , 'localStorage' , {
40
32
value : {
41
33
getItem : vi . fn ( ( key ) => {
@@ -52,6 +44,21 @@ beforeEach(() => {
52
44
53
45
vi . spyOn ( window , 'alert' ) . mockImplementation ( ( ) => { } ) ;
54
46
useStateWithStorage . mockReturnValue ( [ '/groceries' ] ) ;
47
+ useEnsureListPath . mockReturnValue ( false ) ;
48
+ useUrgency . mockReturnValue ( {
49
+ getUrgency : vi . fn ( ( name ) => {
50
+ if ( name === 'nutella' ) return 'soon' ;
51
+ if ( name === 'Cheese' ) return 'overdue' ;
52
+ return 'notSoon' ;
53
+ } ) ,
54
+ urgencyObject : {
55
+ overdue : [ { name : 'nutella' , id : '0T1ByXr8YJSOzujOlLMI' } ] ,
56
+ soon : [ { name : 'Cheese' , id : '1MFWOWMCzDtEHQboFZfR' } ] ,
57
+ kindOfSoon : [ ] ,
58
+ notSoon : [ { name : 'Jam' , id : 'MnUiYUmhg8iCzX1eMxW8' } ] ,
59
+ inactive : [ ] ,
60
+ } ,
61
+ } ) ;
55
62
getDateLastPurchasedOrDateCreated . mockReturnValue ( new Date ( ) ) ;
56
63
getDaysFromDate . mockReturnValue ( 10 ) ;
57
64
getDaysBetweenDates . mockReturnValue ( 5 ) ;
@@ -81,6 +88,9 @@ describe('List Component', () => {
81
88
) ;
82
89
83
90
expect ( screen . getByText ( 'Welcome to groceries!' ) ) . toBeInTheDocument ( ) ;
91
+ expect (
92
+ screen . getByText ( 'Ready to add your first item? Start adding below!' ) ,
93
+ ) . toBeInTheDocument ( ) ;
84
94
expect ( screen . getByLabelText ( 'Item Name:' ) ) . toBeInTheDocument ( ) ;
85
95
expect ( screen . getByLabelText ( 'Soon' ) ) . toBeInTheDocument ( ) ;
86
96
expect ( screen . getByLabelText ( 'Kind of soon' ) ) . toBeInTheDocument ( ) ;
@@ -89,8 +99,6 @@ describe('List Component', () => {
89
99
} ) ;
90
100
91
101
test ( 'triggers alert and redirects when no list path is found in localStorage' , ( ) => {
92
- window . localStorage . getItem . mockReturnValueOnce ( null ) ;
93
-
94
102
useEnsureListPath . mockImplementation ( ( ) => {
95
103
window . alert (
96
104
'It seems like you landed here without first creating a list or selecting an existing one. Please select or create a new list first. Redirecting to Home.' ,
0 commit comments