feat: add unified learning workflows and six-tab assistant
This commit is contained in:
+27
-14
@@ -47,6 +47,11 @@ function documentHTML(practice) {
|
||||
document.addEventListener('click',function(event){const n=event.target.closest('.pc_examtest_content_list_des');if(n){const box=n.closest('.pc_examtest_content');if(box.dataset.showanswer==='true')return;const label=n.querySelector('.examtest_content_list_des_optionsort').textContent;window.optionClicks.push(box.dataset.number+':'+label);if(box.dataset.kind==='多选')n.classList.toggle('examtest_content_list_des_checked');else{box.querySelectorAll('.pc_examtest_content_list_des').forEach(x=>x.classList.remove('examtest_content_list_des_checked'));n.classList.add('examtest_content_list_des_checked');box.dataset.showanswer='true';box.querySelector('.pc_examtest_content_question_showanswer').remove();box.querySelectorAll('.pc_examtest_content_list_child1').forEach(x=>x.className='pc_examtest_content_list_child2');}}if(event.target.closest('.pc_examtest_content_question_showanswer'))window.parseClicks++;if(event.target.id==='submit')window.submitClicks++;});
|
||||
</script></body>`;
|
||||
}
|
||||
async function activate(page, key) {
|
||||
const expand = page.getByRole('button', { name: '展开题库助手', exact: true });
|
||||
if (await expand.isVisible()) await expand.click();
|
||||
await page.getByTestId('tab-' + key).click();
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const memory = new Map([['yianxue.assistant.setting.v2.autoExport', true], ['yianxue.assistant.setting.v2.exportEnabled', true]]);
|
||||
@@ -116,53 +121,58 @@ function documentHTML(practice) {
|
||||
const startURL = origin + '/clientcn/main?from=assistant-test';
|
||||
await page.goto(startURL); await page.addScriptTag({ content: sandboxScript });
|
||||
await page.evaluate(() => YianAssistant.ready);
|
||||
await page.evaluate(() => YianAssistant.setLearningSetting('answerInterval', 0));
|
||||
assert.equal(page.url(), startURL); assert.equal(await page.title(), '主站主页验证');
|
||||
assert(await page.getByRole('heading', { name: '主站主页的题库搜索' }).isVisible());
|
||||
await page.getByRole('button', { name: '展开题库助手' }).click();
|
||||
assert(await page.locator('#yian-question-assistant .brand').textContent() === '谊安学助手 2.0');
|
||||
await activate(page, 'settings');
|
||||
assert.equal(await page.getByRole('switch', { name: '导出题库', exact: true }).isChecked(), false);
|
||||
await activate(page, 'exam');
|
||||
assert(await page.getByRole('switch', { name: '自动选择答案' }).isDisabled());
|
||||
assert.equal(await page.evaluate(() => typeof window.GM_getValue), 'undefined');
|
||||
console.log('PASS 主站 /clientcn/main 查询参数下显示搜索面板,非练习页禁止自动选择,沙箱 API 兼容');
|
||||
|
||||
const input = await bankInput();
|
||||
await activate(page, 'bank');
|
||||
await page.locator('#yian-question-assistant input[type=file]').setInputFiles(input.file);
|
||||
await page.waitForFunction(total => YianAssistant.getSnapshot().total === total, input.total);
|
||||
assert.deepEqual(await page.evaluate(() => YianAssistant.getSnapshot().counts), input.counts);
|
||||
assert.deepEqual(await page.evaluate(() => YianAssistant.getSnapshot().counts), Object.assign({ 未标明: 0 }, input.counts));
|
||||
assert.equal(await page.evaluate(() => YianAssistant.getSnapshot().storage), 'userscript');
|
||||
await page.getByRole('radio', { name: '主操', exact: true }).check();
|
||||
assert.equal(await page.getByRole('radio').count(), 0, '统一题库已取消岗位选择');
|
||||
await page.getByRole('textbox', { name: '搜索题目' }).fill('工程控制措施');
|
||||
await page.getByRole('button', { name: '搜索', exact: true }).click();
|
||||
assert(await page.locator('#yian-question-assistant .result .conflict').count() > 0);
|
||||
assert((await page.locator('#yian-question-assistant .results-title').innerText()).includes('主操'));
|
||||
console.log('PASS ' + (input.real ? '实际ZIP导入5520条' : '合成ZIP导入90条') + '、岗位数量与冲突来源显示');
|
||||
assert((await page.locator('#yian-question-assistant .results-title').innerText()).includes('统一题库'));
|
||||
console.log('PASS ' + (input.real ? '实际ZIP导入5520条' : '合成ZIP导入90条') + '、旧岗位来源数量与统一冲突显示');
|
||||
|
||||
// 未点击搜索按钮的新输入,也应在换岗位时立即检索。
|
||||
// 三种岗位的同题聚合为统一结果,切栏保留尚未提交的关键词。
|
||||
const query = '广西华谊新材料有限公司涉及几种高危工艺';
|
||||
await page.getByRole('textbox', { name: '搜索题目' }).fill(query);
|
||||
await page.getByRole('radio', { name: '副操', exact: true }).check();
|
||||
await activate(page, 'console'); await activate(page, 'bank');
|
||||
assert.equal(await page.getByRole('textbox', { name: '搜索题目' }).inputValue(), query);
|
||||
assert((await page.locator('#yian-question-assistant .results-title').innerText()).includes('副操'));
|
||||
await page.getByRole('button', { name: '搜索', exact: true }).click();
|
||||
assert((await page.locator('#yian-question-assistant .results-title').innerText()).includes('统一题库'));
|
||||
assert(await page.locator('#yian-question-assistant .result').count() > 0);
|
||||
assert((await page.locator('#yian-question-assistant .sources').first().innerText()).includes('副操'));
|
||||
const unifiedSources = await page.locator('#yian-question-assistant .sources').first().innerText();
|
||||
for (const source of ['主操', '班长', '副操']) assert(unifiedSources.includes(source), '统一结果应保留来源:' + source);
|
||||
await page.getByRole('button', { name: '复制题目与答案' }).first().click();
|
||||
assert(clipboard.includes('正确答案:')); assert(clipboard.includes('高危工艺'));
|
||||
await page.getByRole('radio', { name: '班长', exact: true }).check();
|
||||
assert((await page.locator('#yian-question-assistant .results-title').innerText()).includes('班长'));
|
||||
await page.getByRole('radio', { name: '主操', exact: true }).check();
|
||||
await page.getByRole('textbox', { name: '搜索题目' }).fill('作业');
|
||||
await page.getByRole('button', { name: '搜索', exact: true }).click();
|
||||
assert.equal(await page.locator('#yian-question-assistant .result').count(), 20);
|
||||
await page.getByRole('button', { name: '下一页', exact: true }).click();
|
||||
assert((await page.locator('#yian-question-assistant .pagination').innerText()).includes('21–'));
|
||||
assert(await page.locator('#yian-question-assistant .result').count() > 0);
|
||||
console.log('PASS 三岗位隔离、换岗位保留当前关键词、结果复制与20条分页');
|
||||
console.log('PASS 跨岗位来源统一检索、切栏保留关键词、结果复制与20条分页');
|
||||
|
||||
const restrictions = () => page.evaluate(() => ({ select: document.body.getAttribute('onselectstart'), context: document.body.getAttribute('oncontextmenu'), blocked: !document.body.dispatchEvent(new Event('selectstart', { bubbles: true, cancelable: true })), style: getComputedStyle(document.querySelector('#copy-target')).userSelect }));
|
||||
assert.deepEqual(await restrictions(), { select: null, context: null, blocked: false, style: 'text' });
|
||||
await activate(page, 'settings');
|
||||
await page.getByRole('switch', { name: '允许复制文字' }).uncheck();
|
||||
assert.deepEqual(await restrictions(), { select: 'return false', context: 'return false', blocked: true, style: 'none' });
|
||||
await page.getByRole('switch', { name: '允许复制文字' }).check();
|
||||
await activate(page, 'bank');
|
||||
await page.evaluate(() => { const range = document.createRange(); range.selectNodeContents(document.getElementById('copy-target')); const selection = getSelection(); selection.removeAllRanges(); selection.addRange(range); });
|
||||
await page.getByRole('button', { name: '用选中文字搜索', exact: true }).click();
|
||||
assert.equal(await page.getByRole('textbox', { name: '搜索题目' }).inputValue(), query);
|
||||
@@ -178,10 +188,13 @@ function documentHTML(practice) {
|
||||
const second = await context.newPage(); capture(second);
|
||||
const secondURL = origin + '/clientcn/exam/nested/fixture/questions?flag=exercise';
|
||||
await second.goto(secondURL); await second.addScriptTag({ content: sandboxScript }); await second.evaluate(() => YianAssistant.ready);
|
||||
await second.evaluate(() => YianAssistant.setLearningSetting('answerInterval', 0));
|
||||
await second.waitForFunction(() => YianAssistant.getState().pageReady);
|
||||
await activate(second, 'settings');
|
||||
assert.equal(await second.getByRole('switch', { name: '导出题库', exact: true }).isChecked(), false, '旧版导出偏好不能开启新版开关');
|
||||
assert.equal(await second.evaluate(() => YianAssistant.getSnapshot().total), input.total);
|
||||
assert.equal(await second.evaluate(() => YianAssistant.getState().role), '主操');
|
||||
assert.equal(await second.evaluate(() => YianAssistant.getState().role), '');
|
||||
await activate(second, 'exam');
|
||||
assert.equal(await second.getByRole('switch', { name: '自动选择答案' }).isChecked(), false);
|
||||
await second.getByRole('switch', { name: '自动选择答案' }).check();
|
||||
await second.waitForFunction(() => YianAssistant.getState().metrics.selected === 3);
|
||||
@@ -193,7 +206,7 @@ function documentHTML(practice) {
|
||||
await second.getByRole('switch', { name: '自动选择答案' }).check();
|
||||
await second.waitForTimeout(500); assert.equal(await second.evaluate(() => window.optionClicks.length), 5);
|
||||
await second.getByRole('switch', { name: '自动选择答案' }).uncheck();
|
||||
console.log('PASS 同站不同 /clientcn 路径题库岗位共用,实际选项点击、换序、多选差集与无重复');
|
||||
console.log('PASS 同站不同 /clientcn 路径统一题库共用,实际选项点击、换序、多选差集与无重复');
|
||||
|
||||
await second.evaluate(html => { history.pushState({}, '', '/clientcn/exam/another/random-route?flag=exercise'); const doc = new DOMParser().parseFromString(html, 'text/html'); document.querySelector('app-examtest').replaceWith(doc.querySelector('app-examtest')); window.optionClicks = []; }, practiceHTML());
|
||||
await second.waitForFunction(() => YianAssistant.getContext().ready);
|
||||
|
||||
Reference in New Issue
Block a user