前后端更新

This commit is contained in:
super committed 2026-03-04 22:55:36 +08:00
1 parent a0c8721fbb
commit 24da604727
33 files changed
+1951 -580

No files matched your search

+61
View File
@@ -0,0 +1,61 @@
import pytest
from app import create_app, db
from app.models import User, UserHomepageConfig
@pytest.fixture
def client():
app = create_app('testing')
app.config['TESTING'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
with app.test_client() as client:
with app.app_context():
db.create_all()
# Create user
user = User(username='testuser', role='user', email='test@example.com')
user.set_password('password')
db.session.add(user)
db.session.commit()
yield client
db.session.remove()
db.drop_all()
def get_headers(client):
res = client.post('/api/user/login', json={'username': 'testuser', 'password': 'password'})
data = res.get_json()
return {
'X-User-Id': str(data['id']),
'X-Username': data['username'],
'X-Role': data['role'],
'Content-Type': 'application/json'
}
def test_layout_collapse_persistence(client):
headers = get_headers(client)
# 1. Update layout with collapsed state
layout_data = {
'layout': {
'sections': [
{'id': 'favorites', 'visible': True, 'collapsed': True},
{'id': 'all_agents', 'visible': True, 'collapsed': False}
]
}
}
res = client.put('/api/user/homepage-layout', headers=headers, json=layout_data)
assert res.status_code == 200
# 2. Fetch layout and verify collapsed state
res = client.get('/api/user/home', headers=headers)
assert res.status_code == 200
data = res.get_json()
sections = data['layout']['sections']
favorites = next(s for s in sections if s['id'] == 'favorites')
all_agents = next(s for s in sections if s['id'] == 'all_agents')
assert favorites['collapsed'] is True
assert all_agents['collapsed'] is False