File size: 3,762 Bytes
ef987bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const path = require('path');
const { pathToFileURL } = require('url');
const { chromium } = require('playwright');
const inputText = input => input.evaluate(el => 'value' in el ? el.value : el.textContent || '');
(async () => {
  const browser = await chromium.launch({ headless: true });
  const page = await browser.newPage({ viewport: { width: 1000, height: 720 } });
  await page.goto(pathToFileURL(path.join(process.cwd(), 'index.html')).href, { waitUntil: 'domcontentloaded' });
  const area = page.locator('[data-testid="floating-prompt-area"]');
  const input = area.locator('input, textarea, [contenteditable="true"]');
  if (!(await area.isVisible())) throw new Error('floating prompt area must remain visible');
  if (!(await input.first().isVisible())) throw new Error('floating prompt area should contain the reusable input');
  const box = await area.evaluate(el => {
    const rect = el.getBoundingClientRect();
    const style = getComputedStyle(el);
    return { position: style.position, bottom: style.bottom, radius: style.borderRadius, top: rect.top, bottomEdge: rect.bottom, height: rect.height };
  });
  if (box.position !== 'fixed') throw new Error('floating area must retain fixed positioning');
  // Real on-screen check: the floating area must be fully within the viewport,
  // regardless of whether it is pinned to the top or the bottom. (Previously this
  // used an arbitrary `top > 600` cutoff that rejected a legitimately on-screen
  // bottom-pinned bar, contradicting the instruction to preserve the floating layout.)
  const viewportHeight = 720;
  if (!(box.bottomEdge <= viewportHeight + 1 && box.top >= -1 && box.bottomEdge > box.top)) {
    throw new Error('floating area is not fully visible in viewport');
  }
  await input.first().fill('pending prompt text');
  const value = await inputText(input.first());
  if (value !== 'pending prompt text') throw new Error('pending input should be editable');
  const areaText = ((await area.textContent()) || '').toLowerCase();
  if (areaText.includes('already sent') || areaText.includes('sent message')) {
    throw new Error('floating area should not render sent-message-only content');
  }
  const className = await area.getAttribute('class') || '';
  if (!/(rounded|square|radius|corner)/i.test(className) && !box.radius) {
    throw new Error('corner logic signal should remain on floating area');
  }

  // Chat send behavior: sending appends a new user bubble, clears the input,
  // and an empty input never appends.
  const userBubbles = page.locator('.chat-message.user, [data-testid="chat-message-user"]');
  const sendBtn = page.locator('[data-testid="send-button"], .floating-prompt-area button, .send-btn').first();
  if (!(await sendBtn.isVisible())) throw new Error('a send control should exist in the floating prompt area');
  const before = await userBubbles.count();

  await input.first().fill('hello world');
  await sendBtn.click();
  const after = await userBubbles.count();
  if (after !== before + 1) throw new Error('sending should append exactly one new user message bubble');
  const lastText = ((await userBubbles.last().textContent()) || '').trim();
  if (lastText !== 'hello world') throw new Error('the appended bubble should contain the sent text');
  if ((await inputText(input.first())) !== '') throw new Error('input should be cleared after sending');

  // Empty / whitespace-only input must not append anything.
  await input.first().fill('   ');
  await sendBtn.click();
  if ((await userBubbles.count()) !== after) throw new Error('empty input should not append a message');

  await browser.close();
})().catch(err => { console.error(err && err.stack || err); process.exit(1); });