|
| 1 | +import unittest |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | + |
| 5 | +class TestHintVisibilityIntegration(unittest.TestCase): |
| 6 | + """Integration tests for hint visibility functionality across web and text clients""" |
| 7 | + |
| 8 | + def setUp(self) -> None: |
| 9 | + self.template_path = Path(__file__).parent.parent / "WebHostLib" / "templates" / "multitrackerHintTable.html" |
| 10 | + self.js_path = Path(__file__).parent.parent / "WebHostLib" / "static" / "assets" / "trackerCommon.js" |
| 11 | + self.kvui_path = Path(__file__).parent.parent / "kvui.py" |
| 12 | + self.common_client_path = Path(__file__).parent.parent / "CommonClient.py" |
| 13 | + |
| 14 | + def test_consistent_functionality_across_clients(self) -> None: |
| 15 | + """Test that both web and text clients have consistent hint visibility functionality""" |
| 16 | + # Check web client has toggle controls |
| 17 | + with open(self.template_path, 'r') as f: |
| 18 | + web_content = f.read() |
| 19 | + |
| 20 | + self.assertIn('hide-completed-hints', web_content, |
| 21 | + "Web client should have hide completed hints toggle") |
| 22 | + self.assertIn('hide-external-items', web_content, |
| 23 | + "Web client should have hide external items toggle") |
| 24 | + |
| 25 | + # Check JavaScript has filtering functions |
| 26 | + with open(self.js_path, 'r') as f: |
| 27 | + js_content = f.read() |
| 28 | + |
| 29 | + self.assertIn('filterHints', js_content, |
| 30 | + "Web client should have hint filtering function") |
| 31 | + |
| 32 | + # Check text client has filtering methods |
| 33 | + with open(self.kvui_path, 'r') as f: |
| 34 | + kvui_content = f.read() |
| 35 | + |
| 36 | + self.assertIn('filter_completed_hints', kvui_content, |
| 37 | + "Text client should have completed hints filtering") |
| 38 | + self.assertIn('filter_external_items', kvui_content, |
| 39 | + "Text client should have external items filtering") |
| 40 | + |
| 41 | + # Check text client has commands |
| 42 | + with open(self.common_client_path, 'r') as f: |
| 43 | + client_content = f.read() |
| 44 | + |
| 45 | + self.assertIn('_cmd_hide_completed_hints', client_content, |
| 46 | + "Text client should have hide completed hints command") |
| 47 | + self.assertIn('_cmd_hide_external_items', client_content, |
| 48 | + "Text client should have hide external items command") |
| 49 | + |
| 50 | + def test_edge_case_handling(self) -> None: |
| 51 | + """Test edge cases for hint filtering""" |
| 52 | + # Test empty hints list |
| 53 | + empty_hints = [] |
| 54 | + |
| 55 | + # Test all hints completed |
| 56 | + all_completed_hints = [ |
| 57 | + {"found": True, "receiving_player": 1}, |
| 58 | + {"found": True, "receiving_player": 2}, |
| 59 | + {"found": True, "receiving_player": 3} |
| 60 | + ] |
| 61 | + |
| 62 | + # Test no hints completed |
| 63 | + no_completed_hints = [ |
| 64 | + {"found": False, "receiving_player": 1}, |
| 65 | + {"found": False, "receiving_player": 2}, |
| 66 | + {"found": False, "receiving_player": 3} |
| 67 | + ] |
| 68 | + |
| 69 | + # Test mixed hints |
| 70 | + mixed_hints = [ |
| 71 | + {"found": True, "receiving_player": 1}, |
| 72 | + {"found": False, "receiving_player": 2}, |
| 73 | + {"found": True, "receiving_player": 3} |
| 74 | + ] |
| 75 | + |
| 76 | + # Basic filtering logic tests |
| 77 | + completed_count = len([h for h in mixed_hints if h["found"]]) |
| 78 | + uncompleted_count = len([h for h in mixed_hints if not h["found"]]) |
| 79 | + |
| 80 | + self.assertEqual(completed_count, 2, "Should have 2 completed hints") |
| 81 | + self.assertEqual(uncompleted_count, 1, "Should have 1 uncompleted hint") |
| 82 | + |
| 83 | + def test_css_classes_consistency(self) -> None: |
| 84 | + """Test that CSS classes are consistently applied""" |
| 85 | + with open(self.template_path, 'r') as f: |
| 86 | + content = f.read() |
| 87 | + |
| 88 | + # Check that hint rows have proper classes |
| 89 | + self.assertIn('hint-row', content, "Hint rows should have hint-row class") |
| 90 | + self.assertIn('hint-completed', content, "Completed hints should have hint-completed class") |
| 91 | + self.assertIn('hint-external', content, "External hints should have hint-external class") |
| 92 | + |
| 93 | + def test_javascript_functions_exist(self) -> None: |
| 94 | + """Test that all required JavaScript functions exist""" |
| 95 | + with open(self.js_path, 'r') as f: |
| 96 | + content = f.read() |
| 97 | + |
| 98 | + required_functions = [ |
| 99 | + 'filterHints', |
| 100 | + 'loadHintPreferences', |
| 101 | + 'initializeHintFiltering' |
| 102 | + ] |
| 103 | + |
| 104 | + for func in required_functions: |
| 105 | + self.assertIn(func, content, f"JavaScript should contain {func} function") |
| 106 | + |
| 107 | + def test_localStorage_usage(self) -> None: |
| 108 | + """Test that localStorage is used for persistence""" |
| 109 | + with open(self.js_path, 'r') as f: |
| 110 | + content = f.read() |
| 111 | + |
| 112 | + self.assertIn('localStorage.setItem', content, |
| 113 | + "Should save preferences to localStorage") |
| 114 | + self.assertIn('localStorage.getItem', content, |
| 115 | + "Should load preferences from localStorage") |
| 116 | + self.assertIn('hideCompletedHints', content, |
| 117 | + "Should store hideCompletedHints preference") |
| 118 | + self.assertIn('hideExternalItems', content, |
| 119 | + "Should store hideExternalItems preference") |
| 120 | + |
| 121 | + |
| 122 | +if __name__ == '__main__': |
| 123 | + unittest.main() |
| 124 | + |
0 commit comments