@@ -24,7 +24,7 @@ import { DataSource } from '../src/dataSource';
2424import { ExtensionState } from '../src/extensionState' ;
2525import { Logger } from '../src/logger' ;
2626import { GitFileStatus , PullRequestProvider } from '../src/types' ;
27- import { GitExecutable , UNCOMMITTED , abbrevCommit , abbrevText , archive , constructIncompatibleGitVersionMessage , copyFilePathToClipboard , copyToClipboard , createPullRequest , evalPromises , findGit , getExtensionVersion , getGitExecutable , getGitExecutableFromPaths , getNonce , getPathFromStr , getPathFromUri , getRelativeTimeDiff , getRepoName , isGitAtLeastVersion , isPathInWorkspace , openExtensionSettings , openFile , openGitTerminal , pathWithTrailingSlash , realpath , resolveSpawnOutput , resolveToSymbolicPath , showErrorMessage , showInformationMessage , viewDiff , viewFileAtRevision , viewScm } from '../src/utils' ;
27+ import { GitExecutable , UNCOMMITTED , abbrevCommit , abbrevText , archive , constructIncompatibleGitVersionMessage , copyFilePathToClipboard , copyToClipboard , createPullRequest , evalPromises , findGit , getExtensionVersion , getGitExecutable , getGitExecutableFromPaths , getNonce , getPathFromStr , getPathFromUri , getRelativeTimeDiff , getRepoName , isGitAtLeastVersion , isPathInWorkspace , openExtensionSettings , openExternalUrl , openFile , openGitTerminal , pathWithTrailingSlash , realpath , resolveSpawnOutput , resolveToSymbolicPath , showErrorMessage , showInformationMessage , viewDiff , viewFileAtRevision , viewScm } from '../src/utils' ;
2828import { EventEmitter } from '../src/utils/event' ;
2929
3030const extensionContext = vscode . mocks . extensionContext ;
@@ -694,7 +694,7 @@ describe('copyToClipboard', () => {
694694describe ( 'createPullRequest' , ( ) => {
695695 it ( 'Should construct and open a BitBucket Pull Request Creation Url' , async ( ) => {
696696 // Setup
697- vscode . env . openExternal . mockResolvedValueOnce ( null ) ;
697+ vscode . env . openExternal . mockResolvedValueOnce ( true ) ;
698698
699699 // Run
700700 const result = await createPullRequest ( {
@@ -718,7 +718,7 @@ describe('createPullRequest', () => {
718718
719719 it ( 'Should construct and open a Custom Providers Pull Request Creation Url' , async ( ) => {
720720 // Setup
721- vscode . env . openExternal . mockResolvedValueOnce ( null ) ;
721+ vscode . env . openExternal . mockResolvedValueOnce ( true ) ;
722722
723723 // Run
724724 const result = await createPullRequest ( {
@@ -745,7 +745,7 @@ describe('createPullRequest', () => {
745745
746746 it ( 'Should construct and open a GitHub Pull Request Creation Url' , async ( ) => {
747747 // Setup
748- vscode . env . openExternal . mockResolvedValueOnce ( null ) ;
748+ vscode . env . openExternal . mockResolvedValueOnce ( true ) ;
749749
750750 // Run
751751 const result = await createPullRequest ( {
@@ -769,7 +769,7 @@ describe('createPullRequest', () => {
769769
770770 it ( 'Should construct and open a GitLab Pull Request Creation Url' , async ( ) => {
771771 // Setup
772- vscode . env . openExternal . mockResolvedValueOnce ( null ) ;
772+ vscode . env . openExternal . mockResolvedValueOnce ( true ) ;
773773
774774 // Run
775775 const result = await createPullRequest ( {
@@ -793,7 +793,7 @@ describe('createPullRequest', () => {
793793
794794 it ( 'Should construct and open a GitLab Pull Request Creation Url (without destProjectId)' , async ( ) => {
795795 // Setup
796- vscode . env . openExternal . mockResolvedValueOnce ( null ) ;
796+ vscode . env . openExternal . mockResolvedValueOnce ( true ) ;
797797
798798 // Run
799799 const result = await createPullRequest ( {
@@ -864,6 +864,68 @@ describe('openExtensionSettings', () => {
864864 } ) ;
865865} ) ;
866866
867+ describe ( 'openExternalUrl' , ( ) => {
868+ it ( 'Should open the URL via Visual Studio Code' , async ( ) => {
869+ // Setup
870+ vscode . env . openExternal . mockResolvedValueOnce ( true ) ;
871+
872+ // Run
873+ const result = await openExternalUrl ( 'https://github.com/mhutchie/vscode-git-graph' ) ;
874+
875+ // Assert
876+ expect ( result ) . toBe ( null ) ;
877+ expect ( vscode . env . openExternal . mock . calls [ 0 ] [ 0 ] . toString ( ) ) . toBe ( 'https://github.com/mhutchie/vscode-git-graph' ) ;
878+ } ) ;
879+
880+ it ( 'Should return an error message if vscode was unable to open the url (vscode.env.openExternal resolves FALSE)' , async ( ) => {
881+ // Setup
882+ vscode . env . openExternal . mockResolvedValueOnce ( false ) ;
883+
884+ // Run
885+ const result = await openExternalUrl ( 'https://github.com/mhutchie/vscode-git-graph' ) ;
886+
887+ // Assert
888+ expect ( result ) . toBe ( 'Visual Studio Code was unable to open the External URL: https://github.com/mhutchie/vscode-git-graph' ) ;
889+ } ) ;
890+
891+ it ( 'Should return an error message if vscode was unable to open the url (vscode.env.openExternal rejects)' , async ( ) => {
892+ // Setup
893+ vscode . env . openExternal . mockRejectedValueOnce ( null ) ;
894+
895+ // Run
896+ const result = await openExternalUrl ( 'https://github.com/mhutchie/vscode-git-graph' ) ;
897+
898+ // Assert
899+ expect ( result ) . toBe ( 'Visual Studio Code was unable to open the External URL: https://github.com/mhutchie/vscode-git-graph' ) ;
900+ } ) ;
901+
902+ it ( 'Should return an error message if vscode was unable to parse the url' , async ( ) => {
903+ // Setup
904+ const spyOnParse = jest . spyOn ( vscode . Uri , 'parse' ) ;
905+ spyOnParse . mockImplementationOnce ( ( ) => {
906+ throw new Error ( ) ;
907+ } ) ;
908+
909+ // Run
910+ const result = await openExternalUrl ( 'https://github.com/mhutchie/vscode-git-graph' ) ;
911+
912+ // Assert
913+ expect ( result ) . toBe ( 'Visual Studio Code was unable to open the External URL: https://github.com/mhutchie/vscode-git-graph' ) ;
914+ expect ( vscode . env . openExternal ) . not . toHaveBeenCalled ( ) ;
915+ } ) ;
916+
917+ it ( 'Should return an error message with a custom type' , async ( ) => {
918+ // Setup
919+ vscode . env . openExternal . mockRejectedValueOnce ( null ) ;
920+
921+ // Run
922+ const result = await openExternalUrl ( 'https://github.com/mhutchie/vscode-git-graph' , 'Custom URL' ) ;
923+
924+ // Assert
925+ expect ( result ) . toBe ( 'Visual Studio Code was unable to open the Custom URL: https://github.com/mhutchie/vscode-git-graph' ) ;
926+ } ) ;
927+ } ) ;
928+
867929describe ( 'openFile' , ( ) => {
868930 it ( 'Should open the file in vscode' , async ( ) => {
869931 // Setup
0 commit comments