// Actual application/router/forms, simulated APIs, no real authentication.
|
const assert=require('node:assert/strict');
|
const {chromium}=require('C:/Users/云/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/playwright');
|
const fs=require('fs'),path=require('path');
|
const output=path.resolve(__dirname,'../../scripts/login-theme-20261015');fs.mkdirSync(output,{recursive:true});
|
(async()=>{
|
const server=await(await import('vite')).createServer({root:path.resolve(__dirname,'..'),server:{host:'127.0.0.1',port:5182}});await server.listen();
|
const browser=await chromium.launch({headless:true,executablePath:'C:/Program Files/Google/Chrome/Application/chrome.exe'});
|
const page=await browser.newPage({viewport:{width:1664,height:941},reducedMotion:'reduce'});
|
const errors=[];let authPosts=0;page.on('pageerror',e=>errors.push(e.message));
|
await page.route('**/admin-api/**',async route=>{
|
const url=route.request().url();if(route.request().method()==='POST')authPosts++;
|
const data=url.includes('company-config')?{companyName:'滋补品管理平台',loginTitle:'滋补品行业数字化管理平台',loginDescription:'传承中医药精华 · 服务健康美好生活'}:url.includes('tenant')?[]:null;
|
await route.fulfill({contentType:'application/json',body:JSON.stringify({code:0,data,msg:''})});
|
});
|
try {
|
await page.goto('http://127.0.0.1:5182/auth/login',{waitUntil:'domcontentloaded',timeout:60000});
|
await page.getByRole('heading',{name:'欢迎回来'}).waitFor({timeout:60000});
|
await page.waitForFunction(()=>!document.querySelector('#__app-loading__')||getComputedStyle(document.querySelector('#__app-loading__')).opacity==='0');
|
await page.waitForFunction(()=>document.querySelector('.herbal-auth__background')?.complete);
|
const user=page.getByRole('textbox',{name:'账号',exact:true}),password=page.locator('input[autocomplete="current-password"]');
|
await user.fill('演示账户');await password.fill('not-a-real-password');await page.locator('.herbal-login__heading').click();await page.waitForTimeout(400);
|
assert.equal(await user.getAttribute('autocomplete'),'username');assert.equal(await password.getAttribute('type'),'password');
|
await page.getByRole('button',{name:'显示密码',exact:true}).focus();await page.keyboard.press('Space');assert.equal(await password.getAttribute('type'),'text');
|
assert.equal(await password.evaluate(e=>getComputedStyle(e).paddingRight),'44px');
|
await page.getByRole('button',{name:'隐藏密码',exact:true}).click();assert.equal(await password.getAttribute('type'),'password');
|
const remember=page.locator('button[role="checkbox"]').first();await remember.click();assert.equal(await remember.getAttribute('aria-checked'),'true');
|
await page.screenshot({path:path.join(output,'desktop-login.png'),fullPage:true});
|
const tokens=await page.evaluate(()=>{const s=getComputedStyle(document.documentElement);return{brand:document.documentElement.dataset.brandTheme,primary:s.getPropertyValue('--primary').trim(),background:s.getPropertyValue('--background-deep').trim()}});
|
assert.equal(tokens.brand,'herbal');assert.equal(tokens.background,'37 33% 95%');
|
await page.locator('.herbal-auth__toolbar button').last().click();await page.waitForFunction(()=>document.documentElement.classList.contains('dark'));await page.waitForTimeout(350);
|
assert.equal(await page.evaluate(()=>getComputedStyle(document.documentElement).getPropertyValue('--primary').trim()),'357 64% 73%');
|
assert.equal(await page.locator('.herbal-panel').evaluate(e=>getComputedStyle(e).backgroundColor),'rgba(39, 31, 26, 0.97)');
|
assert.equal(await page.locator('.herbal-auth__toolbar >div').evaluate(e=>getComputedStyle(e).backgroundColor),'rgb(48, 39, 31)');
|
assert.equal(await page.evaluate(()=>getComputedStyle(document.documentElement).filter),'none','Dark styles must not apply a filter to the document');
|
await page.screenshot({path:path.join(output,'desktop-dark.png'),fullPage:true});
|
await page.locator('.herbal-auth__toolbar button').last().click();await page.waitForFunction(()=>!document.documentElement.classList.contains('dark'));
|
await page.setViewportSize({width:390,height:844});await page.waitForTimeout(250);
|
assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth<=innerWidth),true);
|
await page.screenshot({path:path.join(output,'mobile-login.png'),fullPage:true});
|
await user.fill('');await password.fill('');await page.getByRole('button',{name:'login',exact:true}).click();
|
await page.getByText('请输入用户名',{exact:true}).first().waitFor();assert.equal(authPosts,0);
|
assert.deepEqual(errors,[]);
|
const result={passed:true,scope:'Real application/router/theme/login components; mocked backend and company APIs, demo account, no real authentication',checks:['dynamic company config','background loaded','autocomplete','keyboard password toggle','remember account','light theme variables','dark theme switching','mobile no overflow','required fields block backend'],tokens,screenshots:['desktop-login.png','desktop-dark.png','mobile-login.png']};
|
fs.writeFileSync(path.join(output,'result.json'),JSON.stringify(result,null,2));console.log(JSON.stringify(result));
|
} catch(error){console.error(JSON.stringify({message:error.message,errors}));throw error;}
|
finally{await browser.close();await server.close();}
|
})();
|