Skip to content

Commit

Permalink
Merge pull request aws#100 from aws/steveataws/functionnode_icon_fix
Browse files Browse the repository at this point in the history
Fix up function node to show icon.
  • Loading branch information
Steve Roberts authored Oct 10, 2018
2 parents c5f9933 + b783a89 commit 708d99b
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 31 deletions.
10 changes: 5 additions & 5 deletions src/lambda/explorer/functionNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
'use strict'

import Lambda = require('aws-sdk/clients/lambda')
import * as path from 'path'
import { ThemeIcon, TreeItem, Uri } from 'vscode'
import { TreeItem, Uri } from 'vscode'
import { ext } from '../../shared/extensionGlobals'
import { AWSTreeNodeBase } from '../../shared/treeview/awsTreeNodeBase'

export class FunctionNode extends AWSTreeNodeBase implements TreeItem {
Expand All @@ -16,7 +16,7 @@ export class FunctionNode extends AWSTreeNodeBase implements TreeItem {

public label?: string
public tooltip?: string
public iconPath?: string | Uri | { light: string | Uri; dark: string | Uri } | ThemeIcon
public iconPath?: { light: Uri; dark: Uri }

public constructor(
public readonly functionConfiguration: Lambda.FunctionConfiguration,
Expand All @@ -26,8 +26,8 @@ export class FunctionNode extends AWSTreeNodeBase implements TreeItem {
this.label = `${this.functionConfiguration.FunctionName!}`
this.tooltip = `${this.functionConfiguration.FunctionName}-${this.functionConfiguration.FunctionArn}`
this.iconPath = {
light: path.join(__filename, '..', '..', '..', 'resources', 'light', 'lambda_function.svg'),
dark: path.join(__filename, '..', '..', '..', 'resources', 'dark', 'lambda_function.svg')
dark: Uri.file(ext.context.asAbsolutePath('resources/dark/lambda_function.svg')),
light: Uri.file(ext.context.asAbsolutePath('resources/light/lambda_function.svg'))
}
}

Expand Down
23 changes: 23 additions & 0 deletions src/test/fakeExtensionContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*!
* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

'use strict'

import { ExtensionContext, Memento } from 'vscode'
import { FakeMemento } from './fakeMemento'

export class FakeExtensionContext implements ExtensionContext {
public subscriptions: {
dispose(): any;
}[] = []
public workspaceState: Memento = new FakeMemento()
public globalState: Memento = new FakeMemento()
public extensionPath: string = ''
public storagePath: string | undefined

public asAbsolutePath(relativePath: string): string {
throw new Error('Method not implemented.')
}
}
19 changes: 19 additions & 0 deletions src/test/fakeMemento.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*!
* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

'use strict'

import { Memento } from 'vscode'

export class FakeMemento implements Memento {
public get<T>(key: string): T | undefined
public get<T>(key: string, defaultValue: T): T
public get(key: any, defaultValue?: any) {
throw new Error('Method not implemented.')
}
public update(key: string, value: any): Thenable<void> {
throw new Error('Method not implemented.')
}
}
83 changes: 83 additions & 0 deletions src/test/lambda.Explorer.FunctionNode.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*!
* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

'use strict'

import * as assert from 'assert'
import { Lambda } from 'aws-sdk'
import { Uri } from 'vscode'
import { FunctionNode } from '../lambda/explorer/functionNode'
import { ext } from '../shared/extensionGlobals'
import { FakeExtensionContext } from './fakeExtensionContext'

suite('Lambda Explorer FunctionNode Tests', () => {

let fakeFunctionConfig: Lambda.FunctionConfiguration

class FakeExtensionContextOverride extends FakeExtensionContext {

public asAbsolutePath(relativePath: string): string {
return relativePath
}
}

suiteSetup(function() {
ext.context = new FakeExtensionContextOverride()
fakeFunctionConfig = {
FunctionName: 'testFunctionName',
FunctionArn: 'testFunctionARN'
}
})

// Validates we tagged the node correctly
test('Function node name and tooltip are initialized', async () => {
const testNode = new FunctionNode(fakeFunctionConfig, new Lambda())

assert.equal(testNode.label, fakeFunctionConfig.FunctionName)
assert.equal(testNode.tooltip, `${fakeFunctionConfig.FunctionName}-${fakeFunctionConfig.FunctionArn}`)
})

// Validates we wired up the expected resource for the node icon
test('Function node iconPath member is initialized', async () => {

const fileScheme: string = 'file'
const resourceImageName: string = 'lambda_function.svg'

const testNode = new FunctionNode(fakeFunctionConfig, new Lambda())

const iconPath = testNode.iconPath
assert(iconPath !== undefined)

assert(iconPath!.light !== undefined)
assert(iconPath!.light instanceof Uri)
assert.equal(iconPath!.light.scheme, fileScheme)
const lightResourcePath: string = iconPath!.light.path
assert(lightResourcePath.endsWith(`/light/${resourceImageName}`))

assert(iconPath!.dark !== undefined)
assert(iconPath!.dark instanceof Uri)
assert.equal(iconPath!.dark.scheme, fileScheme)
const darkResourcePath: string = iconPath!.dark.path
assert(darkResourcePath.endsWith(`dark/${resourceImageName}`))
})

// Validates we don't yield some unexpected value that our command triggers
// don't recognize
test('Function node returns expected context value', async () => {
const testNode = new FunctionNode(fakeFunctionConfig, new Lambda())

assert.equal(testNode.contextValue, FunctionNode.contextValue)
})

// Validates function nodes are leaves
test('Function node has no children', async () => {
const testNode = new FunctionNode(fakeFunctionConfig, new Lambda())

const childNodes = await testNode.getChildren()
assert(childNodes !== undefined)
assert.equal(childNodes.length, 0)
})

})
27 changes: 1 addition & 26 deletions src/test/regionHelpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
'use strict'

import * as assert from 'assert'
import * as vscode from 'vscode'
import { DefaultRegionProvider } from '../shared/regions/defaultRegionProvider'
import { ResourceFetcher } from '../shared/resourceFetcher'
import { ResourceLocation } from '../shared/resourceLocation'
import { FakeExtensionContext } from './fakeExtensionContext'

suite('ResourceFetcherBase Tests', function(): void {

Expand All @@ -25,31 +25,6 @@ suite('ResourceFetcherBase Tests', function(): void {
}
}

class FakeMemento implements vscode.Memento {
public get<T>(key: string): T | undefined
public get<T>(key: string, defaultValue: T): T
public get(key: any, defaultValue?: any) {
throw new Error('Method not implemented.')
}
public update(key: string, value: any): Thenable<void> {
throw new Error('Method not implemented.')
}
}

class FakeExtensionContext implements vscode.ExtensionContext {
public subscriptions: {
dispose(): any;
}[] = []
public workspaceState: vscode.Memento = new FakeMemento()
public globalState: vscode.Memento = new FakeMemento()
public extensionPath: string = ''
public storagePath: string | undefined

public asAbsolutePath(relativePath: string): string {
throw new Error('Method not implemented.')
}
}

test('Fetches something', async function() {
const fetchCounter = new ResourceFetcherCounter()
const context = new FakeExtensionContext()
Expand Down

0 comments on commit 708d99b

Please sign in to comment.