Skip to content

Commit

Permalink
place toggleLog command at menu -> editor/title (#126)
Browse files Browse the repository at this point in the history
* place toggleLog command at menu -> editor/title

* update tests

* YomanUi.toggle - add test

* update version to 0.0.34

Co-authored-by: Stanislav Lvovsky <[email protected]>
  • Loading branch information
tomer-epstein and slavik-lvovsky authored Feb 3, 2020
1 parent 586fb1d commit 2e0a590
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 11 deletions.
1 change: 1 addition & 0 deletions backend/.vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
!package.json
!node_modules
!dist
!resources
out/tests/**
tests/**
27 changes: 25 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "Apache 2.0",
"description": "Provide rich user experience for Yeoman generators using VSCode extension or the browser",
"repository": "https://github.com/SAP/yeoman-ui",
"version": "0.0.33",
"version": "0.0.34",
"engines": {
"vscode": "^1.39.2"
},
Expand All @@ -22,8 +22,31 @@
{
"command": "loadYeomanUI",
"title": "Yeoman UI Generators"
},
{
"command": "yeomanUI.toggleLog",
"title": "Toggle Log",
"icon": {
"light": "./resources/images/icons/console_light.svg",
"dark": "./resources/images/icons/console_dark.svg"
}
}
]
],
"menus": {
"commandPalette": [
{
"command": "yeomanUI.toggleLog",
"when": "false"
}
],
"editor/title": [
{
"command": "yeomanUI.toggleLog",
"group": "navigation",
"when": "yeomanUI.Focused"
}
]
}
},
"scripts": {
"backend": "npm install && npm run compile",
Expand Down
5 changes: 5 additions & 0 deletions backend/resources/images/icons/console_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions backend/resources/images/icons/console_light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions backend/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ export function activate(context: vscode.ExtensionContext) {
const messages = _.get(options, "messages");
YeomanUIPanel.createOrShow(context.extensionPath, GeneratorFilter.create(genFilter), messages);
}));
context.subscriptions.push(
vscode.commands.registerCommand('yeomanUI.toggleLog', () => {
const yeomanUi = _.get(YeomanUIPanel, "currentPanel.yeomanui");
if (yeomanUi) {
yeomanUi.toggleLog();
}
}));


if (vscode.window.registerWebviewPanelSerializer) {
// Make sure we register a serializer in activation event
Expand Down Expand Up @@ -97,6 +105,9 @@ export class YeomanUIPanel {
// Set the webview's initial html content
this._update();

// Set the context (yeoman-ui is focused)
vscode.commands.executeCommand('setContext', 'yeomanUI.Focused', this.panel.active);

// Listen for when the panel is disposed
// This happens when the user closes the panel or when the panel is closed programatically
this.panel.onDidDispose(() => this.dispose(), null, this.disposables);
Expand All @@ -107,6 +118,7 @@ export class YeomanUIPanel {
if (this.panel.visible) {
this._update();
}
vscode.commands.executeCommand('setContext', 'yeomanUI.Focused', this.panel.active);
},
null,
this.disposables
Expand Down
19 changes: 16 additions & 3 deletions backend/tests/extension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { expect } from "chai";
import * as sinon from "sinon";
import * as _ from "lodash";
import { mockVscode } from "./mockUtil";
import { GeneratorFilter } from "../src/filter";

const oRegisteredCommands = {};
const testVscode = {
Expand All @@ -21,6 +20,7 @@ describe('extension unit test', () => {
let commandsMock: any;
let windowMock: any;
let yeomanUiPanelMock: any;
let yeomanUiMock: any;

before(() => {
sandbox = sinon.createSandbox();
Expand All @@ -34,12 +34,15 @@ describe('extension unit test', () => {
commandsMock = sandbox.mock(testVscode.commands);
windowMock = sandbox.mock(testVscode.window);
yeomanUiPanelMock = sandbox.mock(extension.YeomanUIPanel);
_.set(extension.YeomanUIPanel, "currentPanel.yeomanui", {toggleLog: () => {}});
yeomanUiMock = sandbox.mock(extension.YeomanUIPanel.currentPanel.yeomanui);
});

afterEach(() => {
commandsMock.verify();
windowMock.verify();
yeomanUiPanelMock.verify();
yeomanUiMock.verify();
});

describe('activate', () => {
Expand All @@ -50,8 +53,11 @@ describe('extension unit test', () => {

it("commands registration", () => {
extension.activate(testContext);
expect(_.size(_.keys(oRegisteredCommands))).to.be.equal(1);
expect(_.keys(oRegisteredCommands)[0]).to.be.equal("loadYeomanUI");
expect(_.size(_.keys(oRegisteredCommands))).to.be.equal(2);
// tslint:disable-next-line: no-unused-expression
expect( _.get(oRegisteredCommands, "loadYeomanUI")).to.be.not.undefined;
// tslint:disable-next-line: no-unused-expression
expect(_.get(oRegisteredCommands, "yeomanUI.toggleLog")).to.be.not.undefined;
});

it("execution loadYeomanUI command", () => {
Expand All @@ -60,5 +66,12 @@ describe('extension unit test', () => {
yeomanUiPanelMock.expects("createOrShow").withArgs(testContext.extensionPath);
loadYeomanUICommand();
});

it("execution yeomanui.toggleLog command", () => {
extension.activate(testContext);
const yeomanUIToggleLogCommand = _.get(oRegisteredCommands, "yeomanUI.toggleLog");
yeomanUiMock.expects("toggleLog");
yeomanUIToggleLogCommand();
});
});
});
2 changes: 1 addition & 1 deletion frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
:selectedGeneratorHeader="selectedGeneratorHeader"
:stepName="prompts[promptIndex].name"
:rpc="rpc"
:isInVsCode="isInVsCode()"
@parentShowConsole="toggleConsole"
/>
<v-row class="main-row ma-0 pa-0">
Expand All @@ -27,7 +28,6 @@
v-if="isDone"
:doneMessage="doneMessage"
:donePath="donePath"
:isInVsCode="isInVsCode()"
/>
<v-slide-x-transition v-else-if="prompts.length">
<Step
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Done.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
export default {
name: "Done",
props: ["doneMessage", "donePath", "isInVsCode"],
props: ["doneMessage", "donePath"],
methods: {
// ISSUE: workbench.action.addRootFolder doesn't get params.
// openCurrentWorkspace(event) {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<v-app-bar class="elevation-0">
<v-toolbar-title>{{selectedGeneratorHeader}}</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn @click="collapseLog" icon>
<v-btn v-if="!isInVsCode" @click="collapseLog" icon>
<v-icon>mdi-console</v-icon>
</v-btn>
</v-app-bar>
Expand All @@ -13,7 +13,7 @@
<script>
export default {
name: "Header",
props: ["selectedGeneratorHeader", "stepName", "rpc"],
props: ["selectedGeneratorHeader", "stepName", "isInVsCode", "rpc"],
methods: {
collapseLog() {
this.rpc.invoke("toggleLog", [{}]);
Expand Down
2 changes: 1 addition & 1 deletion frontend/tests/components/Done.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Done.vue', () => {

test('component props', () => {
wrapper = initComponent(Done)
expect(_.keys(wrapper.props())).toHaveLength(3)
expect(_.keys(wrapper.props())).toHaveLength(2)
})

test('doneMessage set', () => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/tests/components/Header.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('Header.vue', () => {

test('component props', () => {
wrapper = initComponent(Header)
expect(_.keys(wrapper.props())).toHaveLength(3)
expect(_.keys(wrapper.props())).toHaveLength(4)
})

test('generator brand', () => {
Expand Down

0 comments on commit 2e0a590

Please sign in to comment.