wizard
This commit is contained in:
@@ -77,18 +77,17 @@ def test_folder_deletion_and_resync_flow(playwright: playwright.sync_api.Playwri
|
||||
page.click("button[type='submit']")
|
||||
|
||||
# Wait for connection test to complete
|
||||
page.wait_for_selector("button:has-text('Configure Folder Types')")
|
||||
page.wait_for_selector("h3:has-text('Configure IMAP Folders')")
|
||||
|
||||
# Step 5: Sync folders and verify they exist
|
||||
# Click the "Configure Folder Types" button
|
||||
page.click("button:has-text('Configure Folder Types')")
|
||||
|
||||
# Step 5: Click "Save and Continue" on the final modal
|
||||
page.click("button:has-text('Save and Continue')")
|
||||
|
||||
# Wait for modal to close and navigation to complete
|
||||
page.wait_for_load_state("networkidle")
|
||||
|
||||
# Wait for modal to close and navigation to complete
|
||||
page.wait_for_load_state("networkidle")
|
||||
|
||||
# Wait for modal to appear and folders to sync
|
||||
page.wait_for_selector("#folders-list", timeout=10000)
|
||||
|
||||
|
||||
@@ -77,11 +77,7 @@ def test_full_user_flow(playwright: playwright.sync_api.Playwright):
|
||||
page.click("button[type='submit']")
|
||||
|
||||
# Wait for connection test to complete
|
||||
page.wait_for_selector("button:has-text('Configure Folder Types')")
|
||||
|
||||
# Step 4: Sync folders
|
||||
# Click the "Configure Folder Types" button
|
||||
page.click("button:has-text('Configure Folder Types')")
|
||||
page.wait_for_selector("h3:has-text('Configure IMAP Folders')")
|
||||
|
||||
# Step 5: Click "Save and Continue" on the final modal
|
||||
page.click("button:has-text('Save and Continue')")
|
||||
|
||||
@@ -19,17 +19,155 @@ class TestIMAPRoutes:
|
||||
print(response.data)
|
||||
|
||||
assert response.status_code == 200
|
||||
# Should show either success or error message
|
||||
assert b'Test Connection' in response.data
|
||||
# After successful connection, it should show the folder selection modal
|
||||
assert b'Configure IMAP Folders' in response.data
|
||||
|
||||
def test_imap_sync_folders(self, authenticated_client, app, mock_user):
|
||||
# Create a test user and log in
|
||||
def test_imap_sync_selected_folders_no_config(self, authenticated_client):
|
||||
"""Test sync-selected fails when no IMAP config is set"""
|
||||
response = authenticated_client.post('/api/imap/sync-selected', data={})
|
||||
assert response.status_code == 400
|
||||
assert b'No IMAP configuration found' in response.data
|
||||
|
||||
def test_imap_sync_selected_folders_no_selection(self, authenticated_client, mock_user):
|
||||
"""Test sync-selected fails when no folders are selected"""
|
||||
# Set up IMAP config
|
||||
mock_user.imap_config = {'server': 'localhost', 'port': 5143, 'username': 'user1@example.com', 'password': 'password1', 'use_ssl': False}
|
||||
db.session.commit()
|
||||
folders = Folder.query.filter_by(user_id=mock_user.id).all()
|
||||
response = authenticated_client.post('/api/imap/sync')
|
||||
print('respo', response.data, response)
|
||||
|
||||
response = authenticated_client.post('/api/imap/sync-selected', data={})
|
||||
assert response.status_code == 400
|
||||
assert b'No folders selected' in response.data
|
||||
|
||||
def test_imap_sync_selected_folders_with_real_folders(self, authenticated_client, mock_user):
|
||||
"""Test sync-selected succeeds with real folders from the IMAP server"""
|
||||
# Set up IMAP config
|
||||
mock_user.imap_config = {'server': 'localhost', 'port': 5143, 'username': 'user1@example.com', 'password': 'password1', 'use_ssl': False}
|
||||
db.session.commit()
|
||||
|
||||
# Get initial folder count
|
||||
initial_folders = Folder.query.filter_by(user_id=mock_user.id).all()
|
||||
initial_count = len(initial_folders)
|
||||
|
||||
# Use real folder names from the IMAP server that we saw in the test output
|
||||
# Note: The endpoint strips leading/trailing spaces before storing
|
||||
form_data = {
|
||||
'folder_0': ' Receipts',
|
||||
'folder_type_0': 'destination',
|
||||
'folder_1': ' Marketing',
|
||||
'folder_type_1': 'tidy'
|
||||
}
|
||||
|
||||
response = authenticated_client.post('/api/imap/sync-selected', data=form_data)
|
||||
|
||||
# Should return 200 with proper headers
|
||||
assert response.status_code == 200
|
||||
assert response.headers.get('HX-Trigger') == 'close-modal, folder-list-invalidated'
|
||||
|
||||
# Check that new folders were created
|
||||
new_folders = Folder.query.filter_by(user_id=mock_user.id).all()
|
||||
assert len(new_folders) > len(folders)
|
||||
# Should fail without real IMAP server but return proper response
|
||||
assert response.status_code in [200, 400]
|
||||
assert len(new_folders) > initial_count
|
||||
|
||||
# Verify folder types were set correctly (names are stripped before storing)
|
||||
receipts_folder = Folder.query.filter_by(user_id=mock_user.id, name='Receipts').first()
|
||||
marketing_folder = Folder.query.filter_by(user_id=mock_user.id, name='Marketing').first()
|
||||
|
||||
assert receipts_folder is not None
|
||||
assert receipts_folder.folder_type == 'destination'
|
||||
assert marketing_folder is not None
|
||||
assert marketing_folder.folder_type == 'tidy'
|
||||
|
||||
def test_imap_sync_selected_folders_existing_folders(self, authenticated_client, mock_user):
|
||||
"""Test sync-selected updates existing folders instead of creating duplicates"""
|
||||
# Set up IMAP config
|
||||
mock_user.imap_config = {'server': 'localhost', 'port': 5143, 'username': 'user1@example.com', 'password': 'password1', 'use_ssl': False}
|
||||
db.session.commit()
|
||||
|
||||
# Clean up any existing folders first
|
||||
Folder.query.filter_by(user_id=mock_user.id).delete()
|
||||
db.session.commit()
|
||||
|
||||
# Create an existing folder (without leading spaces since they get stripped)
|
||||
existing_folder = Folder(
|
||||
user_id=mock_user.id,
|
||||
name='Receipts', # This is how it will be stored after stripping
|
||||
folder_type='destination',
|
||||
total_count=5,
|
||||
pending_count=2
|
||||
)
|
||||
db.session.add(existing_folder)
|
||||
db.session.commit()
|
||||
|
||||
initial_count = Folder.query.filter_by(user_id=mock_user.id).count()
|
||||
|
||||
# Select the existing folder and a new one
|
||||
form_data = {
|
||||
'folder_0': ' Receipts', # IMAP returns with space, but gets stripped
|
||||
'folder_type_0': 'tidy', # Different type to test update
|
||||
'folder_1': ' Personal',
|
||||
'folder_type_1': 'destination'
|
||||
}
|
||||
|
||||
response = authenticated_client.post('/api/imap/sync-selected', data=form_data)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
# Check that we have exactly one more folder (the new one)
|
||||
final_folders = Folder.query.filter_by(user_id=mock_user.id).all()
|
||||
assert len(final_folders) == initial_count + 1
|
||||
|
||||
# Check that existing folder type was updated
|
||||
updated_folder = Folder.query.filter_by(user_id=mock_user.id, name='Receipts').first()
|
||||
assert updated_folder is not None
|
||||
assert updated_folder.folder_type == 'tidy'
|
||||
|
||||
# Check that new folder was created (name gets stripped)
|
||||
new_folder = Folder.query.filter_by(user_id=mock_user.id, name='Personal').first()
|
||||
assert new_folder is not None
|
||||
assert new_folder.folder_type == 'destination'
|
||||
|
||||
def test_imap_sync_selected_folders_special_folders_skipped(self, authenticated_client, mock_user):
|
||||
"""Test sync-selected skips special folders like sent, drafts, spam, trash"""
|
||||
# Set up IMAP config
|
||||
mock_user.imap_config = {'server': 'localhost', 'port': 5143, 'username': 'user1@example.com', 'password': 'password1', 'use_ssl': False}
|
||||
db.session.commit()
|
||||
|
||||
initial_count = Folder.query.filter_by(user_id=mock_user.id).count()
|
||||
|
||||
# Clean up any existing folders first
|
||||
Folder.query.filter_by(user_id=mock_user.id).delete()
|
||||
db.session.commit()
|
||||
|
||||
initial_count = Folder.query.filter_by(user_id=mock_user.id).count()
|
||||
|
||||
# Try to select special folders along with real folders
|
||||
form_data = {
|
||||
'folder_0': 'Sent',
|
||||
'folder_type_0': 'destination',
|
||||
'folder_1': 'Drafts',
|
||||
'folder_type_1': 'tidy',
|
||||
'folder_2': 'Spam',
|
||||
'folder_type_2': 'destination',
|
||||
'folder_3': 'Trash',
|
||||
'folder_type_3': 'tidy',
|
||||
'folder_4': ' Work',
|
||||
'folder_type_4': 'destination'
|
||||
}
|
||||
|
||||
response = authenticated_client.post('/api/imap/sync-selected', data=form_data)
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
# Check that only Work folder was created (special folders should be skipped)
|
||||
final_folders = Folder.query.filter_by(user_id=mock_user.id).all()
|
||||
assert len(final_folders) == initial_count + 1
|
||||
|
||||
# Check that Work folder exists (name gets stripped)
|
||||
work_folder = Folder.query.filter_by(user_id=mock_user.id, name='Work').first()
|
||||
assert work_folder is not None
|
||||
assert work_folder.folder_type == 'destination'
|
||||
|
||||
# Check that special folders don't exist
|
||||
special_folders = ['Sent', 'Drafts', 'Spam', 'Trash']
|
||||
for folder_name in special_folders:
|
||||
folder = Folder.query.filter_by(user_id=mock_user.id, name=folder_name).first()
|
||||
assert folder is None, f"Special folder {folder_name} should not have been created"
|
||||
|
||||
Reference in New Issue
Block a user