Integration test: add existing torrent

This commit is contained in:
DC
2016-09-13 22:19:52 -07:00
parent 62c5b78358
commit 051c1516a0
12 changed files with 72 additions and 20 deletions

View File

@@ -21,12 +21,7 @@ function openSeedFile () {
title: 'Select a file for the torrent.', title: 'Select a file for the torrent.',
properties: [ 'openFile' ] properties: [ 'openFile' ]
} }
setTitle(opts.title) showOpenSeed(opts)
electron.dialog.showOpenDialog(windows.main.win, opts, function (selectedPaths) {
resetTitle()
if (!Array.isArray(selectedPaths)) return
windows.main.dispatch('showCreateTorrent', selectedPaths)
})
} }
/* /*
@@ -46,12 +41,7 @@ function openSeedDirectory () {
title: 'Select a folder for the torrent.', title: 'Select a folder for the torrent.',
properties: [ 'openDirectory' ] properties: [ 'openDirectory' ]
} }
setTitle(opts.title) showOpenSeed(opts)
electron.dialog.showOpenDialog(windows.main.win, opts, function (selectedPaths) {
resetTitle()
if (!Array.isArray(selectedPaths)) return
windows.main.dispatch('showCreateTorrent', selectedPaths)
})
} }
/* /*
@@ -119,3 +109,16 @@ function setTitle (title) {
function resetTitle () { function resetTitle () {
windows.main.dispatch('resetTitle') windows.main.dispatch('resetTitle')
} }
/**
* Pops up an Open File dialog with the given options.
* After the user selects files / folders, shows the Create Torrent page.
*/
function showOpenSeed (opts) {
setTitle(opts.title)
electron.dialog.showOpenDialog(windows.main.win, opts, function (selectedPaths) {
resetTitle()
if (!Array.isArray(selectedPaths)) return
windows.main.dispatch('showCreateTorrent', selectedPaths)
})
}

View File

@@ -147,8 +147,14 @@ function onAppOpen (newArgv) {
} }
} }
// Remove leading args.
// Production: 1 arg, eg: /Applications/WebTorrent.app/Contents/MacOS/WebTorrent
// Development: 2 args, eg: electron .
// Test: 4 args, eg: electron -r .../mocks.js .
function sliceArgv (argv) { function sliceArgv (argv) {
return argv.slice(config.IS_PRODUCTION ? 1 : 2) return argv.slice(config.IS_PRODUCTION ? 1
: config.IS_TEST ? 4
: 2)
} }
function processArgv (argv) { function processArgv (argv) {

View File

@@ -39,9 +39,10 @@ class ShowMore extends React.Component {
? this.props.hideLabel ? this.props.hideLabel
: this.props.showLabel : this.props.showLabel
return ( return (
<div style={this.props.style}> <div className='show-more' style={this.props.style}>
{this.state.expanded ? this.props.children : null} {this.state.expanded ? this.props.children : null}
<RaisedButton <RaisedButton
className='control'
onClick={this.handleClick} onClick={this.handleClick}
label={label} /> label={label} />
</div> </div>

View File

@@ -15,17 +15,15 @@ test('app runs', function (t) {
const app = setup.createApp() const app = setup.createApp()
setup.waitForLoad(app, t) setup.waitForLoad(app, t)
.then(() => setup.wait()) .then(() => setup.wait())
.then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-basic')) .then(() => setup.screenshotCreateOrCompare(app, t, 'app-basic'))
.then(() => setup.endTest(app, t), .then(() => setup.endTest(app, t),
(err) => setup.endTest(app, t, err || 'error')) (err) => setup.endTest(app, t, err || 'error'))
}) })
console.log('Testing the torrent list (home page)...') // require('./test-torrent-list')
setup.wipeTestDataDir() require('./test-add-torrent')
require('./test-torrent-list')
// TODO: // TODO:
// require('./test-add-torrent')
// require('./test-create-torrent') // require('./test-create-torrent')
// require('./test-prefs') // require('./test-prefs')
// require('./test-video') // require('./test-video')

9
test/mocks.js Normal file
View File

@@ -0,0 +1,9 @@
const path = require('path')
const electron = require('electron')
const MOCK_OPEN_TORRENTS = [path.join(__dirname, 'resources', '1.torrent')]
console.log('Mocking electron native integrations...')
electron.dialog.showOpenDialog = function (win, opts, cb) {
cb(MOCK_OPEN_TORRENTS)
}

BIN
test/resources/1.torrent Normal file

Binary file not shown.

BIN
test/resources/m3.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

View File

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

View File

@@ -24,7 +24,7 @@ function createApp (t) {
return new Application({ return new Application({
path: path.join(__dirname, '..', 'node_modules', '.bin', path: path.join(__dirname, '..', 'node_modules', '.bin',
'electron' + (process.platform === 'win32' ? '.cmd' : '')), 'electron' + (process.platform === 'win32' ? '.cmd' : '')),
args: [path.join(__dirname, '..')], args: ['-r', path.join(__dirname, 'mocks.js'), path.join(__dirname, '..')],
env: {NODE_ENV: 'test'} env: {NODE_ENV: 'test'}
}) })
} }

35
test/test-add-torrent.js Normal file
View File

@@ -0,0 +1,35 @@
const test = require('tape')
const fs = require('fs-extra')
const path = require('path')
const setup = require('./setup')
test('add-torrent', function (t) {
setup.wipeTestDataDir()
t.timeoutAfter(100e3)
const app = setup.createApp()
setup.waitForLoad(app, t)
.then(() => app.client.waitUntilTextExists('.torrent-list', 'Big Buck Bunny'))
// Add an existing torrent. The corresponding file is not present. Should be at 0%
.then(() => app.client.click('.icon.add'))
// The call to dialog.openFiles() is mocked. See mocks.js
.then(() => app.client.waitUntilTextExists('m3.jpg'))
.then(() => setup.screenshotCreateOrCompare(app, t, 'add-torrent-existing-1'))
// Delete the torrent.
.then(() => app.client.moveToObject('.torrent'))
.then(() => setup.wait())
.then(() => app.client.click('.icon.delete'))
.then(() => app.client.waitUntilTextExists('REMOVE'))
.then(() => app.client.click('.control.ok'))
.then(() => setup.wait())
// Add the same existing torrent, this time with the file present. Should be at 100%
.then(() => fs.copySync(
path.join(__dirname, 'resources', 'm3.jpg'),
path.join(setup.TEST_DOWNLOAD_DIR, 'm3.jpg')))
.then(() => app.client.click('.icon.add'))
.then(() => app.client.waitUntilTextExists('m3.jpg'))
.then(() => setup.wait())
.then(() => setup.screenshotCreateOrCompare(app, t, 'add-torrent-existing-2'))
.then(() => setup.endTest(app, t),
(err) => setup.endTest(app, t, err || 'error'))
})