Files
wehub-resource-sync 7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

167 lines
6.1 KiB
JavaScript

/**
* Star Reviews Page UI Test
*
* Tests the star reviews analytics page to ensure proper loading, chart rendering,
* and data visualization. Validates API integration and user interface components.
*
* What this tests:
* - Star reviews page loading and navigation
* - API endpoint functionality (/metrics/api/star-reviews)
* - Chart.js rendering for bar charts and line charts
* - Period selector functionality
* - Overall statistics display
* - Rating distribution visualization
* - Recent ratings list population
*
* Prerequisites: Web server running on http://127.0.0.1:5000
*
* Usage: node tests/ui_tests/test_star_reviews.js
*/
const puppeteer = require('puppeteer');
const AuthHelper = require('./auth_helper');
const { getPuppeteerLaunchOptions } = require('./puppeteer_config');
async function testStarReviews() {
const browser = await puppeteer.launch(getPuppeteerLaunchOptions());
const page = await browser.newPage();
const baseUrl = 'http://127.0.0.1:5000';
const authHelper = new AuthHelper(page, baseUrl);
// Monitor console errors
page.on('console', msg => {
if (msg.type() === 'error') {
console.log('❌ BROWSER ERROR:', msg.text());
}
});
// Monitor network requests
await page.setRequestInterception(true);
page.on('request', request => {
if (request.url().includes('/star-reviews')) {
console.log('→ REQUEST:', request.method(), request.url());
}
request.continue();
});
page.on('response', response => {
if (response.url().includes('/star-reviews')) {
console.log('← RESPONSE:', response.status(), response.url());
}
});
let failed = false;
try {
console.log('🌟 Testing star reviews page...');
// Ensure authenticated before accessing metrics
await authHelper.ensureAuthenticatedWithTimeout();
// Start listening for the API response BEFORE navigation
// (the fetch fires on DOMContentLoaded, which may complete during goto)
const apiResponsePromise = page.waitForResponse(
r => r.url().includes('/metrics/api/star-reviews'),
{ timeout: 30000 }
);
// Navigate directly to star reviews page
await page.goto('http://127.0.0.1:5000/metrics/star-reviews', {
waitUntil: 'domcontentloaded',
timeout: 30000
});
console.log('📊 Checking star reviews page elements...');
// Wait for the star-reviews API call to complete
await apiResponsePromise;
// Check for main page elements
const pageElements = await page.evaluate(() => {
return {
title: !!document.querySelector('h1'),
periodSelector: !!document.querySelector('#period-select'),
overallStats: !!document.querySelector('.overall-stats'),
avgRating: !!document.querySelector('#avg-rating'),
totalRatings: !!document.querySelector('#total-ratings'),
ratingDistribution: !!document.querySelector('.rating-distribution'),
llmChart: !!document.querySelector('#llm-ratings-chart'),
searchEngineChart: !!document.querySelector('#search-engine-ratings-chart'),
trendsChart: !!document.querySelector('#rating-trends-chart'),
recentRatings: !!document.querySelector('#recent-ratings'),
backLink: !!document.querySelector('a[href="/metrics/"]')
};
});
console.log('📋 Page Elements Check:');
Object.entries(pageElements).forEach(([element, exists]) => {
console.log(` ${exists ? '✅' : '❌'} ${element}: ${exists}`);
});
// Test period selector
console.log('🕐 Testing period selector...');
const periodSelect = await page.$('#period-select');
if (periodSelect) {
// Start listening for reload response BEFORE triggering it
const reloadResponsePromise = page.waitForResponse(
r => r.url().includes('/metrics/api/star-reviews'),
{ timeout: 15000 }
);
// Change to "7d" period
await page.select('#period-select', '7d');
console.log('✅ Period selector changed to 7 days');
// Wait for the reload API call to complete
await reloadResponsePromise;
}
// Wait for Chart.js to be available (may not load in CI with no data)
try {
await page.waitForFunction(() => typeof window.Chart !== 'undefined', { timeout: 10000 });
} catch {
console.log('⚠️ Chart.js not loaded (may not have data in CI)');
}
// Check if charts are rendered (Canvas elements)
const chartStatus = await page.evaluate(() => {
const llmChart = document.getElementById('llm-ratings-chart');
const searchChart = document.getElementById('search-engine-ratings-chart');
const trendsChart = document.getElementById('rating-trends-chart');
return {
llmChartRendered: llmChart && llmChart.tagName === 'CANVAS',
searchChartRendered: searchChart && searchChart.tagName === 'CANVAS',
trendsChartRendered: trendsChart && trendsChart.tagName === 'CANVAS'
};
});
console.log('📊 Chart Rendering Check:');
Object.entries(chartStatus).forEach(([chart, rendered]) => {
console.log(` ${rendered ? '✅' : '❌'} ${chart}: ${rendered}`);
});
// Test back navigation
console.log('🔙 Testing back navigation...');
const backLink = await page.$('a[href="/metrics/"]');
if (backLink) {
console.log('✅ Back link found and functional');
}
console.log('🎉 Star reviews page test completed successfully!');
} catch (error) {
console.error('❌ Test error:', error);
failed = true;
} finally {
await browser.close();
process.exit(failed ? 1 : 0);
}
}
testStarReviews().catch(err => {
console.error('❌ Unhandled error:', err);
process.exit(1);
});