Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
121 lines
3.7 KiB
TypeScript
121 lines
3.7 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
|
|
import {
|
|
PluginViewTabStore,
|
|
resolveBatchTabCloseFocus,
|
|
resolvePluginViewRequest,
|
|
toPluginViewTabId,
|
|
} from './pluginViewTabStore.ts';
|
|
|
|
function fixture() {
|
|
let activeTabId = 'vault';
|
|
const store = new PluginViewTabStore({
|
|
getActiveTabId: () => activeTabId,
|
|
setActiveTabId: (next) => { activeTabId = next; },
|
|
});
|
|
return { store, getActiveTabId: () => activeTabId };
|
|
}
|
|
|
|
test('plugin view tab IDs include both plugin and contribution ownership', () => {
|
|
assert.equal(
|
|
toPluginViewTabId('com.example.owner', 'shared.view'),
|
|
'plugin-view:com.example.owner:shared.view',
|
|
);
|
|
});
|
|
|
|
test('closing or withdrawing an active plugin view tab returns focus to a safe root page', () => {
|
|
const first = fixture();
|
|
const tab = first.store.open({
|
|
pluginId: 'com.example.owner',
|
|
pluginName: 'Owner',
|
|
viewId: 'com.example.owner.view',
|
|
title: 'View',
|
|
});
|
|
assert.equal(first.getActiveTabId(), tab.id);
|
|
first.store.close(tab.id);
|
|
assert.equal(first.getActiveTabId(), 'vault');
|
|
|
|
const second = fixture();
|
|
second.store.open({
|
|
pluginId: 'com.example.owner',
|
|
pluginName: 'Owner',
|
|
viewId: 'com.example.owner.view',
|
|
title: 'View',
|
|
});
|
|
second.store.retain(new Set());
|
|
assert.equal(second.getActiveTabId(), 'vault');
|
|
});
|
|
|
|
test('tab withdrawal notifies lifecycle owners for explicit close and contribution removal', () => {
|
|
const { store } = fixture();
|
|
const closed: string[] = [];
|
|
store.onDidClose(({ tab }) => closed.push(tab.id));
|
|
const first = store.open({
|
|
pluginId: 'com.example.owner',
|
|
pluginName: 'Owner',
|
|
viewId: 'com.example.owner.first',
|
|
title: 'First',
|
|
});
|
|
store.close(first.id);
|
|
const second = store.open({
|
|
pluginId: 'com.example.owner',
|
|
pluginName: 'Owner',
|
|
viewId: 'com.example.owner.second',
|
|
title: 'Second',
|
|
});
|
|
store.retain(new Set());
|
|
assert.deepEqual(closed, [first.id, second.id]);
|
|
});
|
|
|
|
test('localized contribution snapshots refresh titles and icons of already-open tabs', () => {
|
|
const { store } = fixture();
|
|
const tab = store.open({
|
|
pluginId: 'com.example.owner',
|
|
pluginName: 'Owner',
|
|
viewId: 'com.example.owner.view',
|
|
title: 'View',
|
|
icon: { kind: 'theme', name: 'terminal' },
|
|
context: { source: 'menu' },
|
|
});
|
|
store.refreshMetadata([{
|
|
pluginId: 'com.example.owner',
|
|
pluginName: '所有者',
|
|
viewId: 'com.example.owner.view',
|
|
title: '视图',
|
|
icon: { kind: 'theme', name: 'layout-panel' },
|
|
}]);
|
|
assert.deepEqual(store.getTab(tab.id), {
|
|
...tab,
|
|
pluginName: '所有者',
|
|
title: '视图',
|
|
icon: { kind: 'theme', name: 'layout-panel' },
|
|
});
|
|
});
|
|
|
|
test('an explicit open request takes precedence over the currently active plugin tab', () => {
|
|
const activeTab = { viewId: 'com.example.current', context: { source: 'tab' } };
|
|
assert.deepEqual(resolvePluginViewRequest({
|
|
viewId: 'com.example.requested',
|
|
context: { source: 'menu' },
|
|
}, activeTab), {
|
|
viewId: 'com.example.requested',
|
|
context: { source: 'menu' },
|
|
});
|
|
assert.deepEqual(resolvePluginViewRequest(null, activeTab), activeTab);
|
|
});
|
|
|
|
test('mixed batch closes focus the nearest tab that remains after every target is removed', () => {
|
|
const pluginTab = toPluginViewTabId('com.example.owner', 'com.example.owner.view');
|
|
assert.equal(resolveBatchTabCloseFocus({
|
|
orderedTabIds: ['session-1', pluginTab, 'workspace-1', 'session-2'],
|
|
closingTabIds: new Set(['session-1', pluginTab, 'workspace-1']),
|
|
activeTabId: pluginTab,
|
|
}), 'session-2');
|
|
assert.equal(resolveBatchTabCloseFocus({
|
|
orderedTabIds: ['session-1', pluginTab],
|
|
closingTabIds: new Set(['session-1', pluginTab]),
|
|
activeTabId: pluginTab,
|
|
}), 'vault');
|
|
});
|