44 */
55
66import assert from 'assert'
7+ import * as sinon from 'sinon'
78import { RegionSubmenu } from '../../../../shared/ui/common/regionSubmenu'
89import { DataQuickPickItem , QuickPickPrompter } from '../../../../shared/ui/pickerPrompter'
910import { createQuickPickPrompterTester } from '../../../shared/ui/testUtils'
@@ -12,7 +13,7 @@ describe('regionSubmenu', function () {
1213 let submenuPrompter : RegionSubmenu < string >
1314
1415 const region1Data = [ 'option1a' , 'option2a' , 'option3a' ]
15- const region2Data = [ 'option1b' , 'option2b' , 'option3b' ]
16+ let region2Data = [ 'option1b' , 'option2b' , 'option3b' ]
1617
1718 before ( async function ( ) {
1819 const mockDataProvider = function ( regionCode : string ) {
@@ -64,4 +65,34 @@ describe('regionSubmenu', function () {
6465 data : 'option2b' ,
6566 } )
6667 } )
68+
69+ it ( 'only has a refresh button' , function ( ) {
70+ const activeButtons = submenuPrompter . activePrompter ! . quickPick . buttons
71+ assert . strictEqual ( activeButtons . length , 1 )
72+ } )
73+
74+ it ( 'refresh button calls refresh once onClick' , function ( ) {
75+ const refreshButton = submenuPrompter . activePrompter ! . quickPick . buttons [ 0 ]
76+ const refreshStub = sinon . stub ( RegionSubmenu . prototype , 'refresh' )
77+ refreshButton . onClick ! ( )
78+ sinon . assert . calledOnce ( refreshStub )
79+ sinon . restore ( )
80+ } )
81+
82+ it ( 'refresh reloads items' , async function ( ) {
83+ const itemsBeforeLabels = submenuPrompter . activePrompter ! . quickPick . items . map ( ( i ) => i . label )
84+ region2Data = [ 'option1c' , 'option2c' , 'option3c' ]
85+
86+ // Note that onDidChangeBusy event fires with busy=false when we load new items in.
87+ // Since regionSubmenu retroactively adds the default items, they won't be there yet.
88+ // So we don't check for them in test to avoid looking at implementation level details.
89+ submenuPrompter . activePrompter ! . onDidChangeBusy ( ( b : boolean ) => {
90+ if ( ! b ) {
91+ const itemsAfterLabels = submenuPrompter . activePrompter ! . quickPick . items . map ( ( i ) => i . label )
92+ region2Data . forEach ( ( item ) => assert ( itemsAfterLabels . includes ( item ) ) )
93+ assert . notStrictEqual ( itemsBeforeLabels , itemsAfterLabels )
94+ }
95+ } )
96+ submenuPrompter . refresh ( submenuPrompter . activePrompter ! as QuickPickPrompter < any > )
97+ } )
6798} )
0 commit comments