Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3147,12 +3147,12 @@
},
{
"command": "pr.revealFileInOS",
"when": "(view =~ /(pr|prStatus):github/ && viewItem =~ /filechange(?!:ADD)/) && !isSessionsWindow",
"when": "(view =~ /(pr|prStatus):github/ && viewItem =~ /filechange(?!:(ADD|DELETE))/) && !isSessionsWindow",
"group": "0_open@1"
},
{
"command": "pr.openOriginalFile",
"when": "(view =~ /(pr|prStatus):github/ && viewItem =~ /filechange:MODIFY/) && !isSessionsWindow",
"when": "(view =~ /(pr|prStatus):github/ && viewItem =~ /filechange:(MODIFY|DELETE)/) && !isSessionsWindow",
"group": "0_open@2"
},
{
Expand Down
42 changes: 42 additions & 0 deletions src/test/view/fileChangeMenus.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { default as assert } from 'assert';
import packageJson from '../../../package.json';

describe('File change context menus', function () {
const cases = [
{ status: 'ADD', openOriginal: false, reveal: false },
{ status: 'DELETE', openOriginal: true, reveal: false },
{ status: 'MODIFY', openOriginal: true, reveal: true },
{ status: 'RENAME', openOriginal: false, reveal: true },
{ status: 'COPY', openOriginal: false, reveal: true },
{ status: 'TYPE', openOriginal: false, reveal: true },
{ status: 'UNKNOWN', openOriginal: false, reveal: true },
{ status: 'UNMERGED', openOriginal: false, reveal: true },
];

for (const command of ['pr.openOriginalFile', 'pr.revealFileInOS']) {
it(`shows ${command} only for applicable file changes`, function () {
const menu = packageJson.contributes.menus['view/item/context'].find(item => item.command === command);
assert.ok(menu);
const match = /viewItem =~ \/(?<pattern>[^/]+)\//.exec(menu.when);
assert.ok(match?.groups?.pattern);
const pattern = new RegExp(match.groups.pattern);

for (const testCase of cases) {
for (const viewed of ['viewed', 'unviewed']) {
const contextValue = `filechange:${testCase.status}:${viewed}`;
assert.strictEqual(
pattern.test(contextValue),
command === 'pr.openOriginalFile' ? testCase.openOriginal : testCase.reveal,
contextValue,
);
}
}
assert.strictEqual(pattern.test('description'), false);
});
}
});
Loading