From 68cd4f9392fbeb0bc93a14489bb29243fc670c00 Mon Sep 17 00:00:00 2001 From: Logan Ramos Date: Wed, 30 Mar 2022 14:39:04 -0400 Subject: [PATCH] Add test for open and closing tab patching --- .../test/browser/extHostEditorTabs.test.ts | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/src/vs/workbench/api/test/browser/extHostEditorTabs.test.ts b/src/vs/workbench/api/test/browser/extHostEditorTabs.test.ts index 793c5af2886..c9fe89b33c7 100644 --- a/src/vs/workbench/api/test/browser/extHostEditorTabs.test.ts +++ b/src/vs/workbench/api/test/browser/extHostEditorTabs.test.ts @@ -602,4 +602,80 @@ suite('ExtHostEditorTabs', function () { // Something related to the active tab changed assert.strictEqual(activeTabChangeCount, 2); }); + test('Tab operations patches open and close correctly', function () { + const extHostEditorTabs = new ExtHostEditorTabs( + SingleProxyRPCProtocol(new class extends mock() { + // override/implement $moveTab or $closeTab + }) + ); + + const tab1: IEditorTabDto = createTabDto({ + id: 'uniquestring', + isActive: true, + label: 'label1', + }); + + const tab2: IEditorTabDto = createTabDto({ + isActive: false, + id: 'uniquestring2', + label: 'label2', + }); + + const tab3: IEditorTabDto = createTabDto({ + isActive: false, + id: 'uniquestring3', + label: 'label3', + }); + + extHostEditorTabs.$acceptEditorTabModel([{ + isActive: true, + viewColumn: 0, + groupId: 12, + tabs: [tab1, tab2, tab3] + }]); + + assert.strictEqual(extHostEditorTabs.tabGroups.groups.length, 1); + assert.strictEqual(extHostEditorTabs.tabGroups.groups.map(g => g.tabs).flat().length, 3); + + // Close tab 2 + extHostEditorTabs.$acceptTabOperation({ + groupId: 12, + index: 1, + kind: TabModelOperationKind.TAB_CLOSE, + tabDto: tab2 + }); + assert.strictEqual(extHostEditorTabs.tabGroups.groups.length, 1); + assert.strictEqual(extHostEditorTabs.tabGroups.groups.map(g => g.tabs).flat().length, 2); + + // Close active tab and update tab 3 to be active + extHostEditorTabs.$acceptTabOperation({ + groupId: 12, + index: 0, + kind: TabModelOperationKind.TAB_CLOSE, + tabDto: tab1 + }); + assert.strictEqual(extHostEditorTabs.tabGroups.groups.length, 1); + assert.strictEqual(extHostEditorTabs.tabGroups.groups.map(g => g.tabs).flat().length, 1); + tab3.isActive = true; + extHostEditorTabs.$acceptTabOperation({ + groupId: 12, + index: 0, + kind: TabModelOperationKind.TAB_UPDATE, + tabDto: tab3 + }); + assert.strictEqual(extHostEditorTabs.tabGroups.groups.length, 1); + assert.strictEqual(extHostEditorTabs.tabGroups.groups.map(g => g.tabs).flat().length, 1); + assert.strictEqual(extHostEditorTabs.tabGroups.groups[0]?.activeTab?.label, 'label3'); + + // Open tab 2 back + extHostEditorTabs.$acceptTabOperation({ + groupId: 12, + index: 1, + kind: TabModelOperationKind.TAB_OPEN, + tabDto: tab2 + }); + assert.strictEqual(extHostEditorTabs.tabGroups.groups.length, 1); + assert.strictEqual(extHostEditorTabs.tabGroups.groups.map(g => g.tabs).flat().length, 2); + assert.strictEqual(extHostEditorTabs.tabGroups.groups[0]?.tabs[1]?.label, 'label2'); + }); });