From 84b3186118ca89d6f7f5ae8064fa862fcd0db70f Mon Sep 17 00:00:00 2001 From: Matthew Mulholland Date: Wed, 21 Feb 2018 09:12:41 +1000 Subject: [PATCH 01/16] Initial working poc for cucumber with spectron. --- features/support/hooks.js | 32 +++ features/support/steps.js | 34 +++ features/support/world.js | 23 ++ features/test.feature | 15 + package.json | 11 +- src/main/index.js | 10 +- src/renderer/components/Home.vue | 13 +- src/renderer/dialect.js | 1 + test/e2e/specs/GuessColumnProperties.spec.js | 21 ++ test/e2e/utils.js | 7 +- yarn.lock | 288 +++++++++++++++++-- 11 files changed, 427 insertions(+), 28 deletions(-) create mode 100644 features/support/hooks.js create mode 100644 features/support/steps.js create mode 100644 features/support/world.js create mode 100644 features/test.feature create mode 100644 test/e2e/specs/GuessColumnProperties.spec.js diff --git a/features/support/hooks.js b/features/support/hooks.js new file mode 100644 index 000000000..207c116d3 --- /dev/null +++ b/features/support/hooks.js @@ -0,0 +1,32 @@ +var Application = require('spectron').Application +var electron = require('electron') +var { After, Before } = require('cucumber') +var fakeDialog = require('spectron-fake-dialog') + +process.env.BABEL_ENV = 'test' + +// Enable use of ES6+ on required files +require('babel-register')({ + ignore: /node_modules/ +}) + +After({timeout: 10000}, function () { + if (this.app && this.app.isRunning()) { + return this.app.stop() + } +}) + +Before({timeout: 10000}, function () { + // this.app = new Application({ + // path: electron, + // args: ['dist/electron/main.js'], + // startTimeout: 10000, + // waitTimeout: 10000 + // }) + // fakeDialog.apply(this.app) + // return this.app.start() + // .then(() => + // // 1 = Quit (No Cancel No save) + // fakeDialog.mock([ { method: 'showMessageBox', value: 1 } ]) + // ) +}) diff --git a/features/support/steps.js b/features/support/steps.js new file mode 100644 index 000000000..9e6ba1599 --- /dev/null +++ b/features/support/steps.js @@ -0,0 +1,34 @@ +const { Given, When, Then} = require('cucumber') +const { expect, should, assert } = require('chai') +var fakeDialog = require('spectron-fake-dialog') +var Application = require('spectron').Application +var electron = require('electron') + +Given(/^I have opened Data Curator$/, function () { + this.app = new Application({ + path: electron, + args: ['dist/electron/main.js'], + startTimeout: 10000, + waitTimeout: 10000 + }) + fakeDialog.apply(this.app) + return this.app.start() + .then(() => + // 1 = Quit (No Cancel No save) + fakeDialog.mock([ { method: 'showMessageBox', value: 1 } ]) + ) +}) + +When(/^I invoke the Guess Column Properties command$/, function () { + return this.app.client.waitForVisible('#toolbar') + .element('#guess-column-properties') + .click() +}) + +Then(/^I should see the success message$/, function () { + return this.app.client.waitForVisible('#message-panel', 1000) + .getText('#error-message') + .then(text => { + expect(text).to.equal('Success: Guess column properties succeeded.') + }) +}) diff --git a/features/support/world.js b/features/support/world.js new file mode 100644 index 000000000..b51b346df --- /dev/null +++ b/features/support/world.js @@ -0,0 +1,23 @@ +var { setWorldConstructor } = require('cucumber') +var Application = require('spectron').Application +var electron = require('electron') + +// setWorldConstructor(function () { +// this.app = new Application({ +// path: electron, +// args: ['dist/electron/main.js'], +// startTimeout: 10000, +// waitTimeout: 10000 +// }) +// }) + +// function CustomWorld() { +// this.app = new Application({ +// path: electron, +// args: ['dist/electron/main.js'], +// startTimeout: 10000, +// waitTimeout: 10000 +// }) +// } +// +// setWorldConstructor(CustomWorld) diff --git a/features/test.feature b/features/test.feature new file mode 100644 index 000000000..57085d7a1 --- /dev/null +++ b/features/test.feature @@ -0,0 +1,15 @@ +Feature: Guess Column Properties + As a Data Packager + I want to derive as many column properties as possible from the data and the CSV dialect + So that I can quickly set the column properties + + The "Guess Column Properties" command can be invoked using a menu item or a toolbar button + + Read the first 100 rows of the data and for each column, infer the data type and format and set the 'type' and 'format' property values to the inferred values. + + If column properties already exist for the guessed properties, then prompt the user to ask if they should be over-written. + + Scenario: Guess column properties + Given I have opened Data Curator + When I invoke the Guess Column Properties command + Then I should see the success message diff --git a/package.json b/package.json index 3c7c4f123..deb89d9e3 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,9 @@ "test-main": "mocha-webpack --webpack-config .electron-vue/webpack.test.config.js --glob *_spec.js test/main/specs", "test": "yarn run unit && yarn run e2e", "unit": "karma start test/unit/karma.conf.js", - "e2e": "yarn run pack && mocha test/e2e" + "e2e": "yarn run pack && mocha test/e2e", + "cucumber:full": "yarn run pack && cucumber-js", + "cucumber": "cucumber-js" }, "build": { "productName": "DataCurator", @@ -86,6 +88,7 @@ "moment": "^2.19.1", "pikaday": "^1.6.1", "pouchdb-adapter-idb": "^6.3.4", + "remove": "^0.1.5", "request": "^2.81.0", "rxjs": "^5.5.2", "slug": "^0.9.1", @@ -115,14 +118,16 @@ "babel-polyfill": "^6.26.0", "babel-preset-env": "^1.6.1", "babel-preset-stage-0": "^6.5.0", - "babel-register": "^6.2.0", + "babel-register": "^6.26.0", "babili-webpack-plugin": "^0.1.1", "cfonts": "^1.1.3", "chai": "^4.0.0", + "chai-as-promised": "^7.1.1", "chalk": "^2.3.0", "copy-webpack-plugin": "^4.2.0", "cross-env": "^5.0.0", "css-loader": "^0.28.4", + "cucumber": "^4.0.0", "del": "^3.0.0", "devtron": "^1.1.0", "electron": "^1.7.11", @@ -147,6 +152,7 @@ "json-loader": "^0.5.4", "karma": "^1.7.1", "karma-chai": "^0.1.0", + "karma-chai-as-promised": "^0.1.2", "karma-coverage": "^1.1.1", "karma-electron": "^5.2.1", "karma-mocha": "^1.2.0", @@ -162,6 +168,7 @@ "sinon-chai": "^2.14.0", "sinon-test": "^2.1.2", "spectron": "^3.7.1", + "spectron-fake-dialog": "^0.0.1", "style-loader": "^0.18.1", "stylus": "^0.54.5", "stylus-loader": "^3.0.1", diff --git a/src/main/index.js b/src/main/index.js index 8df9f3c63..46913aa32 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -56,11 +56,11 @@ function closeAppNoPrompt() { app.exit() } -if (process.env.NODE_ENV === 'production') { - app.on('before-quit', (event) => { - quitOrSaveDialog(event, 'Quit', closeAppNoPrompt) - }) -} +// if (process.env.NODE_ENV === 'production') { +app.on('before-quit', (event) => { + quitOrSaveDialog(event, 'Quit', closeAppNoPrompt) +}) +// } app.on('window-all-closed', () => { if (process.platform !== 'darwin') { diff --git a/src/renderer/components/Home.vue b/src/renderer/components/Home.vue index f1cd8c035..6b91a3077 100644 --- a/src/renderer/components/Home.vue +++ b/src/renderer/components/Home.vue @@ -13,7 +13,7 @@