Skip to content

Commit 9dc008c

Browse files
authored
Fix unstable quickPickUserOrderedValues test in windows (#4900)
1 parent d65c8b6 commit 9dc008c

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

extension/src/test/suite/util.ts

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
commands,
66
ConfigurationChangeEvent,
77
EventEmitter,
8+
QuickPick,
89
TextEditor,
910
Uri,
1011
window,
@@ -38,6 +39,7 @@ import { Toast } from '../../vscode/toast'
3839
import { GitExecutor } from '../../cli/git/executor'
3940
import { DvcConfig } from '../../cli/dvc/config'
4041
import { ExpShowOutput, PlotsOutput } from '../../cli/dvc/contract'
42+
import { QuickPickItemWithValue } from '../../vscode/quickPick'
4143

4244
export const mockDisposable = {
4345
dispose: stub()
@@ -85,23 +87,46 @@ export const selectQuickPickItem = async (number: number) => {
8587
return commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem')
8688
}
8789

88-
const toggleQuickPickItem = async (number: number, itemsLength: number) => {
90+
type NumberQuickPick = QuickPick<QuickPickItemWithValue<number>>
91+
92+
const getQuickPickSelectionEvent = (
93+
quickPick: NumberQuickPick,
94+
numberInd: number
95+
) =>
96+
new Promise(resolve =>
97+
quickPick.onDidChangeSelection(items => {
98+
const isItemSelected = items[numberInd]
99+
if (isItemSelected) {
100+
resolve(undefined)
101+
}
102+
})
103+
)
104+
105+
const toggleQuickPickItem = async (
106+
number: number,
107+
numberInd: number,
108+
itemsLength: number,
109+
quickPick: NumberQuickPick
110+
) => {
89111
for (let itemInd = 1; itemInd <= itemsLength; itemInd++) {
90112
await commands.executeCommand('workbench.action.quickOpenSelectNext')
91113

92114
if (itemInd === number) {
115+
const selectionEvent = getQuickPickSelectionEvent(quickPick, numberInd)
93116
await commands.executeCommand('workbench.action.quickPickManyToggle')
117+
await selectionEvent
94118
}
95119
}
96120
}
97121

98122
export const selectMultipleQuickPickItems = async (
99123
numbers: number[],
100124
itemsLength: number,
125+
quickPick: NumberQuickPick,
101126
acceptItems = true
102127
) => {
103-
for (const number of numbers) {
104-
await toggleQuickPickItem(number, itemsLength)
128+
for (const [ind, num] of numbers.entries()) {
129+
await toggleQuickPickItem(num, ind, itemsLength, quickPick)
105130
}
106131
if (acceptItems) {
107132
return commands.executeCommand(

extension/src/test/suite/vscode/quickPick.test.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ suite('Quick Pick Test Suite', () => {
144144

145145
describe('quickPickUserOrderedValues', () => {
146146
it('should return selected values in the order that the user selected', async () => {
147+
const quickPick = disposable.track(
148+
window.createQuickPick<QuickPickItemWithValue<number>>()
149+
)
150+
stub(window, 'createQuickPick').returns(quickPick)
147151
const items = [
148152
{ label: 'J', value: 1 },
149153
{ label: 'K', value: 2 },
@@ -156,12 +160,12 @@ suite('Quick Pick Test Suite', () => {
156160
title: 'Select some values' as Title
157161
})
158162

159-
await selectMultipleQuickPickItems([5, 2, 1], items.length)
163+
await selectMultipleQuickPickItems([5, 2, 1], items.length, quickPick)
160164

161165
const result = await resultPromise
162166

163167
expect(result).to.deep.equal([5, 2, 1])
164-
}).timeout(8000)
168+
}).timeout(10000)
165169

166170
it('should return undefined if user cancels the quick pick', async () => {
167171
const quickPick = disposable.track(
@@ -209,7 +213,12 @@ suite('Quick Pick Test Suite', () => {
209213
maxSelectedItems
210214
)
211215

212-
await selectMultipleQuickPickItems([5, 2, 1], items.length, false)
216+
await selectMultipleQuickPickItems(
217+
[5, 2, 1],
218+
items.length,
219+
quickPick,
220+
false
221+
)
213222

214223
expect(
215224
quickPick.selectedItems,
@@ -219,6 +228,6 @@ suite('Quick Pick Test Suite', () => {
219228
quickPick.items,
220229
'all items which could be selected are hidden'
221230
).to.have.lengthOf(maxSelectedItems)
222-
}).timeout(8000)
231+
}).timeout(10000)
223232
})
224233
})

0 commit comments

Comments
 (0)