function test_frontend_files
A test function that validates the presence of model selection functionality in frontend files (HTML, JavaScript, and CSS) for a document chat application.
/tf/active/vicechatdev/docchat/test_model_selection.py
135 - 169
simple
Purpose
This function performs integration testing to ensure that frontend files have been properly updated with model selection features. It checks that index.html contains a model selector element, app.js includes model selection functions and sends model data in requests, and style.css has appropriate styling for the model selector. This is part of a test suite (TEST 5) that validates the frontend implementation of a multi-model chat interface.
Source Code
def test_frontend_files():
"""Test that frontend files have been updated"""
print("=" * 60)
print("TEST 5: Frontend Files")
print("=" * 60)
import os
# Check index.html has model-select
html_file = '/tf/active/docchat/templates/index.html'
with open(html_file, 'r') as f:
html_content = f.read()
assert 'model-select' in html_content, "index.html missing model-select element"
print("✓ index.html contains model selector")
# Check app.js has getSelectedModel
js_file = '/tf/active/docchat/static/js/app.js'
with open(js_file, 'r') as f:
js_content = f.read()
assert 'getSelectedModel' in js_content, "app.js missing getSelectedModel function"
assert 'loadModels' in js_content, "app.js missing loadModels function"
assert 'model: model' in js_content, "app.js not sending model in request"
print("✓ app.js has model selection functions")
# Check style.css has model-select styles
css_file = '/tf/active/docchat/static/css/style.css'
with open(css_file, 'r') as f:
css_content = f.read()
assert '.model-select' in css_content, "style.css missing .model-select styles"
print("✓ style.css has model selector styles")
print()
Return Value
This function does not return any value (implicitly returns None). It either completes successfully with printed confirmation messages or raises an AssertionError if any of the required frontend elements are missing.
Dependencies
os
Required Imports
import os
Usage Example
# Run the test function to validate frontend files
try:
test_frontend_files()
print("All frontend file checks passed!")
except AssertionError as e:
print(f"Test failed: {e}")
except FileNotFoundError as e:
print(f"Required file not found: {e}")
Best Practices
- This function uses hardcoded file paths specific to a Docker container environment (/tf/active/docchat/). Modify paths if running in a different environment.
- The function performs simple string matching to verify presence of elements. It does not validate syntax or functionality of the code.
- This is a test function meant to be run as part of a test suite, not in production code.
- Ensure all required files exist and are readable before running this test.
- The function prints progress messages to stdout, which is appropriate for test output but may need redirection in automated testing environments.
- Consider wrapping this in a try-except block to handle FileNotFoundError gracefully if files don't exist.
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function test_web_ui 60.0% similar
-
function main_v39 55.9% similar
-
function main_v30 55.4% similar
-
function test_markdown_processing 55.1% similar
-
function test_fixes 55.1% similar