|
| 1 | +import test from 'node:test'; |
| 2 | +import assert from 'node:assert/strict'; |
| 3 | +import { loadApp } from '../lib/load-app.mjs'; |
| 4 | + |
| 5 | +// GitHub and 工蜂 sync stores the tracker number in issue.number, so a synced |
| 6 | +// issue and a platform requirement of the same project can both have number 1. |
| 7 | +// Every surface must show the same, unambiguous key for each of them. |
| 8 | +test('synced tracker issues keep their tracker key on every surface', async (t) => { |
| 9 | + const app = await loadApp(); |
| 10 | + t.after(app.close); |
| 11 | + const result = structuredClone(await app.evaluate(`(() => { |
| 12 | + state.data.projects[0].key = 'SWP'; |
| 13 | + const local = {id:'local-1',projectId:'project-1',number:1,title:'title_case 吞掉连续空格',source:'local',status:'todo',priority:'medium'}; |
| 14 | + const github = {id:'gh-repo-1',projectId:'project-1',number:1,title:'word_count 全角空格',source:'github',kind:'issue',status:'todo',priority:'medium', |
| 15 | + externalRef:{source:'github',externalId:'990001',externalIid:1,externalType:'issue'}}; |
| 16 | + const gongfeng = {id:'gf-repo-5',projectId:'project-1',number:5,title:'工蜂缺陷',source:'gongfeng',status:'todo',priority:'medium', |
| 17 | + externalRef:{source:'gongfeng',externalId:'77005',externalIid:5}}; |
| 18 | + const tapd = {id:'tapd-1',projectId:'project-1',number:2,title:'TAPD 需求',source:'tapd',status:'todo',priority:'medium', |
| 19 | + externalRef:{source:'tapd',externalId:'1010101'}}; |
| 20 | + const plain = {id:'p-9',projectId:'missing',number:9,title:'无项目',status:'todo'}; |
| 21 | + state.data.issues = [local, github, gongfeng, tapd]; |
| 22 | + state.projectFilter = 'project-1'; |
| 23 | + state.sourceFilter=''; state.issueStatusFilter=''; state.issueAssigneeFilter=''; state.issueRunFilter=''; |
| 24 | + const search = q => { state.issueQuery = q; return filteredIssues().map(i => i.id); }; |
| 25 | + state.data.tasks = [{id:'t1',issueId:'local-1',runId:'run-local'},{id:'t2',issueId:'gh-repo-1',runId:'run-gh'}]; |
| 26 | + const run = (id, issueId) => ({id, workflowId:'flow-1', status:'waiting', nodes:{}, createdAt:new Date().toISOString(), |
| 27 | + executionContext:{issueId}, workflowSnapshot:{id:'flow-1', name:'LOOP', nodes:[{id:'accept',name:'人工验收',type:'approval'}]}}); |
| 28 | + const runRef = r => { const d = document.createElement('div'); d.innerHTML = runRowHTML(r, state.data.workflows || []); return d.querySelector('.run-ref')?.textContent; }; |
| 29 | + const apKey = r => { const d = document.createElement('div'); d.innerHTML = approvalCardHTML(r); return d.querySelector('.ap-key')?.textContent; }; |
| 30 | + openIssue(github); |
| 31 | + const modalGitHub = document.querySelector('#issueModalTitle').textContent; |
| 32 | + openIssue(local); |
| 33 | + const modalLocal = document.querySelector('#issueModalTitle').textContent; |
| 34 | + return { |
| 35 | + labels: [local, github, gongfeng, tapd, plain].map(issueKeyLabel), |
| 36 | + searchLocalKey: search('SWP-1'), |
| 37 | + searchGitHubKey: search('#1'), |
| 38 | + searchGongfengKey: search('#5'), |
| 39 | + runRefs: [runRef(run('run-local','local-1')), runRef(run('run-gh','gh-repo-1'))], |
| 40 | + approvalKeys: [apKey(run('run-local','local-1')), apKey(run('run-gh','gh-repo-1'))], |
| 41 | + modalGitHub, modalLocal, |
| 42 | + }; |
| 43 | + })()`)); |
| 44 | + assert.deepEqual(result.labels, ['SWP-1', '#1', '#5', '1010101', 'ISS-9']); |
| 45 | + assert.deepEqual(result.searchLocalKey, ['local-1']); |
| 46 | + assert.deepEqual(result.searchGitHubKey, ['gh-repo-1']); |
| 47 | + assert.deepEqual(result.searchGongfengKey, ['gf-repo-5']); |
| 48 | + assert.deepEqual(result.runRefs, ['SWP-1', '#1']); |
| 49 | + assert.deepEqual(result.approvalKeys, ['SWP-1', '#1']); |
| 50 | + assert.equal(result.modalGitHub, '#1 word_count 全角空格'); |
| 51 | + assert.equal(result.modalLocal, 'SWP-1 title_case 吞掉连续空格'); |
| 52 | +}); |
0 commit comments