Refactor tests for HostsManagerApp: update status verification to use footer instead of subtitle for improved accuracy and clarity.
This commit is contained in:
		
							parent
							
								
									bc0f8b99e8
								
							
						
					
					
						commit
						e6f3e9f3d4
					
				
					 2 changed files with 27 additions and 10 deletions
				
			
		| 
						 | 
					@ -78,7 +78,7 @@
 | 
				
			||||||
- ✅ **Entry editing**: Complete inline editing for IP, hostnames, comments, and active status
 | 
					- ✅ **Entry editing**: Complete inline editing for IP, hostnames, comments, and active status
 | 
				
			||||||
- ✅ **Search functionality**: Complete search/filter by hostname, IP address, or comment
 | 
					- ✅ **Search functionality**: Complete search/filter by hostname, IP address, or comment
 | 
				
			||||||
- ✅ **Undo/Redo**: Complete command pattern implementation with 43 comprehensive tests
 | 
					- ✅ **Undo/Redo**: Complete command pattern implementation with 43 comprehensive tests
 | 
				
			||||||
- ❌ **Bulk operations**: Select and modify multiple entries (moved to Phase 6)
 | 
					- ❌ ~~**Bulk operations**: Select and modify multiple entries (won't be implemented)~~
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Phase 5: Advanced Features
 | 
					### Phase 5: Advanced Features
 | 
				
			||||||
- ❌ **DNS resolution**: Resolve hostnames to IP addresses
 | 
					- ❌ **DNS resolution**: Resolve hostnames to IP addresses
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -267,6 +267,10 @@ class TestHostsManagerApp:
 | 
				
			||||||
        ):
 | 
					        ):
 | 
				
			||||||
            app = HostsManagerApp()
 | 
					            app = HostsManagerApp()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            # Mock the query_one method to avoid UI dependencies
 | 
				
			||||||
 | 
					            mock_footer = Mock()
 | 
				
			||||||
 | 
					            app.query_one = Mock(return_value=mock_footer)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # Add test entries
 | 
					            # Add test entries
 | 
				
			||||||
            app.hosts_file = HostsFile()
 | 
					            app.hosts_file = HostsFile()
 | 
				
			||||||
            app.hosts_file.add_entry(
 | 
					            app.hosts_file.add_entry(
 | 
				
			||||||
| 
						 | 
					@ -280,10 +284,12 @@ class TestHostsManagerApp:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            app.update_status()
 | 
					            app.update_status()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # Verify sub_title was set correctly
 | 
					            # Verify footer status was updated
 | 
				
			||||||
            assert "Read-only mode" in app.sub_title
 | 
					            mock_footer.set_status.assert_called_once()
 | 
				
			||||||
            assert "2 entries" in app.sub_title
 | 
					            status_call = mock_footer.set_status.call_args[0][0]
 | 
				
			||||||
            assert "1 active" in app.sub_title
 | 
					            assert "Read-only" in status_call
 | 
				
			||||||
 | 
					            assert "2 entries" in status_call
 | 
				
			||||||
 | 
					            assert "1 active" in status_call
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_update_status_custom_message(self):
 | 
					    def test_update_status_custom_message(self):
 | 
				
			||||||
        """Test status bar update with custom message."""
 | 
					        """Test status bar update with custom message."""
 | 
				
			||||||
| 
						 | 
					@ -299,9 +305,18 @@ class TestHostsManagerApp:
 | 
				
			||||||
            # Mock set_timer and query_one to avoid event loop and UI issues
 | 
					            # Mock set_timer and query_one to avoid event loop and UI issues
 | 
				
			||||||
            app.set_timer = Mock()
 | 
					            app.set_timer = Mock()
 | 
				
			||||||
            mock_status_bar = Mock()
 | 
					            mock_status_bar = Mock()
 | 
				
			||||||
            app.query_one = Mock(return_value=mock_status_bar)
 | 
					            mock_footer = Mock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # Add test hosts_file for subtitle generation
 | 
					            def mock_query_one(selector, widget_type=None):
 | 
				
			||||||
 | 
					                if selector == "#status-bar":
 | 
				
			||||||
 | 
					                    return mock_status_bar
 | 
				
			||||||
 | 
					                elif selector == "#custom-footer":
 | 
				
			||||||
 | 
					                    return mock_footer
 | 
				
			||||||
 | 
					                return Mock()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            app.query_one = mock_query_one
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            # Add test hosts_file for footer status generation
 | 
				
			||||||
            app.hosts_file = HostsFile()
 | 
					            app.hosts_file = HostsFile()
 | 
				
			||||||
            app.hosts_file.add_entry(
 | 
					            app.hosts_file.add_entry(
 | 
				
			||||||
                HostEntry(ip_address="127.0.0.1", hostnames=["localhost"])
 | 
					                HostEntry(ip_address="127.0.0.1", hostnames=["localhost"])
 | 
				
			||||||
| 
						 | 
					@ -317,9 +332,11 @@ class TestHostsManagerApp:
 | 
				
			||||||
            # Verify status bar was updated with custom message
 | 
					            # Verify status bar was updated with custom message
 | 
				
			||||||
            mock_status_bar.update.assert_called_with("Custom status message")
 | 
					            mock_status_bar.update.assert_called_with("Custom status message")
 | 
				
			||||||
            mock_status_bar.remove_class.assert_called_with("hidden")
 | 
					            mock_status_bar.remove_class.assert_called_with("hidden")
 | 
				
			||||||
            # Verify subtitle shows current status (not the custom message)
 | 
					            # Verify footer status was updated with current status (not the custom message)
 | 
				
			||||||
            assert "2 entries" in app.sub_title
 | 
					            mock_footer.set_status.assert_called_once()
 | 
				
			||||||
            assert "Read-only mode" in app.sub_title
 | 
					            footer_status = mock_footer.set_status.call_args[0][0]
 | 
				
			||||||
 | 
					            assert "2 entries" in footer_status
 | 
				
			||||||
 | 
					            assert "Read-only" in footer_status
 | 
				
			||||||
            # Verify timer was set for auto-clearing
 | 
					            # Verify timer was set for auto-clearing
 | 
				
			||||||
            app.set_timer.assert_called_once()
 | 
					            app.set_timer.assert_called_once()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue