@@ -4,8 +4,9 @@ import { fireEvent, render, waitFor } from '@testing-library/react';
4
4
import { makeTestHabit } from '@tests' ;
5
5
import { format } from 'date-fns' ;
6
6
import React from 'react' ;
7
+ import { BrowserRouter } from 'react-router-dom' ;
7
8
8
- import DayHabitModalDialog from './DayHabitModalDialog ' ;
9
+ import AddOccurrenceDialog from './AddOccurrenceDialog ' ;
9
10
10
11
jest . mock ( '@stores' , ( ) => ( {
11
12
useHabitsStore : jest . fn ( ) ,
@@ -20,7 +21,7 @@ jest.mock('date-fns', () => ({
20
21
format : jest . fn ( ) ,
21
22
} ) ) ;
22
23
23
- describe ( DayHabitModalDialog . name , ( ) => {
24
+ describe ( AddOccurrenceDialog . name , ( ) => {
24
25
const mockOnClose = jest . fn ( ) ;
25
26
const date = new Date ( 2021 , 1 , 1 , 12 ) ;
26
27
@@ -42,7 +43,11 @@ describe(DayHabitModalDialog.name, () => {
42
43
addOccurrence : jest . fn ( ) ,
43
44
addingOccurrence : false ,
44
45
} ) ;
45
- const { getByText } = render ( < DayHabitModalDialog { ...props } /> ) ;
46
+ const { getByText } = render (
47
+ < BrowserRouter >
48
+ < AddOccurrenceDialog { ...props } />
49
+ </ BrowserRouter >
50
+ ) ;
46
51
expect ( getByText ( 'Add habit entries for 2021-01-01' ) ) . toBeInTheDocument ( ) ;
47
52
} ) ;
48
53
@@ -55,7 +60,7 @@ describe(DayHabitModalDialog.name, () => {
55
60
addingOccurrence : false ,
56
61
} ) ;
57
62
const { container } = render (
58
- < DayHabitModalDialog { ...props } date = { null } />
63
+ < AddOccurrenceDialog { ...props } date = { null } />
59
64
) ;
60
65
expect ( container . firstChild ) . toBeNull ( ) ;
61
66
} ) ;
@@ -69,7 +74,7 @@ describe(DayHabitModalDialog.name, () => {
69
74
addingOccurrence : false ,
70
75
} ) ;
71
76
const { container } = render (
72
- < DayHabitModalDialog { ...props } open = { false } />
77
+ < AddOccurrenceDialog { ...props } open = { false } />
73
78
) ;
74
79
expect ( container . firstChild ) . toBeNull ( ) ;
75
80
} ) ;
@@ -83,7 +88,7 @@ describe(DayHabitModalDialog.name, () => {
83
88
addingOccurrence : false ,
84
89
} ) ;
85
90
const { container } = render (
86
- < DayHabitModalDialog { ...props } date = { null } />
91
+ < AddOccurrenceDialog { ...props } date = { null } />
87
92
) ;
88
93
expect ( container . firstChild ) . toBeNull ( ) ;
89
94
} ) ;
@@ -96,8 +101,14 @@ describe(DayHabitModalDialog.name, () => {
96
101
addOccurrence : jest . fn ( ) ,
97
102
addingOccurrence : false ,
98
103
} ) ;
99
- const { getAllByText } = render ( < DayHabitModalDialog { ...props } /> ) ;
100
- expect ( getAllByText ( 'No habits yet' ) ) . toHaveLength ( 2 ) ;
104
+ const { getByText } = render (
105
+ < BrowserRouter >
106
+ < AddOccurrenceDialog { ...props } />
107
+ </ BrowserRouter >
108
+ ) ;
109
+ expect (
110
+ getByText ( 'No habits yet. Create a habit to get started.' )
111
+ ) . toBeInTheDocument ( ) ;
101
112
} ) ;
102
113
103
114
it ( 'should render habit options' , ( ) => {
@@ -110,7 +121,7 @@ describe(DayHabitModalDialog.name, () => {
110
121
addOccurrence : jest . fn ( ) ,
111
122
addingOccurrence : false ,
112
123
} ) ;
113
- const { getByText } = render ( < DayHabitModalDialog { ...props } /> ) ;
124
+ const { getByText } = render ( < AddOccurrenceDialog { ...props } /> ) ;
114
125
expect ( getByText ( 'Test Habit' ) ) . toBeInTheDocument ( ) ;
115
126
} ) ;
116
127
@@ -125,7 +136,7 @@ describe(DayHabitModalDialog.name, () => {
125
136
addingOccurrence : false ,
126
137
} ) ;
127
138
const { container, getAllByText, getByTestId } = render (
128
- < DayHabitModalDialog { ...props } />
139
+ < AddOccurrenceDialog { ...props } />
129
140
) ;
130
141
fireEvent . click ( getByTestId ( 'habit-select' ) ) ;
131
142
fireEvent . click ( getAllByText ( 'Test Habit' ) [ 1 ] ) ;
@@ -145,7 +156,7 @@ describe(DayHabitModalDialog.name, () => {
145
156
addOccurrence : jest . fn ( ) ,
146
157
addingOccurrence : false ,
147
158
} ) ;
148
- const { getByRole } = render ( < DayHabitModalDialog { ...props } /> ) ;
159
+ const { getByRole } = render ( < AddOccurrenceDialog { ...props } /> ) ;
149
160
fireEvent . click ( getByRole ( 'button' , { name : 'Close' } ) ) ;
150
161
expect ( mockOnClose ) . toHaveBeenCalledTimes ( 1 ) ;
151
162
} ) ;
@@ -160,7 +171,7 @@ describe(DayHabitModalDialog.name, () => {
160
171
addOccurrence : jest . fn ( ) ,
161
172
addingOccurrence : false ,
162
173
} ) ;
163
- const { getByRole, getByText } = render ( < DayHabitModalDialog { ...props } /> ) ;
174
+ const { getByRole, getByText } = render ( < AddOccurrenceDialog { ...props } /> ) ;
164
175
fireEvent . click ( getByRole ( 'habit-select' ) ) ;
165
176
fireEvent . click ( getByText ( 'Test Habit' ) ) ;
166
177
expect (
@@ -183,7 +194,7 @@ describe(DayHabitModalDialog.name, () => {
183
194
addOccurrence : mockAddOccurrence ,
184
195
addingOccurrence : false ,
185
196
} ) ;
186
- const { getByRole, getByText } = render ( < DayHabitModalDialog { ...props } /> ) ;
197
+ const { getByRole, getByText } = render ( < AddOccurrenceDialog { ...props } /> ) ;
187
198
fireEvent . click ( getByRole ( 'habit-select' ) ) ;
188
199
fireEvent . click ( getByText ( 'Test Habit' ) ) ;
189
200
expect (
0 commit comments