forked from aws/aws-toolkit-vscode
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request aws#100 from aws/steveataws/functionnode_icon_fix
Fix up function node to show icon.
- Loading branch information
Showing
5 changed files
with
131 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters