Freeze experimental social/admin UX on test12 for reference only; see docs/archive/test12-NEVER-DEPLOY.md. Co-authored-by: Cursor <cursoragent@cursor.com>
124 lines
7.3 KiB
Python
124 lines
7.3 KiB
Python
"""Focused discovery regression. Run with the portal on localhost:3000.
|
|
|
|
Uses mocked discovery data; does not publish profiles or send messages.
|
|
"""
|
|
import asyncio
|
|
import json
|
|
import os
|
|
import sys
|
|
sys.stdout.reconfigure(encoding="utf-8")
|
|
from pathlib import Path
|
|
from playwright.async_api import async_playwright, expect
|
|
|
|
BASE = os.environ.get('SOCIAL_BASE_URL', 'http://localhost:3000')
|
|
OUTPUT = Path('artifacts/social-discovery')
|
|
|
|
|
|
async def main():
|
|
OUTPUT.mkdir(parents=True, exist_ok=True)
|
|
async with async_playwright() as p:
|
|
browser = await p.chromium.launch()
|
|
context = await browser.new_context(locale='en-US', timezone_id='America/New_York', reduced_motion='reduce')
|
|
# The Windows host has Chinese fonts installed. Make font-based audience
|
|
# detection deterministic for this international-browser scenario only.
|
|
await context.add_init_script('''
|
|
const measure = CanvasRenderingContext2D.prototype.measureText;
|
|
CanvasRenderingContext2D.prototype.measureText = function(text) {
|
|
if (text === 'mmmmmmmmmmlli中文测试') return { width: 100 };
|
|
return measure.call(this, text);
|
|
};
|
|
''')
|
|
await context.route('**/favicon.ico?*', lambda route: route.abort())
|
|
async def mock(route):
|
|
if '/roster/discovery' in route.request.url:
|
|
await route.fulfill(json={'items': [
|
|
{'guestId': 'test-here', 'name': 'Here Offline', 'city': 'Test City', 'status': 'here', 'online': False, 'tags': ['Testing'], 'faceOk': True, 'avatar': 'https://i.pravatar.cc/100?u=test', 'languages': ['English']},
|
|
{'guestId': 'test-soon', 'name': 'Soon Online', 'city': 'Test City', 'status': 'arriving', 'online': True, 'tags': ['Testing'], 'faceOk': True, 'avatar': 'https://i.pravatar.cc/100?u=test', 'languages': ['English']},
|
|
]})
|
|
elif '/realtime/' in route.request.url:
|
|
await route.fulfill(json={'enabled': False})
|
|
else:
|
|
await route.fulfill(json={'items': []})
|
|
await context.route('**/api/social/v1/**', mock)
|
|
page = await context.new_page()
|
|
errors = []
|
|
page.on('pageerror', lambda error: errors.append(str(error)))
|
|
async def go(path):
|
|
response = await page.goto(BASE + '/social' + path)
|
|
assert response.status == 200
|
|
await expect(page.locator('.people-connection-card').first).to_be_visible()
|
|
|
|
await go('/people')
|
|
cards = page.locator('.people-connection-card')
|
|
await expect(cards.filter(has_text='Here Offline')).to_have_count(1)
|
|
card = cards.filter(has_text='Here Offline')
|
|
await card.get_by_role('button', name='Follow Here Offline', exact=True).click()
|
|
await expect(card.get_by_role('button', name='Unfollow Here Offline')).to_have_attribute('aria-pressed', 'true')
|
|
await page.locator('.social-filters button').last.click()
|
|
await expect(cards).to_have_count(1)
|
|
await page.reload()
|
|
await page.wait_for_timeout(1500)
|
|
print('RELOAD',page.url,await page.evaluate("localStorage.getItem('nomadro-social:social-roster-likes')"),errors,await page.locator('.people-results-bar').inner_text(),flush=True)
|
|
await expect(cards).to_have_count(1, timeout=15000)
|
|
await cards.get_by_role('button', name='Unfollow Here Offline').click()
|
|
await expect(cards).to_have_count(0)
|
|
await expect(page.get_by_role('button', name='Explore everyone')).to_be_visible()
|
|
await page.get_by_role('button', name='Explore everyone').click()
|
|
# City and the existing text query can be combined without overwriting one another.
|
|
await page.locator('.people-toolbar-top select').select_option('Test City')
|
|
await page.get_by_role('searchbox').fill('Offline')
|
|
await expect(cards).to_have_count(1)
|
|
await page.get_by_role('button', name='Remove Test City').click()
|
|
await expect(page.get_by_role('searchbox')).to_have_value('Offline')
|
|
await page.get_by_role('button', name='Clear search').click()
|
|
await page.get_by_role('button', name='Refine', exact=True).click()
|
|
await page.locator('#people-refinements select').last.select_option('here')
|
|
await expect(cards).to_have_count(1)
|
|
await expect(cards).to_contain_text('Here Offline')
|
|
await page.locator('#people-refinements select').last.select_option('soon')
|
|
await expect(cards).to_have_count(1)
|
|
await expect(cards).to_contain_text('Soon Online')
|
|
await page.get_by_role('button', name='Reset filters').click()
|
|
await page.get_by_role('button', name='Testing', exact=True).first.click()
|
|
await expect(cards).to_have_count(2)
|
|
await page.get_by_role('button', name='Remove Testing').click()
|
|
await page.locator('.people-results-bar select').select_option('name')
|
|
names = await cards.locator('h2').all_text_contents()
|
|
assert names.index('Here Offline') < names.index('Soon Online')
|
|
layouts = []
|
|
for width in [320, 390, 768, 1440]:
|
|
await page.set_viewport_size({'width': width, 'height': 900})
|
|
await page.screenshot(path=str(OUTPUT / f'people-{width}.png'), full_page=True)
|
|
overflow = await page.evaluate('document.documentElement.scrollWidth - innerWidth')
|
|
assert overflow <= 1, (width, overflow)
|
|
layouts.append({'page': 'people', 'width': width, 'overflow': overflow})
|
|
await page.goto(BASE + '/social')
|
|
await page.get_by_role('button', name='Coffee & conversation', exact=True).click()
|
|
await expect(page.locator('#social-intent-panel > .intent-panel-actions > a').first).to_have_attribute('href', '/social/coffeechat')
|
|
await page.locator('.intent-options').get_by_role('button', name='Build together', exact=True).click()
|
|
await expect(page.locator('#social-intent-panel > .intent-panel-actions > a').first).to_have_attribute('href', '/social/skills')
|
|
for width in [320, 390, 768, 1440]:
|
|
await page.set_viewport_size({'width': width, 'height': 900})
|
|
await page.locator('.social-intent-guide').scroll_into_view_if_needed()
|
|
await page.screenshot(path=str(OUTPUT / f'home-{width}.png'))
|
|
overflow = await page.evaluate('document.documentElement.scrollWidth - innerWidth')
|
|
assert overflow <= 1, (width, overflow)
|
|
layouts.append({'page': 'home', 'width': width, 'overflow': overflow})
|
|
await context.close()
|
|
zh = await browser.new_context(locale='zh-CN', timezone_id='Asia/Shanghai', viewport={'width': 390, 'height': 844})
|
|
await zh.route('**/api/social/v1/**', mock)
|
|
page = await zh.new_page()
|
|
page.on('pageerror', lambda error: errors.append(str(error)))
|
|
await go('/people')
|
|
await expect(page.get_by_role('button', name='更多筛选', exact=True)).to_be_visible()
|
|
assert '???' not in await page.locator('.people-toolbar').inner_text()
|
|
await page.screenshot(path=str(OUTPUT / 'people-zh.png'))
|
|
assert not errors, errors
|
|
report = {'interactions': 'passed', 'locales': ['en', 'zh'], 'layouts': layouts, 'pageErrors': errors}
|
|
(OUTPUT / 'report.json').write_text(json.dumps(report, indent=2), encoding='utf-8')
|
|
print(json.dumps(report))
|
|
await browser.close()
|
|
|
|
|
|
asyncio.run(main())
|