重构多 flow 邮件轮询并接入 Grok SSO
This commit is contained in:
@@ -36,6 +36,7 @@ function extractFunction(source, name) {
|
||||
test('sidepanel html exposes flow selector and kiro source fields', () => {
|
||||
[
|
||||
'id="select-flow"',
|
||||
'<option value="grok">Grok</option>',
|
||||
'id="label-source-selector"',
|
||||
'id="row-step6-cookie-settings"',
|
||||
'id="row-kiro-rs-url"',
|
||||
@@ -46,9 +47,90 @@ test('sidepanel html exposes flow selector and kiro source fields', () => {
|
||||
'id="row-kiro-web-status"',
|
||||
'id="row-kiro-login-url"',
|
||||
'id="row-kiro-upload-status"',
|
||||
'id="row-grok-register-status"',
|
||||
'id="row-grok-sso-status"',
|
||||
'id="row-grok-sso-settings"',
|
||||
'id="btn-copy-grok-sso"',
|
||||
'id="btn-export-grok-sso"',
|
||||
'id="btn-clear-grok-sso"',
|
||||
'<script src="../flows/grok/index.js"></script>',
|
||||
'<script src="../flows/grok/workflow.js"></script>',
|
||||
].forEach((snippet) => {
|
||||
assert.match(sidepanelHtml, new RegExp(snippet.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')));
|
||||
});
|
||||
assert.ok(
|
||||
sidepanelHtml.indexOf('<script src="../flows/kiro/workflow.js"></script>')
|
||||
< sidepanelHtml.indexOf('<script src="../flows/grok/index.js"></script>')
|
||||
);
|
||||
assert.ok(
|
||||
sidepanelHtml.indexOf('<script src="../flows/grok/workflow.js"></script>')
|
||||
< sidepanelHtml.indexOf('<script src="../flows/index.js"></script>')
|
||||
);
|
||||
});
|
||||
|
||||
test('sidepanel Grok SSO clear action goes through background message instead of direct storage writes', () => {
|
||||
const clearButtonIndex = sidepanelSource.indexOf("btnClearGrokSso?.addEventListener('click'");
|
||||
assert.notEqual(clearButtonIndex, -1);
|
||||
const nextManagerIndex = sidepanelSource.indexOf('const hotmailManager', clearButtonIndex);
|
||||
assert.notEqual(nextManagerIndex, -1);
|
||||
const block = sidepanelSource.slice(clearButtonIndex, nextManagerIndex);
|
||||
|
||||
assert.match(block, /type:\s*'CLEAR_GROK_SSO_COOKIES'/);
|
||||
assert.match(block, /chrome\.runtime\.sendMessage/);
|
||||
assert.doesNotMatch(block, /chrome\.storage/);
|
||||
assert.doesNotMatch(block, /storage\.local\.set/);
|
||||
});
|
||||
|
||||
test('sidepanel renders Grok SSO status from canonical runtime state', () => {
|
||||
const bundle = [
|
||||
extractFunction(sidepanelSource, 'getGrokRuntimeState'),
|
||||
extractFunction(sidepanelSource, 'normalizeGrokSsoCookies'),
|
||||
extractFunction(sidepanelSource, 'getGrokRegisterStatusLabel'),
|
||||
extractFunction(sidepanelSource, 'renderGrokRuntimeState'),
|
||||
].join('\n');
|
||||
|
||||
const api = new Function(`
|
||||
let latestState = {};
|
||||
const displayGrokRegisterStatus = { textContent: '' };
|
||||
const displayGrokSsoStatus = { textContent: '' };
|
||||
const displayGrokSsoCookie = { textContent: '', title: '' };
|
||||
const buttons = [];
|
||||
const btnCopyGrokSso = { disabled: false };
|
||||
const btnExportGrokSso = { disabled: false };
|
||||
const btnClearGrokSso = { disabled: false };
|
||||
${bundle}
|
||||
return {
|
||||
displayGrokRegisterStatus,
|
||||
displayGrokSsoStatus,
|
||||
displayGrokSsoCookie,
|
||||
btnCopyGrokSso,
|
||||
btnExportGrokSso,
|
||||
btnClearGrokSso,
|
||||
renderGrokRuntimeState,
|
||||
};
|
||||
`)();
|
||||
|
||||
api.renderGrokRuntimeState({
|
||||
runtimeState: {
|
||||
flowState: {
|
||||
grok: {
|
||||
register: { status: 'completed' },
|
||||
sso: {
|
||||
currentCookie: '1234567890abcdef',
|
||||
cookies: ['1234567890abcdef', 'second-cookie'],
|
||||
extractedAt: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
assert.equal(api.displayGrokRegisterStatus.textContent, '已完成');
|
||||
assert.match(api.displayGrokSsoStatus.textContent, /^已提取 2 条/);
|
||||
assert.equal(api.displayGrokSsoCookie.textContent, '12345678...abcdef');
|
||||
assert.equal(api.btnCopyGrokSso.disabled, false);
|
||||
assert.equal(api.btnExportGrokSso.disabled, false);
|
||||
assert.equal(api.btnClearGrokSso.disabled, false);
|
||||
});
|
||||
|
||||
test('sidepanel Kiro GitHub button opens the configured fork', () => {
|
||||
|
||||
Reference in New Issue
Block a user