diff --git a/src/main/dialog.js b/src/main/dialog.js
index f94a53b8..38b9c96b 100644
--- a/src/main/dialog.js
+++ b/src/main/dialog.js
@@ -21,12 +21,7 @@ function openSeedFile () {
title: 'Select a file for the torrent.',
properties: [ 'openFile' ]
}
- setTitle(opts.title)
- electron.dialog.showOpenDialog(windows.main.win, opts, function (selectedPaths) {
- resetTitle()
- if (!Array.isArray(selectedPaths)) return
- windows.main.dispatch('showCreateTorrent', selectedPaths)
- })
+ showOpenSeed(opts)
}
/*
@@ -46,12 +41,7 @@ function openSeedDirectory () {
title: 'Select a folder for the torrent.',
properties: [ 'openDirectory' ]
}
- setTitle(opts.title)
- electron.dialog.showOpenDialog(windows.main.win, opts, function (selectedPaths) {
- resetTitle()
- if (!Array.isArray(selectedPaths)) return
- windows.main.dispatch('showCreateTorrent', selectedPaths)
- })
+ showOpenSeed(opts)
}
/*
@@ -119,3 +109,16 @@ function setTitle (title) {
function 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)
+ })
+}
diff --git a/src/main/index.js b/src/main/index.js
index 8eb62626..02b54228 100644
--- a/src/main/index.js
+++ b/src/main/index.js
@@ -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) {
- return argv.slice(config.IS_PRODUCTION ? 1 : 2)
+ return argv.slice(config.IS_PRODUCTION ? 1
+ : config.IS_TEST ? 4
+ : 2)
}
function processArgv (argv) {
diff --git a/src/renderer/components/show-more.js b/src/renderer/components/show-more.js
index 7df2d55c..bb0084e1 100644
--- a/src/renderer/components/show-more.js
+++ b/src/renderer/components/show-more.js
@@ -39,9 +39,10 @@ class ShowMore extends React.Component {
? this.props.hideLabel
: this.props.showLabel
return (
-
+
{this.state.expanded ? this.props.children : null}
diff --git a/test/index.js b/test/index.js
index 03c96ec3..7373b84f 100644
--- a/test/index.js
+++ b/test/index.js
@@ -15,17 +15,15 @@ test('app runs', function (t) {
const app = setup.createApp()
setup.waitForLoad(app, t)
.then(() => setup.wait())
- .then(() => setup.screenshotCreateOrCompare(app, t, 'torrent-list-basic'))
+ .then(() => setup.screenshotCreateOrCompare(app, t, 'app-basic'))
.then(() => setup.endTest(app, t),
(err) => setup.endTest(app, t, err || 'error'))
})
-console.log('Testing the torrent list (home page)...')
-setup.wipeTestDataDir()
-require('./test-torrent-list')
+// require('./test-torrent-list')
+require('./test-add-torrent')
// TODO:
-// require('./test-add-torrent')
// require('./test-create-torrent')
// require('./test-prefs')
// require('./test-video')
diff --git a/test/mocks.js b/test/mocks.js
new file mode 100644
index 00000000..730d1dbc
--- /dev/null
+++ b/test/mocks.js
@@ -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)
+}
diff --git a/test/resources/1.torrent b/test/resources/1.torrent
new file mode 100644
index 00000000..f83f19e3
Binary files /dev/null and b/test/resources/1.torrent differ
diff --git a/test/resources/m3.jpg b/test/resources/m3.jpg
new file mode 100644
index 00000000..425913a4
Binary files /dev/null and b/test/resources/m3.jpg differ
diff --git a/test/screenshots/darwin/add-torrent-existing-1.png b/test/screenshots/darwin/add-torrent-existing-1.png
new file mode 100644
index 00000000..93a24ac8
Binary files /dev/null and b/test/screenshots/darwin/add-torrent-existing-1.png differ
diff --git a/test/screenshots/darwin/add-torrent-existing-2.png b/test/screenshots/darwin/add-torrent-existing-2.png
new file mode 100644
index 00000000..4b627997
Binary files /dev/null and b/test/screenshots/darwin/add-torrent-existing-2.png differ
diff --git a/test/screenshots/darwin/torrent-list-basic.png b/test/screenshots/darwin/app-basic.png
similarity index 100%
rename from test/screenshots/darwin/torrent-list-basic.png
rename to test/screenshots/darwin/app-basic.png
diff --git a/test/setup.js b/test/setup.js
index 09c582b1..4e6d179c 100644
--- a/test/setup.js
+++ b/test/setup.js
@@ -24,7 +24,7 @@ function createApp (t) {
return new Application({
path: path.join(__dirname, '..', 'node_modules', '.bin',
'electron' + (process.platform === 'win32' ? '.cmd' : '')),
- args: [path.join(__dirname, '..')],
+ args: ['-r', path.join(__dirname, 'mocks.js'), path.join(__dirname, '..')],
env: {NODE_ENV: 'test'}
})
}
diff --git a/test/test-add-torrent.js b/test/test-add-torrent.js
new file mode 100644
index 00000000..07782ba8
--- /dev/null
+++ b/test/test-add-torrent.js
@@ -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'))
+})