测试文件

测试用例

适配设备:RW

作者:dengyuhang

下载量:11 · 点赞:1

可信源码风险提示:保存或下载前请阅读源码和权限声明。
SHA-25686d20533c89c137f7627a3e52c40ae7b5118bfac62f4faefbbc6334e6a44f160
let count = 0;

async function main() {
  // 1. 读取本地存储,测试持久化能力
  let savedCount = await script.data.get('testCount', 0);
  count = savedCount;

  drawUI();
}

function drawUI() {
  ui.render([
    ui.spacer(10),
    ui.heading('环境测试', { align: 'center' }),
    
    // 2. 状态显示区
    ui.column([
      ui.text('当前计数:', { align: 'center', color: '#888888', size: 16 }),
      ui.text(count.toString(), { align: 'center', size: 40, bold: true, color: '#1a8f38' })
    ], { background: '#111111', radius: 8, height: 90, justify: 'center' }),
    
    ui.spacer(10),

    // 3. 交互与存储测试
    ui.row([
      ui.button("增加并保存", async () => {
        count++;
        await script.data.set('testCount', count); // 测试异步存储
        script.toast("已保存到本地!");
        drawUI(); // 刷新界面
      }, { flex: 1, tone: 'primary', height: 52 }),
      
      ui.button("清零", async () => {
        count = 0;
        await script.data.set('testCount', 0);
        drawUI();
      }, { flex: 1, tone: 'neutral', height: 52 })
    ], { gap: 10 }),

    ui.spacer(10),

    // 4. 对话框 (dialog) 测试
    ui.button("测试弹窗", async () => {
      const res = await dialog.confirm({ 
        title: '测试确认', 
        message: '你能看到并点击这个弹窗吗?',
        confirmText: '可以',
        cancelText: '取消'
      });
      if (res.action === 'confirm') {
        script.toast("弹窗交互正常!");
      } else {
        script.toast("你取消了弹窗");
      }
    }, { tone: 'neutral', height: 52 }),

    // 5. 定时器 (setTimeout) 与防重启测试
    ui.button("测试延迟(3秒后)", () => {
      script.toast("3秒后更新文字...");
      setTimeout(() => {
        count += 10;
        script.data.set('testCount', count);
        drawUI();
        script.toast("定时器执行成功!");
      }, 3000);
    }, { tone: 'warning', height: 52 }),

    // 6. 列表滚动测试
    ui.spacer(10),
    ui.text('滑动测试区:', { color: '#888888' }),
    ...Array(10).fill(0).map((_, i) => 
      ui.text(`这是第 ${i + 1} 行测试文本,尝试上下滑动查看。`, { lines: 1 })
    )
  ]);
}

// 运行器入口
return main();