Skip to content

Commit

Permalink
Merge pull request #46 from SAP/App_tests
Browse files Browse the repository at this point in the history
App tests
  • Loading branch information
slavik-lvovsky authored Dec 9, 2019
2 parents ec00f5d + 4d0a5dc commit 5e9e206
Show file tree
Hide file tree
Showing 4 changed files with 328 additions and 61 deletions.
8 changes: 4 additions & 4 deletions frontend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ module.exports = {
],
coverageThreshold: {
"global": {
"branches": 58,
"functions": 76,
"lines": 65,
"statements": 65
"branches": 85,
"functions": 98,
"lines": 94,
"statements": 94
}
}
}
3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"mock-socket": "^9.0.2",
"vue-jest": "^3.0.5",
"vue-template-compiler": "^2.6.10",
"webpack": "^4.41.2"
"webpack": "^4.41.2",
"flush-promises": "^1.0.2"
},
"eslintConfig": {
"root": true,
Expand Down
74 changes: 31 additions & 43 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ import { RpcBrowser } from "@sap-devx/webview-rpc/out.browser/rpc-browser";
import { RpcBrowserWebSockets } from "@sap-devx/webview-rpc/out.browser/rpc-browser-ws";
import * as _ from "lodash"
const FUNCTION = '__Function'
const LOADING = 'loading...'
const PENDING = 'Pending...'
export default {
name: "app",
components: {
Expand Down Expand Up @@ -101,41 +105,35 @@ export default {
const questions = _.get(this.currentPrompt, "questions", []);
_.forEach(questions, question => {
const questionName = question.name
if (question._default === "__Function") {
console.error('question._default - ' + question._default);
if (question._default === FUNCTION) {
this.rpc.invoke("evaluateMethod", [[curentPromptAnswers], questionName, "default"]).then(response => {
question.default = response
if (question.answer === undefined) {
question.answer = question.default
}
})
}
if (question.when === "__Function") {
console.error('question.when - ' + question.when);
if (question.when === FUNCTION) {
this.rpc.invoke("evaluateMethod", [[curentPromptAnswers], questionName, "when"]).then(response => {
question.isWhen = response
})
}
if (question._message === "__Function") {
console.error('question._message - ' + question._message);
if (question._message === FUNCTION) {
this.rpc.invoke("evaluateMethod", [[curentPromptAnswers], questionName, "message"]).then(response => {
question.message = response
})
}
if (question._choices === "__Function") {
console.error('question._choices - ' + question._choices);
if (question._choices === FUNCTION) {
this.rpc.invoke("evaluateMethod", [[curentPromptAnswers], questionName, "choices"]).then(response => {
question.choices = response
})
}
if (question.filter === "__Function") {
console.error('question.filter - ' + question.filter);
if (question.filter === FUNCTION) {
this.rpc.invoke("evaluateMethod", [[question.answer], questionName, "filter"]).then(response => {
question.answer = response
})
}
if (question.validate === "__Function") {
console.error('question.validate - ' + question.validate);
if (question.validate === FUNCTION) {
this.rpc.invoke("evaluateMethod", [[question.answer, curentPromptAnswers], questionName, "validate"]).then(response => {
question.isValid = (_.isString(response) ? false : response)
question.validationMessage = (_.isString(response) ? response : undefined)
Expand All @@ -152,10 +150,11 @@ export default {
this.resolve(this.currentPrompt.answers)
} catch (e) {
this.reject(e)
return
}
}
if (this.promptIndex >= this.prompts.length - 1) {
const prompt = { questions: [], name: "Pending...", status: "pending" }
if (this.promptIndex >= _.size(this.prompts) - 1) {
const prompt = { questions: [], name: PENDING, status: "pending" }
this.setPrompts([prompt])
}
this.promptIndex++
Expand Down Expand Up @@ -184,7 +183,7 @@ export default {
} else {
if (currentPrompt) {
currentPrompt.questions = prompt.questions
if (prompt.name && currentPrompt.name === "Pending...") {
if (prompt.name && currentPrompt.name === PENDING) {
currentPrompt.name = prompt.name
}
// if questions are provided, remote the pending status
Expand All @@ -207,17 +206,17 @@ export default {
setQuestionProps(prompt) {
const questions = _.get(prompt, "questions", [])
_.forEach(questions, question => {
if (question.default === "__Function") {
if (question.default === FUNCTION) {
question.default = undefined
this.$set(question, "_default", "__Function")
this.$set(question, "_default", FUNCTION)
}
if (question.message === "__Function") {
question.message = "loading..."
this.$set(question, "_message", "__Function")
if (question.message === FUNCTION) {
question.message = LOADING
this.$set(question, "_message", FUNCTION)
}
if (question.choices === "__Function") {
question.choices = ["loading..."]
this.$set(question, "_choices", "__Function")
if (question.choices === FUNCTION) {
question.choices = [LOADING]
this.$set(question, "_choices", FUNCTION)
}
let answer = question.default;
Expand Down Expand Up @@ -267,7 +266,7 @@ export default {
this.rpc.invoke("runGenerator", [generatorName])
},
isInVsCode() {
return typeof acquireVsCodeApi !== "undefined"
return typeof acquireVsCodeApi !== 'undefined'
},
setupRpc() {
if (this.isInVsCode()) {
Expand All @@ -284,26 +283,15 @@ export default {
}
},
initRpc() {
this.rpc.registerMethod({
func: this.showPrompt,
thisArg: this,
name: "showPrompt"
})
this.rpc.registerMethod({
func: this.setPrompts,
thisArg: this,
name: "setPrompts"
})
this.rpc.registerMethod({
func: this.generatorDone,
thisArg: this,
name: "generatorDone"
})
this.rpc.registerMethod({
func: this.log,
thisArg: this,
name: "log"
const functions = ["showPrompt", "setPrompts", "generatorDone", "log"]
_.forEach(functions, funcName => {
this.rpc.registerMethod({
func: this[funcName],
thisArg: this,
name: funcName
})
})
this.rpc.invoke("receiveIsWebviewReady", [])
}
},
Expand Down
Loading

0 comments on commit 5e9e206

Please sign in to comment.