File size: 6,064 Bytes
144940a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/**
 * Visual Test Script for AutoSite Application
 * 
 * This script provides functions to visually test the AutoSite application,
 * particularly focusing on the AskAI component and its integration with the UI.
 */

// Test data for AI prompts
const TEST_PROMPTS = [
  "Create a simple landing page with a header, hero section, and footer",
  "Add a contact form to the page",
  "Change the background color to light blue",
  "Add a navigation menu with Home, About, and Contact links"
];

// Helper function to wait for a specified time
function wait(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

// Test the AskAI component's UI elements
async function testAskAIUI() {
  console.log('Testing AskAI UI elements...');
  
  // Test input field
  const inputField = document.querySelector('.group input[type="text"]');
  if (!inputField) {
    console.error('Input field not found');
    return false;
  }
  
  // Test send button
  const sendButton = document.querySelector('.group button');
  if (!sendButton) {
    console.error('Send button not found');
    return false;
  }
  
  // Test placeholder text
  console.log('Initial placeholder:', inputField.placeholder);
  
  console.log('AskAI UI elements test passed');
  return true;
}

// Test the progress indicator
async function testProgressIndicator() {
  console.log('Testing progress indicator...');
  
  // Submit a prompt to trigger the progress indicator
  const inputField = document.querySelector('.group input[type="text"]');
  const sendButton = document.querySelector('.group button');
  
  if (!inputField || !sendButton) {
    console.error('Input field or send button not found');
    return false;
  }
  
  // Enter a test prompt
  inputField.value = TEST_PROMPTS[0];
  
  // Click the send button
  sendButton.click();
  
  // Wait for the progress indicator to appear
  await wait(1000);
  
  // Check if progress indicator is visible
  const progressBar = document.querySelector('.bg-gradient-to-r');
  if (!progressBar) {
    console.error('Progress indicator not found after submitting prompt');
    return false;
  }
  
  console.log('Progress indicator test passed');
  return true;
}

// Test the response mode indicator
async function testResponseModeIndicator() {
  console.log('Testing response mode indicator...');
  
  // Wait for the response mode indicator to appear
  await wait(2000);
  
  // Check if response mode indicator is visible
  const modeIndicator = document.querySelector('.bg-gray-800\/90');
  if (!modeIndicator) {
    console.warn('Response mode indicator not found - this may be normal for first request');
    return true;
  }
  
  // Check the text content to verify mode
  const modeText = modeIndicator.textContent.trim();
  console.log('Response mode:', modeText);
  
  console.log('Response mode indicator test passed');
  return true;
}

// Test the preview panel updates
async function testPreviewUpdates() {
  console.log('Testing preview panel updates...');
  
  // Get the preview iframe
  const previewFrame = document.querySelector('iframe');
  if (!previewFrame) {
    console.error('Preview iframe not found');
    return false;
  }
  
  // Store initial content for comparison
  const initialContent = previewFrame.srcdoc;
  
  // Wait for content to update (this may take some time depending on AI response)
  await wait(10000);
  
  // Check if content has changed
  const updatedContent = previewFrame.srcdoc;
  if (initialContent === updatedContent) {
    console.warn('Preview content did not update - this may indicate an issue');
    return false;
  }
  
  console.log('Preview updates test passed');
  return true;
}

// Test the success animation
async function testSuccessAnimation() {
  console.log('Testing success animation...');
  
  // Wait for AI processing to complete
  await wait(15000);
  
  // Check if success class was added to body
  if (document.body.classList.contains('ai-success')) {
    console.log('Success animation detected');
    return true;
  }
  
  // It's possible the animation already completed and class was removed
  console.warn('Success animation not detected - may have already completed');
  return true;
}

// Test responsive design
async function testResponsiveDesign() {
  console.log('Testing responsive design...');
  
  // Store original window dimensions
  const originalWidth = window.innerWidth;
  const originalHeight = window.innerHeight;
  
  // Test mobile layout
  console.log('Testing mobile layout...');
  window.resizeTo(375, 667); // iPhone 8 dimensions
  await wait(1000);
  
  // Check if layout has adjusted
  const editorMobile = document.querySelector('.w-full.h-\\[30dvh\\]');
  if (!editorMobile) {
    console.warn('Mobile layout may not be applied correctly');
  }
  
  // Test tablet layout
  console.log('Testing tablet layout...');
  window.resizeTo(768, 1024); // iPad dimensions
  await wait(1000);
  
  // Test desktop layout
  console.log('Testing desktop layout...');
  window.resizeTo(1440, 900); // Common desktop dimensions
  await wait(1000);
  
  // Restore original dimensions
  window.resizeTo(originalWidth, originalHeight);
  
  console.log('Responsive design test completed');
  return true;
}

// Run all tests
async function runAllTests() {
  console.log('Starting visual tests for AutoSite application...');
  
  const results = {
    uiElements: await testAskAIUI(),
    progressIndicator: await testProgressIndicator(),
    responseModeIndicator: await testResponseModeIndicator(),
    previewUpdates: await testPreviewUpdates(),
    successAnimation: await testSuccessAnimation(),
    responsiveDesign: await testResponsiveDesign()
  };
  
  console.log('Test results:', results);
  console.log('Tests completed:', Object.values(results).filter(Boolean).length, 'of', Object.values(results).length, 'passed');
  
  return results;
}

// Execute tests when run in browser console
if (typeof window !== 'undefined') {
  console.log('AutoSite Visual Test Script loaded');
  console.log('Run tests by calling: runAllTests()');
}