Spaces:
Running on Zero
Running on Zero
Download tests/react-browser.mjs from ManasT2485/readloops: direct link, hf CLI and curl.
- Browser
- Download file 4.13 kB
-
https://huggingface.co/spaces/ManasT2485/readloops/resolve/main/tests/react-browser.mjs
- Command line
-
hf download hf://spaces/ManasT2485/readloops/tests/react-browser.mjs
-
curl -L -o react-browser.mjs https://huggingface.co/spaces/ManasT2485/readloops/resolve/main/tests/react-browser.mjs
4.13 kB
| import { createRequire } from 'node:module'; | |
| import { mkdir, writeFile } from 'node:fs/promises'; | |
| const { chromium, expect } = createRequire(new URL('../frontend/package.json', import.meta.url))('@playwright/test'); | |
| const browser = await chromium.launch({ headless: true }); | |
| const ctx = await browser.newContext({ viewport: { width: 1440, height: 1000 } }); | |
| const otherCtx = await browser.newContext({ viewport: { width: 1440, height: 1000 } }); | |
| const page = await ctx.newPage(); | |
| const other = await otherCtx.newPage(); | |
| const errors = []; | |
| page.on('pageerror', e => errors.push(e.message)); | |
| page.on('dialog', dialog => dialog.accept()); | |
| const app = page.frameLocator('#readloops-frame'); | |
| try { | |
| await mkdir('test-results/react', { recursive: true }); | |
| await page.goto('http://127.0.0.1:7860'); | |
| await expect(app.getByRole('heading', { name: 'Let’s read.' })).toBeVisible(); | |
| await expect(app.locator('.passage-choice')).toHaveCount(2); | |
| expect(await page.locator('#readloops-frame').boundingBox()).toEqual({ x: 0, y: 0, width: 1440, height: 1000 }); | |
| await app.locator('body').evaluate(() => document.fonts.ready); | |
| await page.screenshot({ path: 'test-results/react/desktop-home.png', fullPage: true }); | |
| for (const language of ['en', 'el']) { | |
| if (language === 'el') await app.getByRole('button', { name: /Ελληνικά/ }).click(); | |
| await expect(app.locator('.passage-choice')).toHaveCount(2); | |
| await app.locator('.passage-list').getByRole('button', { name: 'Read', exact: true }).first().click(); | |
| await expect(app.getByRole('button', { name: 'Continue without transcription' })).toBeVisible(); | |
| await page.screenshot({ path: `test-results/react/desktop-reading-${language}.png`, fullPage: true }); | |
| await app.getByRole('button', { name: 'Continue without transcription' }).click(); | |
| await app.locator('#transcript').fill(language === 'en' ? 'Typed demonstration only.' : 'Παράδειγμα κειμένου.'); | |
| await app.getByRole('button', { name: 'Compare words', exact: true }).click(); | |
| await app.getByRole('button', { name: 'Continue to exercise' }).click(); | |
| await app.getByRole('radio').first().check(); | |
| await app.getByRole('button', { name: 'Check answer' }).click(); | |
| await app.getByRole('button', { name: 'Finish session', exact: true }).click(); | |
| await expect(app.getByRole('heading', { name: 'Reading complete.' })).toBeVisible(); | |
| await app.getByRole('button', { name: 'Choose another passage' }).click(); | |
| } | |
| await page.reload(); | |
| await app.getByRole('button', { name: 'Progress', exact: true }).click(); | |
| await expect(app.getByRole('button', { name: 'View session', exact: true })).toHaveCount(1); | |
| await app.getByRole('button', { name: 'Experiments', exact: true }).click(); | |
| await expect(app.getByRole('heading', { name: 'Delayed reading outcomes' })).toBeVisible(); | |
| await other.goto('http://127.0.0.1:7860'); | |
| const otherApp = other.frameLocator('#readloops-frame'); | |
| await otherApp.getByRole('button', { name: 'Progress', exact: true }).click(); | |
| await expect(otherApp.getByRole('button', { name: 'View session', exact: true })).toHaveCount(0); | |
| expect(errors).toEqual([]); | |
| const geometry = await app.locator('.sidebar').evaluate(e => ({ width: e.getBoundingClientRect().width, | |
| font: getComputedStyle(e).fontFamily, brand: getComputedStyle(document.documentElement).getPropertyValue('--brand') })); | |
| expect(geometry.width).toBe(234); | |
| expect(geometry.font).toContain('Nunito Variable'); | |
| expect(geometry.brand.trim().toUpperCase()).toBe('#58CC02'); | |
| await writeFile('test-results/react/browser.json', JSON.stringify({ passed: true, geometry, checks: ['English session', 'Greek session', 'reload/resume', 'visitor isolation', 'experiment panel', 'original theme'] }, null, 2)); | |
| console.log('REACT_BROWSER_CHECKS_PASSED', JSON.stringify(geometry)); | |
| } catch (error) { | |
| await page.screenshot({ path: 'test-results/react/failure.png', fullPage: true }); | |
| await writeFile('test-results/react/failure.txt', await app.locator('body').innerText().catch(() => 'iframe unavailable')); | |
| throw error; | |
| } finally { await browser.close(); } | |