Skip to content

Commit 44af406

Browse files
committed
fix tests from merge
1 parent ac2b8da commit 44af406

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

src/ec2/prompter.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@ export interface Ec2Selection {
2020
export class Ec2Prompter {
2121
public constructor(protected filter?: instanceFilter) {}
2222

23-
protected static asQuickPickItem(instance: Ec2Instance): DataQuickPickItem<string> {
23+
public static getLabel(instance: Ec2Instance): string {
2424
const icon = `$(${getIconCode(instance)})`
25+
return `${instance.name ?? '(no name)'} \t ${icon} ${instance.status!.toUpperCase()}`
26+
}
27+
28+
protected static asQuickPickItem(instance: Ec2Instance): DataQuickPickItem<string> {
2529
return {
26-
label: `${instance.name ?? '(no name)'} \t ${icon} ${instance.status!.toUpperCase()}`,
30+
label: this.getLabel(instance),
2731
detail: instance.InstanceId,
2832
data: instance.InstanceId,
2933
}

src/test/ec2/explorer/ec2ParentNode.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ describe('ec2ParentNode', function () {
5858
beforeEach(function () {
5959
getInstanceStub = sinon.stub(Ec2Client.prototype, 'getInstances')
6060
defaultInstances = [
61-
{ name: 'firstOne', InstanceId: '0' },
62-
{ name: 'secondOne', InstanceId: '1' },
61+
{ name: 'firstOne', InstanceId: '0', status: 'running' },
62+
{ name: 'secondOne', InstanceId: '1', status: 'stopped' },
6363
]
6464

6565
testNode = new Ec2ParentNode(testRegion, testPartition, client)

src/test/ec2/prompter.test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ describe('Ec2Prompter', async function () {
5757
InstanceId: 'testInstanceId',
5858
status: 'running',
5959
}
60+
const icon = `$(${getIconCode(testInstance)})`
6061

6162
const result = prompter.testAsQuickPickItem(testInstance)
6263
const expected = {
63-
label: `$(${getIconCode(testInstance)}) \t ${testInstance.name}`,
64+
label: `${testInstance.name ?? '(no name)'} \t ${icon} ${testInstance.status!.toUpperCase()}`,
6465
detail: testInstance.InstanceId,
6566
data: testInstance.InstanceId,
6667
}
@@ -71,11 +72,12 @@ describe('Ec2Prompter', async function () {
7172
const testInstance = {
7273
InstanceId: 'testInstanceId',
7374
status: 'running',
75+
name: 'testInstance',
7476
}
7577

7678
const result = prompter.testAsQuickPickItem(testInstance)
7779
const expected = {
78-
label: `$(${getIconCode(testInstance)}) \t (no name)`,
80+
label: Ec2Prompter.getLabel(testInstance),
7981
detail: testInstance.InstanceId,
8082
data: testInstance.InstanceId,
8183
}
@@ -144,17 +146,17 @@ describe('Ec2Prompter', async function () {
144146
it('returns items mapped to QuickPick items without filter', async function () {
145147
const expected = [
146148
{
147-
label: `$(${getIconCode(prompter.instances[0])}) \t ${prompter.instances[0].name!}`,
149+
label: Ec2Prompter.getLabel(prompter.instances[0]),
148150
detail: prompter.instances[0].InstanceId!,
149151
data: prompter.instances[0].InstanceId!,
150152
},
151153
{
152-
label: `$(${getIconCode(prompter.instances[1])}) \t ${prompter.instances[1].name!}`,
154+
label: Ec2Prompter.getLabel(prompter.instances[1]),
153155
detail: prompter.instances[1].InstanceId!,
154156
data: prompter.instances[1].InstanceId!,
155157
},
156158
{
157-
label: `$(${getIconCode(prompter.instances[2])}) \t ${prompter.instances[2].name!}`,
159+
label: Ec2Prompter.getLabel(prompter.instances[2]),
158160
detail: prompter.instances[2].InstanceId!,
159161
data: prompter.instances[2].InstanceId!,
160162
},
@@ -169,12 +171,12 @@ describe('Ec2Prompter', async function () {
169171

170172
const expected = [
171173
{
172-
label: `$(${getIconCode(prompter.instances[0])}) \t ${prompter.instances[0].name!}`,
174+
label: Ec2Prompter.getLabel(prompter.instances[0]),
173175
detail: prompter.instances[0].InstanceId!,
174176
data: prompter.instances[0].InstanceId!,
175177
},
176178
{
177-
label: `$(${getIconCode(prompter.instances[2])}) \t ${prompter.instances[2].name!}`,
179+
label: Ec2Prompter.getLabel(prompter.instances[2]),
178180
detail: prompter.instances[2].InstanceId!,
179181
data: prompter.instances[2].InstanceId!,
180182
},

0 commit comments

Comments
 (0)