@@ -11,6 +11,7 @@ import { FolderRepositoryManager } from '../../github/folderRepositoryManager';
1111import { MockTelemetry } from '../mocks/mockTelemetry' ;
1212import { MockRepository } from '../mocks/mockRepository' ;
1313import { PullRequestOverviewPanel } from '../../github/pullRequestOverview' ;
14+ import { panelKey } from '../../github/issueOverview' ;
1415import { PullRequestModel } from '../../github/pullRequestModel' ;
1516import { MockCommandRegistry } from '../mocks/mockCommandRegistry' ;
1617import { Protocol } from '../../common/protocol' ;
@@ -58,8 +59,9 @@ describe('PullRequestOverview', function () {
5859 } ) ;
5960
6061 afterEach ( function ( ) {
61- if ( PullRequestOverviewPanel . currentPanel ) {
62- PullRequestOverviewPanel . currentPanel . dispose ( ) ;
62+ // Dispose all open panels
63+ for ( const panel of ( PullRequestOverviewPanel as any ) . _panels . values ( ) ) {
64+ panel . dispose ( ) ;
6365 }
6466
6567 pullRequestManager . dispose ( ) ;
@@ -69,7 +71,7 @@ describe('PullRequestOverview', function () {
6971
7072 describe ( 'createOrShow' , function ( ) {
7173 it ( 'creates a new panel' , async function ( ) {
72- assert . strictEqual ( PullRequestOverviewPanel . currentPanel , undefined ) ;
74+ assert . strictEqual ( PullRequestOverviewPanel . findPanel ( 'aaa' , 'bbb' , 1000 ) , undefined ) ;
7375 const createWebviewPanel = sinon . spy ( vscode . window , 'createWebviewPanel' ) ;
7476
7577 repo . addGraphQLPullRequest ( builder => {
@@ -94,10 +96,10 @@ describe('PullRequestOverview', function () {
9496 enableFindWidget : true
9597 } ) ,
9698 ) ;
97- assert . notStrictEqual ( PullRequestOverviewPanel . currentPanel , undefined ) ;
99+ assert . notStrictEqual ( PullRequestOverviewPanel . findPanel ( 'aaa' , 'bbb' , 1000 ) , undefined ) ;
98100 } ) ;
99101
100- it ( 'reveals and updates an existing panel' , async function ( ) {
102+ it ( 'reveals an existing panel for the same PR ' , async function ( ) {
101103 const createWebviewPanel = sinon . spy ( vscode . window , 'createWebviewPanel' ) ;
102104
103105 repo . addGraphQLPullRequest ( builder => {
@@ -125,11 +127,50 @@ describe('PullRequestOverview', function () {
125127 sinon . stub ( prModel0 , 'getStatusChecks' ) . resolves ( [ { state : CheckState . Success , statuses : [ ] } , null ] ) ;
126128 await PullRequestOverviewPanel . createOrShow ( telemetry , EXTENSION_URI , pullRequestManager , identity0 , prModel0 ) ;
127129
128- const panel0 = PullRequestOverviewPanel . currentPanel ;
130+ const panel0 = PullRequestOverviewPanel . findPanel ( identity0 . owner , identity0 . repo , identity0 . number ) ;
129131 assert . notStrictEqual ( panel0 , undefined ) ;
130132 assert . strictEqual ( createWebviewPanel . callCount , 1 ) ;
131133 assert . strictEqual ( panel0 ! . getCurrentTitle ( ) , 'Pull Request #1000' ) ;
132134
135+ // Opening the same PR again should reuse the existing panel
136+ await PullRequestOverviewPanel . createOrShow ( telemetry , EXTENSION_URI , pullRequestManager , identity0 , prModel0 ) ;
137+
138+ assert . strictEqual ( panel0 , PullRequestOverviewPanel . findPanel ( identity0 . owner , identity0 . repo , identity0 . number ) ) ;
139+ assert . strictEqual ( createWebviewPanel . callCount , 1 ) ;
140+ } ) ;
141+
142+ it ( 'creates separate panels for different PRs' , async function ( ) {
143+ const createWebviewPanel = sinon . spy ( vscode . window , 'createWebviewPanel' ) ;
144+
145+ repo . addGraphQLPullRequest ( builder => {
146+ builder . pullRequest ( response => {
147+ response . repository ( r => {
148+ r . pullRequest ( pr => pr . number ( 1000 ) ) ;
149+ } ) ;
150+ } ) ;
151+ } ) ;
152+ repo . addGraphQLPullRequest ( builder => {
153+ builder . pullRequest ( response => {
154+ response . repository ( r => {
155+ r . pullRequest ( pr => pr . number ( 2000 ) ) ;
156+ } ) ;
157+ } ) ;
158+ } ) ;
159+
160+ const prItem0 = convertRESTPullRequestToRawPullRequest ( new PullRequestBuilder ( ) . number ( 1000 ) . build ( ) , repo ) ;
161+ const prModel0 = new PullRequestModel ( credentialStore , telemetry , repo , remote , prItem0 ) ;
162+ const identity0 = { owner : prModel0 . remote . owner , repo : prModel0 . remote . repositoryName , number : prModel0 . number } ;
163+ const resolveStub = sinon . stub ( pullRequestManager , 'resolvePullRequest' ) . resolves ( prModel0 ) ;
164+ sinon . stub ( prModel0 , 'getReviewRequests' ) . resolves ( [ ] ) ;
165+ sinon . stub ( prModel0 , 'getTimelineEvents' ) . resolves ( [ ] ) ;
166+ sinon . stub ( prModel0 , 'validateDraftMode' ) . resolves ( true ) ;
167+ sinon . stub ( prModel0 , 'getStatusChecks' ) . resolves ( [ { state : CheckState . Success , statuses : [ ] } , null ] ) ;
168+ await PullRequestOverviewPanel . createOrShow ( telemetry , EXTENSION_URI , pullRequestManager , identity0 , prModel0 ) ;
169+
170+ const panel0 = PullRequestOverviewPanel . findPanel ( identity0 . owner , identity0 . repo , identity0 . number ) ;
171+ assert . notStrictEqual ( panel0 , undefined ) ;
172+ assert . strictEqual ( createWebviewPanel . callCount , 1 ) ;
173+
133174 const prItem1 = convertRESTPullRequestToRawPullRequest ( new PullRequestBuilder ( ) . number ( 2000 ) . build ( ) , repo ) ;
134175 const prModel1 = new PullRequestModel ( credentialStore , telemetry , repo , remote , prItem1 ) ;
135176 const identity1 = { owner : prModel1 . remote . owner , repo : prModel1 . remote . repositoryName , number : prModel1 . number } ;
@@ -140,9 +181,12 @@ describe('PullRequestOverview', function () {
140181 sinon . stub ( prModel1 , 'getStatusChecks' ) . resolves ( [ { state : CheckState . Success , statuses : [ ] } , null ] ) ;
141182 await PullRequestOverviewPanel . createOrShow ( telemetry , EXTENSION_URI , pullRequestManager , identity1 , prModel1 ) ;
142183
143- assert . strictEqual ( panel0 , PullRequestOverviewPanel . currentPanel ) ;
144- assert . strictEqual ( createWebviewPanel . callCount , 1 ) ;
145- assert . strictEqual ( panel0 ! . getCurrentTitle ( ) , 'Pull Request #2000' ) ;
184+ const panel1 = PullRequestOverviewPanel . findPanel ( identity1 . owner , identity1 . repo , identity1 . number ) ;
185+ assert . notStrictEqual ( panel1 , undefined ) ;
186+ assert . notStrictEqual ( panel0 , panel1 ) ;
187+ assert . strictEqual ( createWebviewPanel . callCount , 2 ) ;
188+ assert . strictEqual ( panel0 ! . getCurrentTitle ( ) , 'Pull Request #1000' ) ;
189+ assert . strictEqual ( panel1 ! . getCurrentTitle ( ) , 'Pull Request #2000' ) ;
146190 } ) ;
147191 } ) ;
148192} ) ;
0 commit comments