Skip to content

Commit

Permalink
final changes to tests before release.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Mulholland committed Feb 28, 2018
1 parent 474b430 commit 8689133
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 78 deletions.
3 changes: 1 addition & 2 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@
]
}
},
"plugins": ["transform-runtime"],
"sourceMaps": "inline"
"plugins": ["transform-runtime"]
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"datapackage": "^1.0.5",
"escape-regexp": "^0.0.1",
"etl": "^0.5.8",
"fs-extra": "^5.0.0",
"fs-extra": "~5.0.0",
"handsontable": "^0.34.5",
"imports-loader": "^0.7.1",
"lodash": "^4.17.4",
Expand All @@ -94,6 +94,7 @@
"rxjs": "^5.5.2",
"slug": "^0.9.1",
"sortablejs": "^1.6.0",
"spectron-fake-dialog": "^0.0.1",
"svgo": "^1.0.0",
"tableschema": "^1.7.0",
"temp": "^0.8.3",
Expand Down Expand Up @@ -171,7 +172,6 @@
"sinon-chai": "^2.14.0",
"sinon-test": "^2.1.2",
"spectron": "^3.7.1",
"spectron-fake-dialog": "^0.0.1",
"spectron-fake-menu": "^0.0.1",
"style-loader": "^0.18.1",
"stylus": "^0.54.5",
Expand Down
3 changes: 3 additions & 0 deletions src/main/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ function openFile(format) {
Dialog.showOpenDialog({
filters: format.filters
}, function(filenames) {
if (process.env.BABEL_ENV === 'test') {
global.openFileDialogReturned = filenames
}
if (filenames === undefined || filenames.length === 0) {
return
}
Expand Down
28 changes: 14 additions & 14 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ function createWindow() {
}
}

// const isSecondInstance = app.makeSingleInstance((commandLine, workingDirectory) => {
// // Someone tried to run a second instance, we should focus our window.
// console.log('Attempted to open a second instance. Disallowing...')
// let firstWindow = BrowserWindow.getAllWindows()[0]
// if (firstWindow) {
// if (firstWindow.isMinimized()) { firstWindow.restore() }
// firstWindow.focus()
// }
// })
//
// if (isSecondInstance) {
// console.log('Data curator is already open. Quitting this application.')
// app.quit()
// }
const isSecondInstance = app.makeSingleInstance((commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
console.log('Attempted to open a second instance. Disallowing...')
let firstWindow = BrowserWindow.getAllWindows()[0]
if (firstWindow) {
if (firstWindow.isMinimized()) { firstWindow.restore() }
firstWindow.focus()
}
})

if (isSecondInstance) {
console.log('Data curator is already open. Quitting this application.')
app.quit()
}

// app.on('activate', checkForMultipleWindows)

Expand Down
36 changes: 36 additions & 0 deletions src/main/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,39 @@ export function quitOrSaveDialog(event, endButtonName, callback) {
}
})
}

export function testMenu() {
clickLabelsOnMenu()
}

ipc.on('clickLabelsOnMenu', async function(event, arg) {
let returned = await promiseClickLabelsOnMenu()
event.returnValue = returned
// menu = subMenu
// }
})

function promiseClickLabelsOnMenu() {
return new Promise((resolve, reject) => {
// There is a short render wait in home page, so if hotId not first returned, just wait and try again
resolve(clickLabelsOnMenu())
})
}

function clickLabelsOnMenu() {
// console.log(arg) // prints "ping"
// console.log('args are')
// console.log(args)
// let menuLabel = args.shift()
let menu = Menu.getApplicationMenu().items.find(x => x.label === 'File')
// console.log(menu.submenu.items)
menu.click()
// for (subMenuLabel of args) {
let subMenu = menu.submenu.items.find(x => x.label === 'Open')
// console.log(subMenu.submenu.items)
subMenu.click()
let subSubMenu = subMenu.submenu.items.find(x => x.label.startsWith('Comma'))
// console.log(subSubMenu)
subSubMenu.click()
return subSubMenu.label
}
9 changes: 5 additions & 4 deletions test/features/edit/insert-row-below.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ Feature: Insert Row Below
Scenario: Insert Row Below
Given I have opened Data Curator
And The table has 1 row by 3 columns
And I click in row 1, column 1
When I click in row 1, column 1
And I right-click
Then I invoke the "Insert Row Below" command
Then I click on "Insert Row Below"
And The table should have 2 rows by 3 columns
Then I should see a new row below the current row
And I should see the cursor in the first column
And I should see 1 new row below the current row
And I should see 3 columns
And I should see the cursor in row 2, column 1
15 changes: 7 additions & 8 deletions test/features/file/open-comma-separated-file.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ Feature: Open a Comma separated value file
- "Guess Column Properties" on open

