148 lines
7.6 KiB
JavaScript
148 lines
7.6 KiB
JavaScript
const test = require('node:test');
|
||
const assert = require('node:assert/strict');
|
||
const fs = require('node:fs');
|
||
const path = require('node:path');
|
||
const vm = require('node:vm');
|
||
const source = fs.readFileSync(path.join(__dirname, '../hongguo-daily.auto.js'), 'utf8');
|
||
function load() {
|
||
const c = vm.createContext({Date, Math, JSON, Error, isFinite});
|
||
vm.runInContext(source.slice(0, source.lastIndexOf('\ntry {\n var endMessage')), c);
|
||
c.device = {width: 1080, height: 2374};
|
||
c.logs = [];
|
||
c.writeRunLog = text => c.logs.push(text);
|
||
c.sleep = () => {};
|
||
return c;
|
||
}
|
||
const item = (text, left, top, right = left + 180, bottom = top + 45) => ({text, rect: {left, top, right, bottom}});
|
||
const singlePopup = () => [item('今日签到领100金币', 250, 600),
|
||
{...item('立即领取', 400, 1400), darkButton: true}, item('X', 520, 1750, 560)];
|
||
|
||
test('实际OPPO福利文字样本按签到标签匹配本行去签到,不依赖日常福利标题', () => {
|
||
const c = load();
|
||
const frames = fs.readFileSync(path.join(__dirname, '../debug/2026-10-21/oppo-hongguo10-slow-inspect.jsonl'), 'utf8')
|
||
.trim().split('\n').map(line => JSON.parse(line));
|
||
const page = frames.find(frame => frame.some(i => i.text === '去签到'));
|
||
assert.ok(page);
|
||
c.snapshot = () => page.filter(i => i.text !== '日常福利');
|
||
c.swipe = () => {throw Error('可见入口不应继续滑动');};
|
||
assert.equal(c.searchEarningTask(c.SIGN_ENTRY, /^[||]?(?:去签到|立即签到|签到)$/, '签到').text, '去签到');
|
||
});
|
||
|
||
test('单按钮签到按番茄规则领取唯一深色按钮,通用处理不能先关闭它', () => {
|
||
const c = load();
|
||
const popup = singlePopup();
|
||
assert.equal(c.needsCommonHandling(popup), true);
|
||
assert.equal(c.singleButtonPopupDecision(popup).signIn, true);
|
||
let taps = [];
|
||
c.snapshot = () => taps.length ? [item('日常福利', 80, 400)] : popup;
|
||
c.tap = button => {taps.push(button.text); c.actionSerial++;};
|
||
c.handleVideosLoop(null, 0);
|
||
assert.deepEqual(taps, ['立即领取']);
|
||
});
|
||
|
||
for (const [left, right, expected] of [[2868, 4868, 4868], [100, 400, 100]]) {
|
||
test(`签到双金额 ${left}/${right} 按通用阈值选择 ${expected}`, () => {
|
||
const c = load();
|
||
const popup = [item('今日签到', 250, 600),
|
||
{...item(`领${left}金币`, 160, 1400), darkButton: true},
|
||
{...item(`领${right}金币`, 600, 1400), darkButton: true}, item('X', 520, 1750, 560)];
|
||
assert.equal(c.findSingleSignPopupClaim(popup), null);
|
||
assert.equal(c.findCoinChoiceClaim(popup).text, `领${expected}金币`);
|
||
});
|
||
}
|
||
|
||
test('签到任务背景及无深色按钮证据不能触发单按钮签到领取', () => {
|
||
const c = load();
|
||
assert.equal(c.findSingleSignPopupClaim([item('签到领金币8828', 203, 900), item('去签到', 828, 920)]), null);
|
||
const popup = singlePopup();
|
||
popup[1].darkButton = false;
|
||
assert.equal(c.findSingleSignPopupClaim(popup), null);
|
||
});
|
||
|
||
test('独立签到活动页无X时仍识别深色领取,合并原生与OCR按钮', () => {
|
||
const c = load();
|
||
const native = {...item('立即领取', 183, 1839, 896, 1972), darkButton: false};
|
||
const ocr = {...item('立即领取', 450, 1882, 630, 1925), darkButton: true};
|
||
const page = [item('已签0/7今日签到,额外奖励立即到账+7125', 82, 1674, 997, 1789),
|
||
item('活动时间:10月20日-11月18日', 262, 356), item('back', 64, 194, 86, 230), native, ocr];
|
||
assert.equal(c.singleButtonPopupDecision(page).button, native);
|
||
assert.equal(c.singleButtonPopupDecision(page).signIn, true);
|
||
});
|
||
|
||
test('独立签到页处理后返回福利,再交给吃饭补贴', () => {
|
||
const c = load();
|
||
const backButton = item('back', 64, 194, 86, 230);
|
||
c.snapshot = () => [backButton, item('今日签到', 250, 600), item('活动时间', 250, 356)];
|
||
let returned = false;
|
||
c.tap = button => {assert.equal(button, backButton); returned = true;};
|
||
c.waitForWelfare = () => returned;
|
||
c.returnFromSignPage();
|
||
assert.equal(returned, true);
|
||
});
|
||
|
||
test('真实签到完成浮层忽略X下方背景任务金币,关闭后才能进入吃饭补贴', () => {
|
||
const c = load();
|
||
const page = JSON.parse(fs.readFileSync(path.join(__dirname, '../debug/2026-10-21/oppo-hongguo11-after-signin.json'), 'utf8'));
|
||
const close = page.find(i => i.text === 'X');
|
||
assert.ok(page.some(i => i.text === '领63347金币' && i.rect.top > close.rect.bottom));
|
||
assert.equal(c.findEmptyRewardPopupClose(page), close);
|
||
assert.equal(c.needsCommonHandling(page), true);
|
||
// 浮层内部如果仍有合法金币领取按钮,应保留领取优先。
|
||
assert.equal(c.findEmptyRewardPopupClose([...page, item('领900金币', 400, 1500)]), null);
|
||
});
|
||
|
||
test('签到后追加的桌面助手推广下拉原生拖动条关闭,不在遮挡层下查找补贴', () => {
|
||
const c = load();
|
||
const page = JSON.parse(fs.readFileSync(path.join(__dirname, '../debug/2026-10-21/oppo-hongguo11-shortcut-prompt.json'), 'utf8'));
|
||
assert.equal(c.isShortcutPrompt(page), true);
|
||
assert.equal(c.needsCommonHandling(page), true);
|
||
let returned = 0;
|
||
c.snapshot = () => returned ? [item('日常福利', 80, 400)] : page;
|
||
c.className = name => {
|
||
assert.equal(name, 'android.view.ViewGroup');
|
||
return {find: () => ({size: () => 1, get: () => ({visibleToUser: () => true,
|
||
bounds: () => ({left: 490, top: 1268, right: 590, bottom: 1279})})})};
|
||
};
|
||
c.swipe = (x1, y1, x2, y2, duration) => {
|
||
assert.equal(x1, 540); assert.equal(y1, 1274);
|
||
assert.equal(x2, 540); assert.ok(y2 > 2200); assert.equal(duration, 600);
|
||
returned++; return true;
|
||
};
|
||
c.back = () => {throw Error('真机此推广不响应返回,应下拉拖动条');};
|
||
c.tap = () => {throw Error('不应点击添加桌面助手或背景领取');};
|
||
c.handleVideosLoop(null, 0);
|
||
assert.equal(returned, 1);
|
||
assert.equal(c.actionSerial, 1);
|
||
assert.equal(c.isShortcutPrompt([item('添加赚钱助手到桌面领金币', 200, 600)]), false);
|
||
assert.equal(c.isShortcutPrompt([item('添加賺钱助手到桌面领6666金币', 200, 600), item('立即添加领专属奖励', 300, 1400)]), true);
|
||
});
|
||
|
||
test('主流程先完成签到再启动补贴;无签到入口也继续后续任务', () => {
|
||
for (const available of [true, false]) {
|
||
const c = load();
|
||
const order = [];
|
||
c.files = {write() {}};
|
||
const engine = {id: 1, getSource: () => 'hongguo-daily.auto.js'};
|
||
c.engines = {myEngine: () => engine, all: () => [engine]};
|
||
c.initLocalOcr = () => {c.localOcrEnabled = true;};
|
||
c.auto = {waitFor() {}};
|
||
c.foregroundPackage = () => c.CONFIG.packageName;
|
||
const page = [item('日常福利', 80, 400)];
|
||
c.snapshot = () => page;
|
||
c.enterWelfareStep = () => order.push('福利');
|
||
c.ensureTaskPage = () => page;
|
||
c.returnFromSignPage = () => {};
|
||
c.searchEarningTask = () => available ? item('去签到', 828, 920) : null;
|
||
c.tap = () => {
|
||
order.push('去签到');
|
||
c.snapshot = () => {c.actionSerial++; order.push('通用领取'); return page;};
|
||
};
|
||
c.runMealStep = () => {order.push('补贴'); return {ok: true};};
|
||
c.flipCardStep = () => order.push('翻卡');
|
||
c.massVideoStep = () => {order.push('海量'); return {ok: true};};
|
||
c.runStep = (_name, action) => ({ok: true, value: action()});
|
||
c.runDaily();
|
||
assert.deepEqual(order, available ? ['福利', '去签到', '通用领取', '补贴', '翻卡', '海量'] : ['福利', '补贴', '翻卡', '海量']);
|
||
}
|
||
});
|