17 lines
1.9 KiB
JavaScript
17 lines
1.9 KiB
JavaScript
/* Widget authorization and selection states; intercepted Mock responses only. */
|
|
const assert=require('assert'),{chromium}=require('playwright');
|
|
(async()=>{
|
|
const browser=await chromium.launch({headless:true,executablePath:'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'});
|
|
const page=await browser.newPage();const errors=[];page.on('pageerror',e=>errors.push(e.message));let status='AUTH_REQUIRED',checks=0;
|
|
await page.route('**/api/v1/devices/*/widgets',route=>route.fulfill({json:{source:status==='AUTH_REQUIRED'?'snapshot':'live',configured:status!=='AUTH_REQUIRED',status,observed_at:'2026-10-02',catalog:[],current:null,current_verified:status==='NO_WIDGET',writable:false}}));
|
|
await page.goto(process.env.FRAME_FLOW_URL||'http://127.0.0.1:6005');await page.locator('#username').fill(process.env.FRAME_FLOW_TEST_USERNAME);await page.locator('#password').fill(process.env.FRAME_FLOW_TEST_PASSWORD);await page.locator('#login-form button').click();await page.locator('.hero').waitFor();
|
|
for(const lang of ['zh','en'])for(const value of ['AUTH_REQUIRED','NO_WIDGET','CURRENT_UNVERIFIED']){
|
|
status=value;await page.evaluate(lang=>{state.lang=lang;return navigate('templates');},lang);
|
|
await page.locator('.widget-auth-notice').waitFor({state:'attached'});
|
|
const text=await page.locator('.official-content-info').textContent();
|
|
assert(text.includes(lang==='zh'?'现有 API Key 接入继续':'Your existing API Key continues'));
|
|
assert(text.includes(lang==='zh'?{AUTH_REQUIRED:'尚未授权官方账号',NO_WIDGET:'未使用官方小组件',CURRENT_UNVERIFIED:'当前小组件尚未核实'}[value]:{AUTH_REQUIRED:'Official account not authorized',NO_WIDGET:'No official widget selected',CURRENT_UNVERIFIED:'Current widget is unverified'}[value]));checks++;
|
|
}
|
|
assert(errors.length===0);await browser.close();console.log(`Widget UI: ${checks} states passed; 0 page errors`);
|
|
})().catch(e=>{console.error(e.message);process.exit(1)});
|