"""E2E tests for sample scenario loading.""" import pytest from playwright.sync_api import Page, expect def select_sample(page: Page, sample_text: str): """Helper to select a sample from the dropdown. Args: page: Playwright page sample_text: Text of the sample option to select (e.g., "Bar & Dining Area") """ # Gradio dropdowns use input[role='listbox'] - click to open page.locator("#sample_dropdown input[role='listbox']").click() page.wait_for_timeout(300) # Wait for dropdown to open # Click the option with matching text page.locator(f"[role='option']:has-text('{sample_text}')").click() # Wait for form to be populated - check that project_name has a value # Gradio 6.x uses textarea for textboxes page.wait_for_function( """() => { const textarea = document.querySelector('#project_name textarea'); return textarea && textarea.value && textarea.value.includes('Sample:'); }""", timeout=30000 ) class TestSampleLoading: """Test loading sample scenarios via dropdown.""" def test_bar_dining_loads_correctly(self, page: Page): """Verify Bar & Dining sample loads all data.""" select_sample(page, "Bar & Dining Area") # Verify Tab 1 populated expect(page.locator("#project_name textarea")).to_have_value( "Sample: Bar & Dining Fire Assessment" ) expect(page.locator("#city textarea")).to_have_value("Springfield") def test_bar_area_loads_correctly(self, page: Page): """Verify Bar Area sample loads all data.""" select_sample(page, "Bar Area") expect(page.locator("#project_name textarea")).to_have_value( "Sample: Bar Area Fire Assessment" ) def test_kitchen_loads_6_images(self, page: Page): """Verify Kitchen sample loads 6 images.""" select_sample(page, "Kitchen") # Navigate to Images tab page.locator("#tab-images-button").click() # Wait for gallery to populate - may take time for images to render page.wait_for_function( """() => { const gallery = document.querySelector('#images_gallery'); const images = gallery ? gallery.querySelectorAll('img') : []; return images.length > 0; }""", timeout=10000 ) # Verify image count in gallery gallery = page.locator("#images_gallery") images = gallery.locator("img") expect(images).to_have_count(6) def test_factory_loads_1_image(self, page: Page): """Verify Factory sample loads 1 image.""" select_sample(page, "Factory Area") # Navigate to Images tab page.locator("#tab-images-button").click() page.wait_for_timeout(500) # Verify image count gallery = page.locator("#images_gallery") images = gallery.locator("img") expect(images).to_have_count(1) def test_factory_operational_facility(self, page: Page): """Verify Factory sample has operational classification.""" select_sample(page, "Factory Area") # Check facility classification shows Operational expect(page.locator("#facility_classification")).to_contain_text("Operational") def test_sample_dropdown_resets_after_selection(self, page: Page): """Verify dropdown resets to placeholder after loading sample.""" select_sample(page, "Bar & Dining Area") # Dropdown should reset to placeholder text dropdown_input = page.locator("#sample_dropdown input[role='listbox']") expect(dropdown_input).to_have_value("Select a sample scenario...") class TestSampleRoomData: """Test that sample rooms load correct data.""" def test_bar_dining_room_dimensions(self, page: Page): """Verify Bar & Dining room has correct dimensions.""" select_sample(page, "Bar & Dining Area") # Navigate to Rooms tab page.locator("#tab-rooms-button").click() page.wait_for_timeout(500) # Verify room table shows the room expect(page.locator("#rooms_table")).to_contain_text("Bar & Dining Area") expect(page.locator("#rooms_table")).to_contain_text("40") # Length expect(page.locator("#rooms_table")).to_contain_text("30") # Width def test_kitchen_room_dimensions(self, page: Page): """Verify Kitchen room has correct dimensions.""" select_sample(page, "Kitchen") # Navigate to Rooms tab page.locator("#tab-rooms-button").click() page.wait_for_timeout(500) # Verify room name expect(page.locator("#rooms_table")).to_contain_text("Commercial Kitchen") class TestSampleObservations: """Test that sample observations load correctly.""" def test_bar_dining_observations(self, page: Page): """Verify Bar & Dining sample loads observations.""" select_sample(page, "Bar & Dining Area") # Navigate to Observations tab page.locator("#tab-observations-button").click() page.wait_for_timeout(500) # Verify smoke odor checkbox is checked smoke_checkbox = page.locator("#smoke_odor input[type='checkbox']") expect(smoke_checkbox).to_be_checked() # Verify odor intensity shows Strong expect(page.locator("#odor_intensity")).to_contain_text("Strong")