@latest
@impl
Scenario: Open an existing comma separated value file
Given I have opened Data Curator
When I click on the File menu
# Then a prompt, requesting the 'filename' and 'location' is shown
# And only files ending with a ".csv" can be selected
# And the selected 'filename' is opened in a new data tab to the right of any other open data tabs
# And set the Tab name to the 'filename'
# And set the CSV Dialect in the Table Properties to "Comma Separated"
# And "Fix Ragged Rows"
# And "Freeze Header Row"
When I click on the "File"->"Open"->"Comma separated..." menu
Then I should see the openfile dialog
And another tab is opened with its filename as the title
And set the CSV Dialect in the Table Properties to "Comma Separated"
And "Fix Ragged Rows"
And "Freeze Header Row"
16 changes: 7 additions & 9 deletions test/features/support/edit/insert_row_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,28 @@ When(/^I right-click$/, function () {
let app = this.app
return this.app.client
.rightClick('.ht_master table')
.then(function() {
app.webContents.send('clickInsertRowBelow')
})
})

Then(/^I invoke the "Insert Row Below" command$/, function () {
Then(/^I click on "Insert Row Below"$/, function () {
return this.app
.webContents.send('clickLabelOnContextMenu', 'Insert row below')
})

Then(/^I should see a new row below the current row$/, function () {
Then(/^I should see (\d+) new row[s]? below the current row$/, function (numberOfNewRows) {
let worldRowNumber = this.rowNumber
return this.app.client
.element('.editor.handsontable')
.elements('.ht_master table tr th')
.then(function(response) {
expect(response.value.length).to.equal(this.rowNumber + 1)
expect(response.value.length).to.equal(worldRowNumber + numberOfNewRows)
})
})

Then(/^I should see the cursor in the first column$/, function () {
Then(/^I should see (\d+) columns$/, function (numberOfColumns) {
return this.app.client
.element('.editor.handsontable')
.elements('.ht_master table tr td.current.highlight')
.elements('.ht_master table tr:first-child td')
.then(function(response) {
expect(response.value.length).to.equal(this.colNumber)
expect(response.value.length).to.equal(numberOfColumns)
})
})
4 changes: 2 additions & 2 deletions test/features/support/file/new_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Then(/^The table should be empty$/, function () {
})
})

Then(/^The cursor should be in row (\d+), column (\d+)$/, function (rowNumber, colNumber) {
Then(/^(?:The cursor should be|I should see the cursor) in row (\d+), column (\d+)$/, function (rowNumber, colNumber) {
return this.app.client.element('.editor.handsontable')
.getAttribute('.ht_master table tr th', 'class')
.then(function(response) {
Expand All @@ -79,7 +79,7 @@ Then(/^The cursor should be in row (\d+), column (\d+)$/, function (rowNumber, c
throw new Error(`There is only 1 row in the table, but the test tried to look for row number: ${rowNumber}`)
}
})
.getAttribute('.ht_master table tr td', 'class')
.getAttribute(`.ht_master table tr:nth-child(${rowNumber}) td`, 'class')
.then(function(response) {
const selectedCellClass = 'current highlight'
// when only 1 value returned no longer an array
Expand Down
18 changes: 5 additions & 13 deletions test/features/support/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,23 @@ import electron from 'electron'
import {After, Before, Status, Given, When, Then} from 'cucumber'
import fakeDialog from 'spectron-fake-dialog'
import { expect, should, assert } from 'chai'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
import fs from 'fs'
chai.should()
chai.use(chaiAsPromised)

After({timeout: 10000}, async function (testCase) {
if (testCase.result.status === Status.FAILED) {
const imageBuffer = await this.app.browserWindow.capturePage()
await this.attach(imageBuffer, 'image/png')
}
if (this.app && this.app.isRunning()) {
// console.log('trying to check for screenshot and stop')
await this.app.stop()
}
})

Before({timeout: 10000}, function () {
Before({timeout: 10000}, async function () {
this.rowNumber = null
this.colNumber = null
fakeDialog.apply(this.app)
chaiAsPromised.transferPromiseness = this.app.transferPromiseness
return this.app.start()
.then(function() {
// Auto-close message dialog : 1 = Quit (No Cancel No save)
fakeDialog.mock([ { method: 'showMessageBox', value: 1 } ])
})
await this.app.start()
// Auto-close message dialog : 1 = Quit (No Cancel No save)
fakeDialog.mock([ { method: 'showMessageBox', value: 1 } ])
fakeDialog.mock([ { method: 'showOpenDialog', value: this.openFileDialogReturned } ])
})
47 changes: 24 additions & 23 deletions test/features/support/tools/menu_steps.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
import { expect, should, assert } from 'chai'
import { Given, When, Then, After, Before} from 'cucumber'
import fakeMenu from 'spectron-fake-menu'
import {fileFormats} from '../../../../src/renderer/file-formats.js'
const _ = require('lodash')

Before({timeout: 10000}, function () {
fakeMenu.apply(this.app)
this.fakeMenu = fakeMenu
When(/^I click on the "([\w]+?)"->"([\w]+?)" menu/, async function (menuLabel, subMenuLabel) {
let returned = await this.app.electron.ipcRenderer.sendSync('clickLabelsOnMenu', [menuLabel, subMenuLabel])
expect(returned).to.equal(subMenuLabel)
})

When(/^I click on the ([\w]+?) menu/, function (menuLabel) {
return this.app
.client.waitUntilWindowLoaded()
.getWindowCount().should.eventually.have.at.least(1)
.electron
.Menu
.getApplicationMenu()
.then(function(menu) {
console.log('entered menu')
// let menu1 = getMenuFromLabel(menu, menuLabel)
// let submenu = getSubMenuFromMenu(menu1, subMenuLabels)
// submenu.click()
})
// 3rd menu may contain spaces, dots
When(/^I click on the "([\w]+?)"->"([\w]+?)"->"([\w \.]+?)" menu/, async function (menuLabel, subMenuLabel, subSubMenuLabel) {
let returned = await this.app.electron.ipcRenderer.sendSync('clickLabelsOnMenu', [menuLabel, subMenuLabel, subSubMenuLabel])
expect(returned).to.equal(subSubMenuLabel)
})

function getMenuFromLabel(menu, menuLabel) {
return menu.items.find(function(x) { x.label === menuLabel })
}
Then('I should see the openfile dialog', async function () {
let globalNames = await this.app
.electron
.remote
.getGlobal('openFileDialogReturned')
console.log(globalNames)
expect(globalNames).to.deep.equal(this.openFileDialogReturned)
})

function getSubMenuFromMenu(menu, subMenuLabel) {
return menu.submenu.items.find(function(x) { x.label === subMenuLabel })
}
Then('another tab is opened with its filename as the title', async function () {
let filePath = require('path').join(__dirname, '../../../fixtures/valid.csv')
await this.app.electron.ipcRenderer.send('openFileIntoTab', filePath, fileFormats.csv)
let text = await this.app.client
.timeouts('implicit', 3000)
.getText('#tab1')
expect(text).to.equal('valid')
})
7 changes: 7 additions & 0 deletions test/features/support/world.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import {setWorldConstructor} from 'cucumber'
import {Application} from 'spectron'
import electron from 'electron'
// import fakeDialog from 'spectron-fake-dialog'
import chai from 'chai'
import chaiAsPromised from 'chai-as-promised'
chai.should()
chai.use(chaiAsPromised)

function CustomWorld({attach, parameters}) {
this.attach = attach
Expand All @@ -13,6 +18,8 @@ function CustomWorld({attach, parameters}) {
})
this.rowNumber = null
this.colNumber = null
this.openFileDialogReturned = ['stubbedFilenameForMenuSteps.txt']
chaiAsPromised.transferPromiseness = this.app.transferPromiseness
}

setWorldConstructor(CustomWorld)
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4324,7 +4324,7 @@ fs-extra@^4.0.1:
jsonfile "^4.0.0"
universalify "^0.1.0"

fs-extra@^5.0.0:
fs-extra@^5.0.0, fs-extra@~5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-5.0.0.tgz#414d0110cdd06705734d055652c5411260c31abd"
dependencies:
Expand Down

0 comments on commit 8689133

Please sign in to comment.