forked from Ark0N/Codeman
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest-session-indicator.mjs
More file actions
127 lines (109 loc) · 4.52 KB
/
Copy pathtest-session-indicator.mjs
File metadata and controls
127 lines (109 loc) · 4.52 KB
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
import { chromium } from 'playwright';
const BASE = 'http://localhost:3002';
async function run() {
const browser = await chromium.launch({ headless: true });
const context = await browser.newContext({ viewport: { width: 1280, height: 800 } });
const page = await context.newPage();
const results = [];
function pass(name) { results.push({ name, status: 'PASS' }); console.log(`PASS: ${name}`); }
function fail(name, err) { results.push({ name, status: 'FAIL', error: String(err) }); console.log(`FAIL: ${name} — ${err}`); }
try {
// Check if sessions exist via API
const sessionsRes = await fetch(`${BASE}/api/sessions`);
const sessions = await sessionsRes.json();
const hasSessions = Array.isArray(sessions) && sessions.length > 0;
console.log(`Sessions found: ${hasSessions ? sessions.length : 0}`);
// Load the page
await page.goto(BASE, { waitUntil: 'domcontentloaded' });
await page.waitForTimeout(4000);
// 1. Check #sessionIndicatorBar exists in DOM
const bar = await page.$('#sessionIndicatorBar');
if (bar) {
pass('#sessionIndicatorBar exists in DOM');
} else {
fail('#sessionIndicatorBar exists in DOM', 'Element not found');
await browser.close();
process.exit(1);
}
// 2. Check visibility based on sessions
const display = await page.locator('#sessionIndicatorBar').evaluate(el => getComputedStyle(el).display);
if (hasSessions) {
if (display === 'flex') {
pass('Bar visible (display:flex) when sessions exist');
} else {
fail('Bar visible (display:flex) when sessions exist', `display is "${display}"`);
}
} else {
if (display === 'none') {
pass('Bar hidden (display:none) when no sessions');
} else {
fail('Bar hidden (display:none) when no sessions', `display is "${display}"`);
}
}
// 3. Check CSS properties: height <= 28px on desktop
const height = await page.locator('#sessionIndicatorBar').evaluate(el => {
return parseFloat(getComputedStyle(el).height);
});
if (height <= 28) {
pass(`Height is ${height}px (<=28px on desktop)`);
} else {
fail(`Height <= 28px on desktop`, `Height is ${height}px`);
}
// 4. Check font-size is 0.75rem / 12px
const fontSize = await page.locator('#sessionIndicatorBar').evaluate(el => {
return getComputedStyle(el).fontSize;
});
if (fontSize === '12px' || fontSize === '0.75rem') {
pass(`Font-size is ${fontSize}`);
} else {
fail('Font-size is 0.75rem / 12px', `Font-size is "${fontSize}"`);
}
// 5. Check child elements exist
const childSelectors = ['.sib-status-dot', '.sib-session-name', '.sib-sep', '.sib-project'];
for (const sel of childSelectors) {
const count = await page.locator(`#sessionIndicatorBar ${sel}`).count();
if (count > 0) {
pass(`Child element ${sel} exists`);
} else {
fail(`Child element ${sel} exists`, 'Not found');
}
}
// 6. If bar is visible, check that session name has content
if (display === 'flex') {
const sessionName = await page.locator('#sibSessionName').textContent();
if (sessionName && sessionName.trim().length > 0) {
pass(`Session name has content: "${sessionName.trim()}"`);
} else {
fail('Session name has content', 'Text is empty');
}
const project = await page.locator('#sibProject').textContent();
if (project && project.trim().length > 0) {
pass(`Project has content: "${project.trim()}"`);
} else {
fail('Project has content', 'Text is empty');
}
// Check status dot has a class (idle or busy)
const dotClasses = await page.locator('#sibStatusDot').getAttribute('class');
if (dotClasses && (dotClasses.includes('idle') || dotClasses.includes('busy'))) {
pass(`Status dot has state class: "${dotClasses}"`);
} else {
fail('Status dot has idle/busy class', `Classes: "${dotClasses}"`);
}
}
} catch (e) {
fail('Unexpected error', e.message);
}
await browser.close();
// Summary
console.log('\n=== SUMMARY ===');
const passed = results.filter(r => r.status === 'PASS').length;
const failed = results.filter(r => r.status === 'FAIL').length;
console.log(`${passed} passed, ${failed} failed out of ${results.length} checks`);
if (failed > 0) {
console.log('\nFailed checks:');
results.filter(r => r.status === 'FAIL').forEach(r => console.log(` - ${r.name}: ${r.error}`));
process.exit(1);
}
process.exit(0);
}
run();