@@ -201,12 +201,52 @@ def test_progress_bar(self):
201201 self .assertEqual (test_progress_bar_amount , self .app .session_state .weekly_calorie_progress_amount )
202202
203203
204- class TestDisplayGenAiAdvice (unittest .TestCase ):
205- """Tests the display_genai_advice function."""
206204
207- def test_foo (self ):
208- """Tests foo."""
209- pass
205+ class TestDisplayGenAIAdvice (unittest .TestCase ):
206+ """Tests the display_genai_advice function using Streamlit's AppTest."""
207+
208+
209+ def setUp (self ):
210+ """Set up the AppTest environment with test input values."""
211+ self .test_timestamp = "2024-03-07 12:00:00"
212+ self .test_content = "Stay hydrated and take breaks between workouts."
213+ self .test_image = "https://www.google.com/imgres?q=picture%20of%20water&imgurl=https%3A%2F%2Fmedia.istockphoto.com%2Fid%2F491962870%2Fphoto%2Fmineral-water-is-being-poured-into-glass.jpg%3Fs%3D612x612%26w%3D0%26k%3D20%26c%3DSyuhabOpDKyVo78GtFcOi_7j6r5e4BYMtZFQtDdC7UE%3D&imgrefurl=https%3A%2F%2Fwww.istockphoto.com%2Fphotos%2Fpure-water&docid=5s6c7T7yGr9fbM&tbnid=rHwc6oimw3j6SM&vet=12ahUKEwjwvrTloPmLAxW5M9AFHRRQEB8QM3oECBgQAA..i&w=612&h=459&hcb=2&ved=2ahUKEwjwvrTloPmLAxW5M9AFHRRQEB8QM3oECBgQAA"
214+
215+ self .app = AppTest .from_function (
216+ display_genai_advice ,
217+ kwargs = {
218+ "timestamp" : self .test_timestamp ,
219+ "content" : self .test_content ,
220+ "image" : self .test_image
221+ }
222+ )
223+
224+ self .app .run () # Run the app to apply testing
225+
226+ def test_title_existence (self ):
227+ """Check if the title is present."""
228+ title_elements = [el .value for el in self .app .title ]
229+
230+ # Check for title
231+ found_title = any ("AI Fitness Coach" in text for text in title_elements )
232+ self .assertTrue (found_title , "Title 'AI Fitness Coach title' not found!" )
233+
234+ def test_subheader_existence (self ):
235+ """Check if the subheader is present."""
236+ subheader_elements = [el .value for el in self .app .subheader ]
237+ self .assertTrue (any ("Personalized advice based on your activities" in text for text in subheader_elements ),
238+ "Subheader 'Personalized advice based on your activities' not found!" )
239+
240+ def test_markdown_content (self ):
241+ """Check if the content is correctly displayed."""
242+ markdown_elements = [el .value for el in self .app .markdown ]
243+ self .assertIn (self .test_content , markdown_elements , "Advice content not displayed correctly!" )
244+
245+ def test_timestamp_display (self ):
246+ """Check if the timestamp is correctly displayed."""
247+ markdown_elements = [el .value for el in self .app .markdown ]
248+ expected_timestamp_text = f"Last updated: { self .test_timestamp } "
249+ self .assertIn (expected_timestamp_text , markdown_elements , "Timestamp not displayed correctly!" )
210250
211251
212252class TestDisplayRecentWorkouts (unittest .TestCase ):
0 commit comments